获取"没有这样的文件或目录"简单的perl Dancer app中的错误

时间:2014-08-01 23:13:04

标签: perl dancer

关注' 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

1 个答案:

答案 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