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

version 1.2, 2010/06/25 21:20:15 version 1.6, 2010/06/27 03:33:54
Line 3 
Line 3 
 use Mojolicious::Lite;  use Mojolicious::Lite;
 use Mojo::JSON;  use Mojo::JSON;
   
 use Data::Dumper;  
   
 use 5.010;  use 5.010;
   
 app->renderer->add_helper(  app->renderer->add_helper(
     action => sub {      action => sub {
         my ( $self, $action ) = @_;          my ( $self, $action ) = @_;
   
         state $Actions = {          state %Actions;
             location  => { mtime => 0 },  
             speakers  => { mtime => 0 },  
             talks     => { mtime => 0 },  
             interests => { mtime => 0 },  
             users     => { mtime => 0 },  
         };  
         return if !exists $Actions->{$action};  
   
         my $path  = app->home->rel_file( 'data/' . $action );          my $path = app->home->rel_file( '../t/data/' . $action );
         my $mtime = ( stat $path )[9];  
   
         if ( $mtime != $Actions->{$action}{mtime} ) {          return if !-e $path;
           my $mtime = ( stat _ )[9];
   
           $Actions{$action}{mtime} //= 0;
   
           if ( $mtime != $Actions{$action}{mtime} ) {
             open my $fh, $path or die "Couldn't open [$path]: $!";              open my $fh, $path or die "Couldn't open [$path]: $!";
             my $content = do { local $/; <$fh> };              my $content = do { local $/; <$fh> };
             close $fh;              close $fh;
Line 34 
Line 29 
                 die $json->error;                  die $json->error;
             }              }
   
             $Actions->{$action} = {              $Actions{$action} = {
                 mtime => $mtime,                  mtime => $mtime,
                 data  => $data,                  data  => $data,
             };              };
         }          }
   
         return $Actions->{$action}{data};          return $Actions{$action}{data};
     }      }
 );  );
   
Line 53 
Line 48 
     return if !ref $data;      return if !ref $data;
   
     my @data = @{$data};      my @data = @{$data};
     foreach my $param ( $self->param ) {  
         my $value = $self->param($param);      my $p = $self->req->params->to_hash;
         @data = grep { ( !exists $_->{$param} ) || $value ~~ $_->{$param} }      while ( my ( $param, $value ) = each(%$p) ) {
             @data;          @data = grep {
                      ref $_ ne 'HASH'
                   || ( !exists $_->{$param} )
                   || $value ~~ $_->{$param}
           } @data;
     }      }
   
     $self->render_json( \@data );      $self->render_json( \@data );
 };  };
   
Line 66 
Line 66 
   
 @@ 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>

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.6

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