Created
August 6, 2013 14:08
-
-
Save msouth/6164794 to your computer and use it in GitHub Desktop.
quick store/retrieve with Storable in a Dancer app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Foodle; | |
use Dancer ':syntax'; | |
use Storable; | |
our $VERSION = '0.1'; | |
get '/' => sub { | |
template 'index'; | |
}; | |
my $channel_file = 'channels.storable'; | |
unless (-e $channel_file) { | |
store {}, $channel_file; | |
#system "touch $channel_file" | |
} | |
get '/node/:node/start/:start/stop/:stop' => sub { | |
my $node = param('node'); | |
my $start = param('start'); | |
my $stop = param('stop'); | |
my $channel_data = retrieve($channel_file) || {}; | |
debug( 'channel data was:'. Dumper( $channel_data ) ); use Data::Dumper; | |
$channel_data->{$node}->{start} = $start; | |
$channel_data->{$node}->{stop} = $stop; | |
store $channel_data, $channel_file; | |
return "stored start:$start stop:$stop for node:$node"; | |
}; | |
true; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment