package App;
use strict;
use warnings;
use Mojo::Base 'Mojolicious';
our ($data, $sql, $bv, $result);
sub init
{
my $self = shift;
$data->{log_level} = {
production => 'debug',
development => 'debug',
test => 'debug',
stage => 'debug',
demo => 'debug',
sandbox => 'debug',
};
$self->log->level($data->{log_level}->{$self->mode});
shift @{$self->renderer->paths};
push @{$self->renderer->paths}, $self->home->to_string.'/web/templates';
$self->plugin('Plugin::Debug');
#$self->DEBUG(0, '$self', $self->Dump($self));
$self->{timestamp}->{start} = $self->timestamp;
if($self->{conf})
{
my $file = $self->{conf};
#$self->DEBUG(0, '$file', $self->Dump($file));
if(open FILE, $file)
{
$self->config(eval(join('', )));
close FILE;
}
else
{
die("$file: $!\n");
}
}
my $config = $self->config;
$config->{dir}->{app_home} = $self->home->to_string;
#push(@{$self->static->paths}, "$config->{dir}->{app_home}/web/public");
$self->plugin('Plugin::Util', $config);
$self->plugin('Plugin::Mail', $config);
push(@{$self->static->paths}, @{$config->{dir}->{static}});
$self->renderer->encoding('UTF-8');
my $mason = $self->plugin('Plugin::Mason2',
{
preload_regexps => [ '.mc$', $config->{dir}->{mason_comp}],
interp_params =>
{
comp_root => $config->{dir}->{mason_comp},
data_dir => $config->{dir}->{mason_data}.'/'.$self->mode,
allow_globals => [qw($q $db)],
},
request_params => {},
set_global_items => {'$q' => $self},
});
#$self->secrets($config->{session}->{secrets}.$self->{timestamp}->{D});
$self->secrets($config->{session}->{secrets});
$self->sessions->cookie_name($config->{session}->{cookie_name});
$self->sessions->default_expiration($config->{session}->{default_expiration});
$self->sessions->cookie_path('/');
return 1;
}
sub startup {
my $self = shift;
$self->init(@_);
my $r = $self->routes;
my $auth = $r->under('/')->to(controller => 'auth', action => 'user');
$auth->route('/#controller/#action/#target/#task/#perform/#object/#move')->name('move_route');
$auth->route('/#controller/#action/#target/#task/#perform/#object')->name('oid_route');
$auth->route('/#controller/#action/#target/#task/#perform')->name('perform_route');
$auth->route('/#controller/#action/#target/#task')->name('task_route');
$auth->route('/#controller/#action/#target')->name('target_route');
$auth->route('/#controller/#action')->name('action_route');
$auth->route('/#controller')->name('controller_route')->to(action => 'view');
$auth->route('/')->name('root_route')->to(controller => 'page', action => 'view', target=>'home');
return 1;
}
1; |