关注' dwimmer' Perl Dancer教程: http://perlmaven.com/building-a-blog-engine-using-perl-dancer
但是我遇到了运行时错误:
write_file'' - sysopen:没有这样的文件或目录
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;
这也是config.yaml文件的一部分:
template: "template_toolkit"
# engines:
template_toolkit:
encoding: 'utf8'
# start_tag: '[%'
# end_tag: '%]'
miniblog:
json: /home/rocko/Dancer_Projects/miniblog/miniblog.json
答案 0 :(得分:1)
缩进始终很重要,但在YAML中尤为重要。您的不良缩进会使您的代码难以阅读,并且会使您的YAML与预期不同。
更改
template: "template_toolkit"
# engines:
template_toolkit:
encoding: 'utf8'
# start_tag: '[%'
# end_tag: '%]'
miniblog:
json: /home/rocko/Dancer_Projects/miniblog/miniblog.jsonto
到
template: "template_toolkit"
template_toolkit:
encoding: 'utf8'
# start_tag: '[%'
# end_tag: '%]'
miniblog:
json: /home/rocko/Dancer_Projects/miniblog/miniblog.jsonto