Template Toolkit模块接口详解
1. 模块概述
模板工具包(Template Toolkit)的各个模块相互协作,每个模块都了解完成其工作所需的其他模块,并根据需要加载和创建实例。配置参数的哈希值会传递给每个模块的 new 方法。例如, Template::Service 创建 Template::Context 实例的代码如下:
# In Service.pm
sub _init {
my ($self, $config) = @_;
# Some other configuration
$context = $self->{ CONTEXT } = $config->{ CONTEXT }
|| Template::Config->context($config)
|| return $self->error(Template::Config->error);
return $self;
}
如果 $config 中已经包含 Template::Context 实例,则不会创建新的实例。这一特性对于覆盖特定实例的设置(如 TOLERANT )非常有用:
my $context = Template::Context->new(TOLER
超级会员免费看
订阅专栏 解锁全文
14

被折叠的 条评论
为什么被折叠?



