=================================================================== RCS file: /cvs/HOPE/Net-OpenAMD/script/test_server.pl,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- HOPE/Net-OpenAMD/script/test_server.pl 2010/06/25 21:20:15 1.2 +++ HOPE/Net-OpenAMD/script/test_server.pl 2010/06/26 17:14:52 1.3 @@ -11,19 +11,16 @@ 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]; - 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 +31,13 @@ die $json->error; } - $Actions->{$action} = { + $Actions{$action} = { mtime => $mtime, data => $data, }; } - return $Actions->{$action}{data}; + return $Actions{$action}{data}; } );