Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
deprecated mode specific methods in application class
  • Loading branch information
kraih committed Sep 4, 2013
1 parent 2c3438e commit c52aca1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 31 deletions.
4 changes: 4 additions & 0 deletions Changes
@@ -1,5 +1,9 @@

4.31 2013-09-04
- Deprecated mode specific methods in application class.
sub production_mode {...}
becomes
if ($self->mode eq 'production') {...}

4.30 2013-09-01
- Fixed memory leak in Mojolicious::Routes.
Expand Down
30 changes: 10 additions & 20 deletions lib/Mojolicious.pm
Expand Up @@ -88,8 +88,12 @@ sub new {
# Reduced log output outside of development mode
$self->log->level('info') unless $mode eq 'development';

# Run mode before startup
if (my $sub = $self->can("${mode}_mode")) { $self->$sub(@_) }
# DEPRECATED in Top Hat!
if (my $sub = $self->can("${mode}_mode")) {
warn qq{"sub ${mode}_mode {...}" in application class is DEPRECATED.\n};
$self->$sub(@_);
}

$self->startup(@_);

return $self;
Expand Down Expand Up @@ -255,24 +259,10 @@ L<Mojolicious::Controller>.
$app = $app->mode('production');
The operating mode for your application, defaults to a value from the
MOJO_MODE and PLACK_ENV environment variables or C<development>. You can also
add per mode logic to your application by defining methods named
C<${mode}_mode> in the application class, which will be called right before
C<startup>.
sub development_mode {
my $self = shift;
...
}
sub production_mode {
my $self = shift;
...
}
Right before calling C<startup> and mode specific methods, L<Mojolicious>
will pick up the current mode, name the log file after it and raise the log
level from C<debug> to C<info> if it has a value other than C<development>.
MOJO_MODE and PLACK_ENV environment variables or C<development>. Right before
calling C<startup>, L<Mojolicious> will pick up the current mode, name the log
file after it and raise the log level from C<debug> to C<info> if it has a
value other than C<development>.
=head2 moniker
Expand Down
21 changes: 10 additions & 11 deletions t/mojolicious/lib/MojoliciousTest.pm
Expand Up @@ -3,22 +3,21 @@ use Mojo::Base 'Mojolicious';

use MojoliciousTest::Foo;

sub development_mode {
sub startup {
my $self = shift;

# Template and static file class with higher precedence for development
unshift @{$self->static->classes}, 'MojoliciousTest::Foo';
unshift @{$self->renderer->classes}, 'MojoliciousTest::Foo';
if ($self->mode eq 'development') {

# Static root for development
unshift @{$self->static->paths}, $self->home->rel_dir('public_dev');
# Template and static file class with higher precedence for development
unshift @{$self->static->classes}, 'MojoliciousTest::Foo';
unshift @{$self->renderer->classes}, 'MojoliciousTest::Foo';

# Development namespace
unshift @{$self->routes->namespaces}, 'MojoliciousTest3';
}
# Static root for development
unshift @{$self->static->paths}, $self->home->rel_dir('public_dev');

sub startup {
my $self = shift;
# Development namespace
unshift @{$self->routes->namespaces}, 'MojoliciousTest3';
}

# Template and static file class with lower precedence for production
push @{$self->static->classes}, 'MojoliciousTest';
Expand Down

0 comments on commit c52aca1

Please sign in to comment.