【发布时间】:2016-02-03 10:45:56
【问题描述】:
这是 lib 文件夹中 myapp 的模块:
package myapp;
use Moose;
use namespace::autoclean;
use Catalyst::Runtime 5.80;
use Catalyst qw/
ConfigLoader
Session
Session::Store
Session::State
Static::Simple
/;
extends 'Catalyst';
our $VERSION = '0.01';
__PACKAGE__->config(
name => 'myapp',
# Disable deprecated behavior needed by old applications
disable_component_resolution_regex_fallback => 1,
enable_catalyst_header => 1, # Send X-Catalyst header
);
sub init {
my ( $c ) = @_;
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime();
$c->session->{ed_year} = $year + 1900;
}
# Start the application
__PACKAGE__->setup();
__PACKAGE__->init();
1;
上面的例子是错误的,没有可用的上下文($c)。我想知道是否可以在 Catalyst 应用程序的主模块中初始化会话。这里我要初始化全局变量,以后视图、模型和控制器会用到?
最好的问候, SK
【问题讨论】: