=================================================================== RCS file: /cvs/HOPE/Net-OpenAMD/script/test_server.pl,v retrieving revision 1.2 retrieving revision 1.5 diff -u -r1.2 -r1.5 --- HOPE/Net-OpenAMD/script/test_server.pl 2010/06/25 21:20:15 1.2 +++ HOPE/Net-OpenAMD/script/test_server.pl 2010/06/27 01:52:33 1.5 @@ -3,27 +3,22 @@ use Mojolicious::Lite; use Mojo::JSON; -use Data::Dumper; - use 5.010; app->renderer->add_helper( action => sub { my ( $self, $action ) = @_; - state $Actions = { - location => { mtime => 0 }, - speakers => { mtime => 0 }, - talks => { mtime => 0 }, - interests => { mtime => 0 }, - users => { mtime => 0 }, - }; - return if !exists $Actions->{$action}; + state %Actions; - my $path = app->home->rel_file( 'data/' . $action ); - my $mtime = ( stat $path )[9]; + my $path = app->home->rel_file( '../t/data/' . $action ); - 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]: $!"; my $content = do { local $/; <$fh> }; close $fh; @@ -34,13 +29,13 @@ die $json->error; } - $Actions->{$action} = { + $Actions{$action} = { mtime => $mtime, data => $data, }; } - return $Actions->{$action}{data}; + return $Actions{$action}{data}; } ); @@ -55,8 +50,11 @@ my @data = @{$data}; foreach my $param ( $self->param ) { my $value = $self->param($param); - @data = grep { ( !exists $_->{$param} ) || $value ~~ $_->{$param} } - @data; + @data = grep { + ref $_ ne 'HASH' + || ( !exists $_->{$param} ) + || $value ~~ $_->{$param} + } @data; } $self->render_json( \@data ); }; @@ -66,7 +64,8 @@ @@ index.html.ep % layout 'default'; -Please try /api/action +Please try /api/action, or see +amd.hope.net. @@ layouts/default.html.ep