=================================================================== RCS file: /cvs/HOPE/Net-OpenAMD/script/test_server.pl,v retrieving revision 1.2 retrieving revision 1.7 diff -u -r1.2 -r1.7 --- 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 04:26:56 1.7 @@ -1,29 +1,31 @@ #!/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 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 +36,13 @@ die $json->error; } - $Actions->{$action} = { + $Actions{$action} = { mtime => $mtime, data => $data, }; } - return $Actions->{$action}{data}; + return $Actions{$action}{data}; } ); @@ -53,11 +55,16 @@ return if !ref $data; my @data = @{$data}; - foreach my $param ( $self->param ) { - my $value = $self->param($param); - @data = grep { ( !exists $_->{$param} ) || $value ~~ $_->{$param} } - @data; + + my $p = $self->req->params->to_hash; + while ( my ( $param, $value ) = each(%$p) ) { + @data = grep { + ref $_ ne 'HASH' + || ( !exists $_->{$param} ) + || $value ~~ $_->{$param} + } @data; } + $self->render_json( \@data ); }; @@ -66,7 +73,8 @@ @@ index.html.ep % layout 'default'; -Please try /api/action +Please try /api/action, or see +amd.hope.net. @@ layouts/default.html.ep