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

version 1.1, 2010/06/25 03:30:56 version 1.2, 2010/06/25 21:20:15
Line 1 
Line 1 
 #!/usr/bin/env perl  #!/usr/bin/env perl
   
 use Mojolicious::Lite;  use Mojolicious::Lite;
   use Mojo::JSON;
   
   use Data::Dumper;
   
 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',              location  => { mtime => 0 },
             user   => '12983',              speakers  => { mtime => 0 },
             button => 'False',              talks     => { mtime => 0 },
         },              interests => { mtime => 0 },
     ],              users     => { mtime => 0 },
     speakers => [          };
         {   name => 'Johnny',          return if !exists $Actions->{$action};
             bio  => 'Johnny\'s bio'  
         },          my $path  = app->home->rel_file( 'data/' . $action );
         {   name => 'Judas',          my $mtime = ( stat $path )[9];
             bio  => 'Judas\'s bio'  
         },          if ( $mtime != $Actions->{$action}{mtime} ) {
     ],              open my $fh, $path or die "Couldn't open [$path]: $!";
     talks => [              my $content = do { local $/; <$fh> };
         {   speakers => [ 'Judas', 'JohnnyX' ],              close $fh;
             title    => 'Ancient Egyptian Music and DRM',  
             abstract =>              my $json = Mojo::JSON->new;
                 '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.',              my $data = $json->decode($content);
             'time'    => '2008/7/18 13:00:00',              if ( $json->error ) {
             track     => 'Hooper',                  die $json->error;
             interests => [ 'media', 'crypto' ]              }
         },  
     ],              $Actions->{$action} = {
     interests => [                  mtime => $mtime,
         'new tech',           'activism',                  data  => $data,
         'radio',              'lockpicking',              };
         'crypto',             'privacy',          }
         'ethics',             'telephones',  
         'social engineering', 'hacker spaces',          return $Actions->{$action}{data};
         '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 { ( !exists $_->{$param} ) || $value ~~ $_->{$param} }
               @data;
     }      }
     $self->render_json( \@data );      $self->render_json( \@data );
 };  };
Line 115 
Line 72 
 <!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.2

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