Reputation: 41
Following the 'dwimmer' tutorial for Perl Dancer: http://perlmaven.com/building-a-blog-engine-using-perl-dancer
But I'm getting a run time error:
write_file '' - sysopen: No such file or directory
Here is the app.pl:
package miniblog;
use Dancer ':syntax';
use File::Slurp qw(read_file write_file);
our $VERSION = '0.1';
get '/' => sub {
template 'index';
};
get '/page' => sub {
template 'page';
};
post '/page' => sub {
my $file = config->{miniblog} {json};
my $json = -e $file ? read_file $file : '{}';
my $data = from_json $json;
my $now = time;
$data->{$now} = {
title => params->{title},
text => params->{text},
};
write_file $file, to_json $data;
redirect '/';
};
true;
Also here is the portion of the config.yaml file:
template: "template_toolkit"
# engines:
template_toolkit:
encoding: 'utf8'
# start_tag: '[%'
# end_tag: '%]'
miniblog:
json: /home/rocko/Dancer_Projects/miniblog/miniblog.json
Upvotes: 2
Views: 268
Reputation: 385496
Indenting is always important, but it's particularly important in YAML. Your bad indenting makes your code hard to read, and it's makes your YAML different than intended.
Change
template: "template_toolkit"
# engines:
template_toolkit:
encoding: 'utf8'
# start_tag: '[%'
# end_tag: '%]'
miniblog:
json: /home/rocko/Dancer_Projects/miniblog/miniblog.jsonto
to
template: "template_toolkit"
template_toolkit:
encoding: 'utf8'
# start_tag: '[%'
# end_tag: '%]'
miniblog:
json: /home/rocko/Dancer_Projects/miniblog/miniblog.jsonto
Upvotes: 1