[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.5

version 1.1, 2010/06/25 03:30:56 version 1.5, 2010/06/27 01:52:33
Line 1 
Line 1 
 #!/usr/bin/env perl  #!/usr/bin/env perl
   
 use Mojolicious::Lite;  use Mojolicious::Lite;
   use Mojo::JSON;
   
 use 5.010;  use 5.010;
   
 my %Actions = (  app->renderer->add_helper(
     location => [      action => sub {
         {   area   => 'Engressia',          my ( $self, $action ) = @_;
             'time' => '2387',  
             x      => '46.7369918823242',          state %Actions;
             y      => '83.1452331542969',  
             user   => '12983',          my $path = app->home->rel_file( '../t/data/' . $action );
             button => 'False',  
         },          return if !-e $path;
     ],          my $mtime = ( stat _ )[9];
     speakers => [  
         {   name => 'Johnny',          $Actions{$action}{mtime} //= 0;
             bio  => 'Johnny\'s bio'  
         },          if ( $mtime != $Actions{$action}{mtime} ) {
         {   name => 'Judas',              open my $fh, $path or die "Couldn't open [$path]: $!";
             bio  => 'Judas\'s bio'              my $content = do { local $/; <$fh> };
         },              close $fh;
     ],  
     talks => [              my $json = Mojo::JSON->new;
         {   speakers => [ 'Judas', 'JohnnyX' ],              my $data = $json->decode($content);
             title    => 'Ancient Egyptian Music and DRM',              if ( $json->error ) {
             abstract =>                  die $json->error;
                 '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.',              }
             'time'    => '2008/7/18 13:00:00',  
             track     => 'Hooper',              $Actions{$action} = {
             interests => [ 'media', 'crypto' ]                  mtime => $mtime,
         },                  data  => $data,
     ],              };
     interests => [          }
         'new tech',           'activism',  
         'radio',              'lockpicking',          return $Actions{$action}{data};
         '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() ) {      foreach my $param ( $self->param ) {
         next if $param eq 'callback';  
         next if $param eq 'action';  
   
         my $value = $self->param($param);          my $value = $self->param($param);
         @data = grep $value ~~ $_->{$param}, @data;          @data = grep {
               ref $_ ne 'HASH'
                   || ( !exists $_->{$param} )
                   || $value ~~ $_->{$param}
           } @data;
     }      }
     $self->render_json( \@data );      $self->render_json( \@data );
 };  };
Line 109 
Line 64 
   
 @@ 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.5

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