Skip to content

Commit

Permalink
we import all modules used in the current class
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Nov 28, 2016
1 parent c895cab commit 4b37c3a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Changes
Expand Up @@ -2,7 +2,7 @@
7.11 2016-11-28
- Improved one_tick method in Mojo::IOLoop to protect from recursion, similar
to the start method.
- Improved Mojolicious log attribute making it easier to override default
- Improved log attribute in Mojolicious making it easier to override default
settings. (jberger)

7.10 2016-11-01
Expand Down
17 changes: 7 additions & 10 deletions lib/Mojolicious.pm
Expand Up @@ -4,6 +4,7 @@ use Mojo::Base 'Mojo';
# "Fry: Shut up and take my money!"
use Carp ();
use Mojo::Exception;
use Mojo::Log;
use Mojo::Util;
use Mojolicious::Commands;
use Mojolicious::Controller;
Expand All @@ -23,23 +24,19 @@ has commands => sub {
return $commands;
};
has controller_class => 'Mojolicious::Controller';

has log => sub {
has log => sub {
my $self = shift;

# Check if we have a log directory that is writable
my $log = Mojo::Log->new;
my $home = $self->home;
my $mode = $self->mode;

# Check if we have a log directory that is writable
$log->path($home->rel_file("log/$mode.log"))
if -d $home->rel_file('log') && -w _;

# Reduced log output outside of development mode
$log->level('info') unless $mode eq 'development';

return $log;
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 };
Expand Down Expand Up @@ -408,8 +405,8 @@ loaded before the first request arrives.
$app = $app->log(Mojo::Log->new);
The logging layer of your application, defaults to a L<Mojo::Log> object. The
level will default to C<debug> if the L</mode> is C<development> or C<info>
otherwise. All messages will be written to C<STDERR> or a C<log/$mode.log> file
level will default to C<debug> if the L</mode> is C<development>, or C<info>
otherwise. All messages will be written to C<STDERR>, or a C<log/$mode.log> file
if a C<log> directory exists.
# Log debug message
Expand Down
15 changes: 5 additions & 10 deletions t/mojolicious/app.t
Expand Up @@ -450,22 +450,17 @@ $t->get_ok('/just/some/template')->status_is(200)
->content_is("Development template with high precedence.\n");

# Check default development mode log level
my $app = Mojolicious->new;
is $app->log->level, 'debug', 'right log level';
is(Mojolicious->new->log->level, 'debug', 'right log level');

# Check non-development mode log level
$app = Mojolicious->new;
$app->mode('test');
is $app->log->level, 'info', 'right log level';
is(Mojolicious->new->mode('test')->log->level, 'info', 'right log level');

# Make sure we can override attributes with constructor arguments
$app = MojoliciousTest->new(mode => 'test');
is $app->mode, 'test', 'right mode';
$app = MojoliciousTest->new({mode => 'test'});
is $app->mode, 'test', 'right mode';
is(MojoliciousTest->new(mode => 'test')->mode, 'test', 'right mode');
is(MojoliciousTest->new({mode => 'test'})->mode, 'test', 'right mode');

# Persistent error
$app = MojoliciousTest->new;
my $app = MojoliciousTest->new;
my $tx = $t->ua->build_tx(GET => '/foo');
$app->handler($tx);
is $tx->res->code, 200, 'right status';
Expand Down

0 comments on commit 4b37c3a

Please sign in to comment.