我有一个看起来像这样的类:
package MyApp::Model::Skunk::Find::Images;
use Moose;
use namespace::autoclean;
extends 'Catalyst::Model::Factory';
use Data::Dump qw/dump/;
sub prepare_arguments {
my ($self, $c) = @_;
# these are for debugging purposes only
$c->log->info("package: " . __PACKAGE__);
$c->log->info("catalyst config: " . dump $c->config);
$c->log->info("images class: " . __PACKAGE__->config->{class});
$c->log->info("images root: " . __PACKAGE__->config->{root});
return { root => __PACKAGE__->config->{root} };
}
和 myapp.conf 看起来像这样(片段):
<Model::Skunk::Find::Images>
root '/foo/bar/myapp/data/img'
class MyApp::Find
</Model::Skunk::Find::Images>
我可以访问整个应用程序配置哈希(我知道这个答案),但我似乎无法直接访问类的配置,所以
$c->log->info("images class: " . __PACKAGE__->config->{class});
$c->log->info("images root: " . __PACKAGE__->config->{root});
在 MyApp::Skunk::Find::Images 中都没有产生任何结果。
如果我像这样从包内部配置变量:
__PACKAGE__->config(
class => 'MyApp::Find',
root => '/foo/bar/myapp/data/img'
);
一切正常。
谁能帮忙解释一下?