Ado
view release on metacpan or search on metacpan
my $static_paths = $app->static->paths;
push @$renderer_paths, $templates_dir
unless (first { $_ eq $templates_dir } @$renderer_paths);
push @$static_paths, $public_dir
unless (first { $_ eq $public_dir } @$static_paths);
$app->secrets([Mojo::Util::sha1_sum($app->moniker . $mode . $home),]);
unshift @$renderer_paths, $site_templates if -d $site_templates;
$app->controller_class("${CLASS}::Control");
$app->routes->namespaces(["${CLASS}::Control"]);
$app->plugins->namespaces(['Mojolicious::Plugin', "${CLASS}::Plugin",]);
unshift @{$app->commands->namespaces}, "${CLASS}::Command";
return $app;
}
# This method will run once at server start
sub startup {
shift->_initialise()->load_config()->load_plugins()->load_routes()->define_mime_types();
return;
}
#load ado.conf
sub load_config {
my ($app) = @_;
my $app_config = $app->home->rel_file('etc/' . $app->moniker . '.conf');
$ENV{MOJO_CONFIG} //=
-s $app_config
? $app_config
: $app->ado_home->rel_file('etc/' . lc($CLASS) . '.conf');
$app->plugin('Config');
return $app;
}
sub load_plugins {
my ($app) = @_;
my $plugins = $app->config('plugins') || [];
foreach my $plugin (@$plugins) {
$app->log->debug('Loading Plugin ' . (ref $plugin ? $plugin->{name} : $plugin));
if (ref $plugin eq 'HASH') {
$app->plugin($plugin->{name} => $plugin->{config});
}
elsif ($plugin) {
$app->plugin($plugin);
}
}
return $app;
}
#load routes defined in ado.conf
sub load_routes {
my ($app, $config_routes) = @_;
$config_routes ||= $app->config('routes') || [];
my $routes = $app->routes;
# Hide Ado::Control methods and attributes from router.
$routes->hide(
qw(
debug config require_format list_for_json
validate_input
)
);
foreach my $route (@$config_routes) {
my ($pattern, $over, $to, $via, $params) =
($route->{route}, $route->{over}, $route->{to}, $route->{via}, $route->{params});
next unless $to;
my $r = $params ? $routes->route($pattern, %$params) : $routes->route($pattern);
if ($over) {
if (ref $over eq 'HASH') { $r->over(%$over); }
else { $r->over($over); }
}
if ($via) {
$r->via(@$via);
}
$r->to(ref $to eq 'HASH' ? %$to : $to);
}
# Default "/perldoc" page is Ado/Manual
my $perldoc = $routes->lookup('perldocmodule');
if ($perldoc) { $perldoc->to->{module} = 'Ado/Manual'; }
return $app;
}
sub define_mime_types {
my ($app) = @_;
my $mimes = $app->config('types') || {}; #HASHREF
foreach my $mime (keys %$mimes) {
# Add new MIME type or redefine any existing
$app->types->type($mime => $mimes->{$mime});
}
return $app;
}
1;
=pod
=encoding utf8
=head1 NAME
Ado - a rapid active commotion (framework for web-projects on Mojolicious)
=head1 SYNOPSIS
require Mojolicious::Commands;
Mojolicious::Commands->start_app('Ado');
=head1 DESCRIPTION
L<Ado> is a framework for web-projects based on L<Mojolicious>, written in the
L<Perl programming language|http://www.perl.org/>. This is the base
application class. Ado C<ISA> L<Mojolicious>. For a more detailed description
on what Ado is and how to get started with Ado see B<L<Ado::Manual>>.
( run in 0.455 second using v1.01-cache-2.11-cpan-140bd7fdf52 )