Skip to content

Commit

Permalink
not everything can be initialized lazily
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Nov 29, 2016
1 parent caab686 commit e76f383
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 28 deletions.
4 changes: 2 additions & 2 deletions Changes
Expand Up @@ -3,8 +3,8 @@
- Added EXPERIMENTAL close_idle_connections method to Mojo::Server::Daemon.
- Improved one_tick method in Mojo::IOLoop to protect from recursion, similar
to the start method.
- Improved log, renderer, routes and static attributes in Mojolicious, making
it easier to override default settings. (jberger, sri)
- Improved log attribute in Mojolicious to make it easier to override default
settings. (jberger)
- Fixed bug in Mojo::Server::Prefork where workers would accept keep-alive
requests after a graceful shutdown had already been initiated.
- Fixed bugs in Mojo::Util and Mojo::Asset::File where incomplete writes would
Expand Down
51 changes: 25 additions & 26 deletions lib/Mojolicious.pm
Expand Up @@ -38,26 +38,11 @@ has log => sub {
return $mode eq 'development' ? $log : $log->level('info');
};
has mode => sub { $ENV{MOJO_MODE} || $ENV{PLACK_ENV} || 'development' };
has moniker => sub { Mojo::Util::decamelize ref shift };
has plugins => sub { Mojolicious::Plugins->new };
has renderer => sub {
Mojolicious::Renderer->new(paths => [shift->home->rel_dir('templates')]);
};
has routes => sub {
my $self = shift;

# Hide controller attributes/methods
my $r = Mojolicious::Routes->new;
$r->hide(qw(app continue cookie every_cookie every_param));
$r->hide(qw(every_signed_cookie finish flash helpers match on param));
$r->hide(qw(redirect_to render render_later render_maybe render_to_string));
$r->hide(qw(rendered req res respond_to send session signed_cookie stash));
$r->hide(qw(tx url_for validation write write_chunk));

# Default to controller and application namespace
return $r->namespaces(["@{[ref $self]}::Controller", ref $self]);
};
has secrets => sub {
has moniker => sub { Mojo::Util::decamelize ref shift };
has plugins => sub { Mojolicious::Plugins->new };
has renderer => sub { Mojolicious::Renderer->new };
has routes => sub { Mojolicious::Routes->new };
has secrets => sub {
my $self = shift;

# Warn developers about insecure default
Expand All @@ -66,9 +51,8 @@ has secrets => sub {
# Default to moniker
return [$self->moniker];
};
has sessions => sub { Mojolicious::Sessions->new };
has static =>
sub { Mojolicious::Static->new(paths => [shift->home->rel_dir('public')]) };
has sessions => sub { Mojolicious::Sessions->new };
has static => sub { Mojolicious::Static->new };
has types => sub { Mojolicious::Types->new };
has validator => sub { Mojolicious::Validator->new };

Expand Down Expand Up @@ -167,6 +151,20 @@ sub hook { shift->plugins->on(@_) }
sub new {
my $self = shift->SUPER::new(@_);

my $home = $self->home;
push @{$self->renderer->paths}, $home->rel_dir('templates');
push @{$self->static->paths}, $home->rel_dir('public');

# Default to controller and application namespace
my $r = $self->routes->namespaces(["@{[ref $self]}::Controller", ref $self]);

# Hide controller attributes/methods
$r->hide(qw(app continue cookie every_cookie every_param));
$r->hide(qw(every_signed_cookie finish flash helpers match on param));
$r->hide(qw(redirect_to render render_later render_maybe render_to_string));
$r->hide(qw(rendered req res respond_to send session signed_cookie stash));
$r->hide(qw(tx url_for validation write write_chunk));

$self->plugin($_)
for qw(HeaderCondition DefaultHelpers TagHelpers EPLRenderer EPRenderer);

Expand Down Expand Up @@ -651,9 +649,10 @@ requests indiscriminately, for a full list of available hooks see L</"HOOKS">.
my $app = Mojolicious->new(moniker => 'foo_bar');
my $app = Mojolicious->new({moniker => 'foo_bar'});
Construct a new L<Mojolicious> application and call L</"startup">. Also sets up
a default set of plugins and an L</"around_dispatch"> hook with the default
exception handling.
Construct a new L<Mojolicious> application and call L</"startup">. Will
automatically detect your home directory. Also sets up the renderer, static file
server, a default set of plugins and an L</"around_dispatch"> hook with the
default exception handling.
=head2 plugin
Expand Down

0 comments on commit e76f383

Please sign in to comment.