Skip to content

Instantly share code, notes, and snippets.

@msouth
Created August 6, 2013 14:08
Show Gist options
  • Save msouth/6164794 to your computer and use it in GitHub Desktop.
Save msouth/6164794 to your computer and use it in GitHub Desktop.
quick store/retrieve with Storable in a Dancer app
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