[BACK]Return to test_server.pl CVS log [TXT][DIR] Up to [local] / HOPE / Net-OpenAMD / script

Diff for /HOPE/Net-OpenAMD/script/test_server.pl between version 1.1 and 1.7

version 1.1, 2010/06/25 03:30:56 version 1.7, 2010/06/27 04:26:56
Line 1 
Line 1 
 #!/usr/bin/env perl  #!/usr/bin/env perl
   
   use 5.010;
   
   BEGIN {
       use FindBin;
       use lib "$FindBin::Bin/../lib";
       use lib "$FindBin::Bin/../mojo/lib";
       use lib "$FindBin::Bin/../../mojo/lib";
   }
   
 use Mojolicious::Lite;  use Mojolicious::Lite;
   use Mojo::JSON;
   
 use 5.010;  app->renderer->add_helper(
       action => sub {
           my ( $self, $action ) = @_;
   
 my %Actions = (          state %Actions;
     location => [  
         {   area   => 'Engressia',          my $path = app->home->rel_file( '../t/data/' . $action );
             'time' => '2387',  
             x      => '46.7369918823242',          return if !-e $path;
             y      => '83.1452331542969',          my $mtime = ( stat _ )[9];
             user   => '12983',  
             button => 'False',          $Actions{$action}{mtime} //= 0;
         },  
     ],          if ( $mtime != $Actions{$action}{mtime} ) {
     speakers => [              open my $fh, $path or die "Couldn't open [$path]: $!";
         {   name => 'Johnny',              my $content = do { local $/; <$fh> };
             bio  => 'Johnny\'s bio'              close $fh;
         },  
         {   name => 'Judas',              my $json = Mojo::JSON->new;
             bio  => 'Judas\'s bio'              my $data = $json->decode($content);
         },              if ( $json->error ) {
     ],                  die $json->error;
     talks => [              }
         {   speakers => [ 'Judas', 'JohnnyX' ],  
             title    => 'Ancient Egyptian Music and DRM',              $Actions{$action} = {
             abstract =>                  mtime => $mtime,
                 'A discussion of the development of musical notation, which was designed as a means of reproducing music while making it impossible for the general public to perform without permission.',                  data  => $data,
             'time'    => '2008/7/18 13:00:00',              };
             track     => 'Hooper',          }
             interests => [ 'media', 'crypto' ]  
         },          return $Actions{$action}{data};
     ],      }
     interests => [  
         'new tech',           'activism',  
         'radio',              'lockpicking',  
         'crypto',             'privacy',  
         'ethics',             'telephones',  
         'social engineering', 'hacker spaces',  
         'hardware hacking',   'nostalgia',  
         'communities',        'science',  
         'government',         'network security',  
         'malicious software', 'pen testing',  
         'web',                'niche hacks',  
         'media'  
     ],  
     users => [  
         {   name      => 'JohnnyX',  
             x         => '32.54091324',  
             y         => '54.10958384',  
             interests => [  
                 'new tech',           'radio',  
                 'lockpicking',        'crypto',  
                 'telephones',         'social engineering',  
                 'hacker spaces',      'hardware hacking',  
                 'nostalgia',          'communities',  
                 'science',            'network security',  
                 'malicious software', 'pen testing',  
             ],  
         },  
         {   name      => 'andrew',  
             x         => '32',  
             y         => '54',  
             interests => [  
                 'media',  
                 'lockpicking',        'crypto',  
                 'telephones',         'social engineering',  
                 'hacker spaces',      'hardware hacking',  
                 'science',            'network security',  
                 'malicious software', 'pen testing',  
             ],  
         },  
         {   name      => 'Judas',  
             x         => '33',  
             y         => '52',  
             interests => [  
                 'media',  
                 'lockpicking',        'crypto',  
                 'telephones',         'social engineering',  
                 'science',            'network security',  
                 'malicious software', 'pen testing',  
             ],  
         },  
     ],  
 );  );
   
 get '/' => 'index';  get '/' => 'index';
   
 get '/api/:action' => sub {  get '/api/:action' => sub {
     my $self   = shift;      my $self = shift;
     my $action = $self->stash('action');  
   
     return if !exists $Actions{$action};      my $data = $self->helper( 'action', $self->stash('action') );
       return if !ref $data;
   
     my @data = @{ $Actions{$action} };      my @data = @{$data};
     foreach my $param ( $self->param() ) {  
         next if $param eq 'callback';  
         next if $param eq 'action';  
   
         my $value = $self->param($param);      my $p = $self->req->params->to_hash;
         @data = grep $value ~~ $_->{$param}, @data;      while ( my ( $param, $value ) = each(%$p) ) {
           @data = grep {
                      ref $_ ne 'HASH'
                   || ( !exists $_->{$param} )
                   || $value ~~ $_->{$param}
           } @data;
     }      }
   
     $self->render_json( \@data );      $self->render_json( \@data );
 };  };
   
Line 109 
Line 73 
   
 @@ index.html.ep  @@ index.html.ep
 % layout 'default';  % layout 'default';
 Please try /api/action  Please try /api/action, or see
   <a href="http://amd.home.net">amd.hope.net</a>.
   
 @@ layouts/default.html.ep  @@ layouts/default.html.ep
 <!doctype html><html>  <!doctype html><html>
     <head><title>Test OpenAMD API!</title></head>      <head><title>Test OpenAMD API!</title></head>
     <body><%== content %></body>      <body><%== content %></body>
   </html>
   
   @@ exception.html.ep
   <!doctype html><html>
       <head><title>Exception</title></head>
       <body><%== $exception %></body>
 </html>  </html>

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.7

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>