Skip to content

Commit

Permalink
improved Mojolicious to be able to detect the current operating mode …
Browse files Browse the repository at this point in the history
…from the PLACK_ENV environment variable
  • Loading branch information
kraih committed May 8, 2013
1 parent 911fcc8 commit 4964945
Show file tree
Hide file tree
Showing 53 changed files with 30 additions and 59 deletions.
2 changes: 2 additions & 0 deletions Changes
Expand Up @@ -16,6 +16,8 @@
- Reduced idle CPU usage of Mojo::IOLoop.
- Increased default lock_timeout from 0.5 to 1 second in
Mojo::Server::Prefork and Mojo::Server::Hypnotoad.
- Improved Mojolicious to be able to detect the current operating mode from
the PLACK_ENV environment variable.
- Improved Mojo::IOLoop performance by reducing stream timeout precision
from 0.5 to 1 second.
- Improved Mojo::DOM::HTML performance.
Expand Down
11 changes: 6 additions & 5 deletions lib/Mojolicious.pm
Expand Up @@ -22,7 +22,7 @@ has commands => sub {
return $commands;
};
has controller_class => 'Mojolicious::Controller';
has mode => sub { $ENV{MOJO_MODE} || 'development' };
has mode => sub { $ENV{MOJO_MODE} || $ENV{PLACK_ENV} || 'development' };
has moniker => sub { decamelize ref shift };
has plugins => sub { Mojolicious::Plugins->new };
has renderer => sub { Mojolicious::Renderer->new };
Expand Down Expand Up @@ -257,10 +257,11 @@ L<Mojolicious::Controller>.
my $mode = $app->mode;
$app = $app->mode('production');
The operating mode for your application, defaults to the value of the
MOJO_MODE environment variable 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>.
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;
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojolicious/Commands.pm
Expand Up @@ -11,8 +11,8 @@ These options are available for all commands:
-h, --help Get more information on a specific command.
--home <path> Path to your applications home directory, defaults to
the value of MOJO_HOME or auto detection.
-m, --mode <name> Run mode of your application, defaults to the value
of MOJO_MODE or "development".
-m, --mode <name> Run mode of your application, defaults to the value of
MOJO_MODE/PLACK_ENV or "development".
See '$0 help COMMAND' for more information on a specific command.
EOF
Expand Down
5 changes: 3 additions & 2 deletions lib/Mojolicious/Lite.pm
Expand Up @@ -914,8 +914,9 @@ changing the L<Mojolicious> operating mode.
app->start;
The default operating mode will usually be C<development> and can be changed
with command line options or the MOJO_MODE environment variable. A mode other
than C<development> will raise the log level from C<debug> to C<info>.
with command line options or the MOJO_MODE and PLACK_ENV environment
variables. A mode other than C<development> will raise the log level from
C<debug> to C<info>.
$ ./myapp.pl daemon -m production
Expand Down
1 change: 0 additions & 1 deletion t/mojo/app.t
@@ -1,6 +1,5 @@
use Mojo::Base -strict;

# Disable IPv6 and libev
BEGIN {
$ENV{MOJO_NO_IPV6} = 1;
$ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll';
Expand Down
1 change: 0 additions & 1 deletion t/mojo/delay.t
@@ -1,6 +1,5 @@
use Mojo::Base -strict;

# Disable IPv6 and libev
BEGIN {
$ENV{MOJO_NO_IPV6} = 1;
$ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll';
Expand Down
1 change: 0 additions & 1 deletion t/mojo/home.t
@@ -1,6 +1,5 @@
use Mojo::Base -strict;

# Disable libev
BEGIN { $ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll' }

use Test::More;
Expand Down
1 change: 0 additions & 1 deletion t/mojo/hypnotoad.t
@@ -1,6 +1,5 @@
use Mojo::Base -strict;

# Disable IPv6 and libev
BEGIN {
$ENV{MOJO_NO_IPV6} = 1;
$ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll';
Expand Down
1 change: 0 additions & 1 deletion t/mojo/ioloop.t
@@ -1,6 +1,5 @@
use Mojo::Base -strict;

# Disable IPv6 and libev
BEGIN {
$ENV{MOJO_NO_IPV6} = 1;
$ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll';
Expand Down
1 change: 0 additions & 1 deletion t/mojo/ioloop_ipv6.t
@@ -1,6 +1,5 @@
use Mojo::Base -strict;

# Disable libev
BEGIN { $ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll' }

use Test::More;
Expand Down
1 change: 0 additions & 1 deletion t/mojo/ioloop_tls.t
@@ -1,6 +1,5 @@
use Mojo::Base -strict;

# Disable IPv6 and libev
BEGIN {
$ENV{MOJO_NO_IPV6} = 1;
$ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll';
Expand Down
1 change: 0 additions & 1 deletion t/mojo/loader.t
@@ -1,6 +1,5 @@
use Mojo::Base -strict;

# Disable libev
BEGIN { $ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll' }

use Test::More;
Expand Down
1 change: 0 additions & 1 deletion t/mojo/morbo.t
@@ -1,6 +1,5 @@
use Mojo::Base -strict;

# Disable IPv6 and libev
BEGIN {
$ENV{MOJO_NO_IPV6} = 1;
$ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll';
Expand Down
1 change: 0 additions & 1 deletion t/mojo/prefork.t
@@ -1,6 +1,5 @@
use Mojo::Base -strict;

# Disable IPv6 and libev
BEGIN {
$ENV{MOJO_NO_IPV6} = 1;
$ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll';
Expand Down
1 change: 0 additions & 1 deletion t/mojo/reactor_ev.t
@@ -1,6 +1,5 @@
use Mojo::Base -strict;

# Disable IPv6
BEGIN { $ENV{MOJO_NO_IPV6} = 1 }

use Test::More;
Expand Down
1 change: 0 additions & 1 deletion t/mojo/reactor_poll.t
@@ -1,6 +1,5 @@
use Mojo::Base -strict;

# Disable IPv6 and libev
BEGIN {
$ENV{MOJO_NO_IPV6} = 1;
$ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll';
Expand Down
1 change: 0 additions & 1 deletion t/mojo/user_agent.t
@@ -1,6 +1,5 @@
use Mojo::Base -strict;

# Disable IPv6, TLS and libev
BEGIN {
$ENV{MOJO_NO_IPV6} = $ENV{MOJO_NO_TLS} = 1;
$ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll';
Expand Down
1 change: 0 additions & 1 deletion t/mojo/user_agent_online.t
@@ -1,6 +1,5 @@
use Mojo::Base -strict;

# Disable libev and proxy detection
BEGIN {
$ENV{MOJO_PROXY} = 0;
$ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll';
Expand Down
1 change: 0 additions & 1 deletion t/mojo/user_agent_tls.t
@@ -1,6 +1,5 @@
use Mojo::Base -strict;

# Disable IPv6 and libev
BEGIN {
$ENV{MOJO_NO_IPV6} = 1;
$ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll';
Expand Down
1 change: 0 additions & 1 deletion t/mojo/websocket.t
@@ -1,6 +1,5 @@
use Mojo::Base -strict;

# Disable IPv6 and libev
BEGIN {
$ENV{MOJO_NO_IPV6} = 1;
$ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll';
Expand Down
1 change: 0 additions & 1 deletion t/mojo/websocket_proxy.t
@@ -1,6 +1,5 @@
use Mojo::Base -strict;

# Disable IPv6 and libev
BEGIN {
$ENV{MOJO_NO_IPV6} = 1;
$ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll';
Expand Down
1 change: 0 additions & 1 deletion t/mojo/websocket_proxy_tls.t
@@ -1,6 +1,5 @@
use Mojo::Base -strict;

# Disable IPv6 and libev
BEGIN {
$ENV{MOJO_NO_IPV6} = 1;
$ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll';
Expand Down
14 changes: 13 additions & 1 deletion t/mojolicious/app.t
@@ -1,7 +1,7 @@
use Mojo::Base -strict;

# Disable IPv6 and libev
BEGIN {
$ENV{PLACK_ENV} = undef;
$ENV{MOJO_MODE} = 'development';
$ENV{MOJO_NO_IPV6} = 1;
$ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll';
Expand All @@ -26,6 +26,18 @@ use Test::Mojo;
'works', 'right result');
}

# Mode detection
{
local $ENV{MOJO_MODE} = undef;
local $ENV{PLACK_ENV} = 'something';
is(Test::Mojo->new('MojoliciousTest')->app->mode, 'something', 'right mode');
}
{
local $ENV{MOJO_MODE} = 'else';
local $ENV{PLACK_ENV} = 'something';
is(Test::Mojo->new('MojoliciousTest')->app->mode, 'else', 'right mode');
}

my $t = Test::Mojo->new('MojoliciousTest');

# Application is already available
Expand Down
1 change: 0 additions & 1 deletion t/mojolicious/caching_lite_app.t
@@ -1,6 +1,5 @@
use Mojo::Base -strict;

# Disable IPv6 and libev
BEGIN {
$ENV{MOJO_NO_IPV6} = 1;
$ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll';
Expand Down
1 change: 0 additions & 1 deletion t/mojolicious/charset_lite_app.t
@@ -1,6 +1,5 @@
use Mojo::Base -strict;

# Disable IPv6 and libev
BEGIN {
$ENV{MOJO_NO_IPV6} = 1;
$ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll';
Expand Down
1 change: 0 additions & 1 deletion t/mojolicious/command.t
@@ -1,6 +1,5 @@
use Mojo::Base -strict;

# Disable libev
BEGIN { $ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll' }

use Test::More;
Expand Down
6 changes: 4 additions & 2 deletions t/mojolicious/commands.t
@@ -1,7 +1,9 @@
use Mojo::Base -strict;

# Disable libev
BEGIN { $ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll' }
BEGIN {
$ENV{PLACK_ENV} = undef;
$ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll';
}

use Test::More;

Expand Down
1 change: 0 additions & 1 deletion t/mojolicious/dispatcher_lite_app.t
@@ -1,6 +1,5 @@
use Mojo::Base -strict;

# Disable IPv6 and libev
BEGIN {
$ENV{MOJO_NO_IPV6} = 1;
$ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll';
Expand Down
1 change: 0 additions & 1 deletion t/mojolicious/embedded_app.t
@@ -1,6 +1,5 @@
use Mojo::Base -strict;

# Disable IPv6 and libev
BEGIN {
$ENV{MOJO_MODE} = 'testing';
$ENV{MOJO_NO_IPV6} = 1;
Expand Down
1 change: 0 additions & 1 deletion t/mojolicious/embedded_lite_app.t
@@ -1,6 +1,5 @@
use Mojo::Base -strict;

# Disable IPv6 and libev
BEGIN {
$ENV{MOJO_MODE} = 'testing';
$ENV{MOJO_NO_IPV6} = 1;
Expand Down
1 change: 0 additions & 1 deletion t/mojolicious/exception_lite_app.t
@@ -1,6 +1,5 @@
use Mojo::Base -strict;

# Disable IPv6 and libev
BEGIN {
$ENV{MOJO_MODE} = 'development';
$ENV{MOJO_NO_IPV6} = 1;
Expand Down
1 change: 0 additions & 1 deletion t/mojolicious/external_app.t
@@ -1,6 +1,5 @@
use Mojo::Base -strict;

# Disable IPv6 and libev
BEGIN {
$ENV{MOJO_MODE} = 'testing';
$ENV{MOJO_NO_IPV6} = 1;
Expand Down
1 change: 0 additions & 1 deletion t/mojolicious/external_lite_app.t
@@ -1,6 +1,5 @@
use Mojo::Base -strict;

# Disable IPv6 and libev
BEGIN {
$ENV{MOJO_MODE} = 'testing';
$ENV{MOJO_NO_IPV6} = 1;
Expand Down
1 change: 0 additions & 1 deletion t/mojolicious/group_lite_app.t
@@ -1,6 +1,5 @@
use Mojo::Base -strict;

# Disable IPv6 and libev
BEGIN {
$ENV{MOJO_NO_IPV6} = 1;
$ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll';
Expand Down
1 change: 0 additions & 1 deletion t/mojolicious/json_config_lite_app.t
@@ -1,6 +1,5 @@
use Mojo::Base -strict;

# Disable IPv6 and libev
BEGIN {
$ENV{MOJO_MODE} = 'development';
$ENV{MOJO_NO_IPV6} = 1;
Expand Down
1 change: 0 additions & 1 deletion t/mojolicious/json_config_mode_lite_app.t
@@ -1,6 +1,5 @@
use Mojo::Base -strict;

# Disable IPv6 and libev
BEGIN {
$ENV{MOJO_MODE} = 'testing';
$ENV{MOJO_NO_IPV6} = 1;
Expand Down
1 change: 0 additions & 1 deletion t/mojolicious/layouted_lite_app.t
@@ -1,6 +1,5 @@
use Mojo::Base -strict;

# Disable IPv6 and libev
BEGIN {
$ENV{MOJO_NO_IPV6} = 1;
$ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll';
Expand Down
1 change: 0 additions & 1 deletion t/mojolicious/lite_app.t
@@ -1,6 +1,5 @@
use Mojo::Base -strict;

# Disable IPv6 and libev
BEGIN {
$ENV{MOJO_MODE} = 'development';
$ENV{MOJO_NO_IPV6} = 1;
Expand Down
1 change: 0 additions & 1 deletion t/mojolicious/longpolling_lite_app.t
@@ -1,6 +1,5 @@
use Mojo::Base -strict;

# Disable IPv6 and libev
BEGIN {
$ENV{MOJO_NO_IPV6} = 1;
$ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll';
Expand Down
1 change: 0 additions & 1 deletion t/mojolicious/multipath_lite_app.t
@@ -1,6 +1,5 @@
use Mojo::Base -strict;

# Disable IPv6 and libev
BEGIN {
$ENV{MOJO_NO_IPV6} = 1;
$ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll';
Expand Down
1 change: 0 additions & 1 deletion t/mojolicious/ojo.t
@@ -1,6 +1,5 @@
use Mojo::Base -strict;

# Disable IPv6, libev and proxy detection
BEGIN {
$ENV{MOJO_MODE} = 'development';
$ENV{MOJO_NO_IPV6} = 1;
Expand Down
1 change: 0 additions & 1 deletion t/mojolicious/pod_renderer_lite_app.t
@@ -1,6 +1,5 @@
use Mojo::Base -strict;

# Disable IPv6 and libev
BEGIN {
$ENV{MOJO_NO_IPV6} = 1;
$ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll';
Expand Down
1 change: 0 additions & 1 deletion t/mojolicious/production_app.t
@@ -1,6 +1,5 @@
use Mojo::Base -strict;

# Disable IPv6 and libev
BEGIN {
$ENV{MOJO_MODE} = 'production';
$ENV{MOJO_NO_IPV6} = 1;
Expand Down
1 change: 0 additions & 1 deletion t/mojolicious/rebased_lite_app.t
@@ -1,6 +1,5 @@
use Mojo::Base -strict;

# Disable IPv6 and libev
BEGIN {
$ENV{MOJO_NO_IPV6} = 1;
$ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll';
Expand Down
1 change: 0 additions & 1 deletion t/mojolicious/restful_lite_app.t
@@ -1,6 +1,5 @@
use Mojo::Base -strict;

# Disable IPv6 and libev
BEGIN {
$ENV{MOJO_NO_IPV6} = 1;
$ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll';
Expand Down
1 change: 0 additions & 1 deletion t/mojolicious/static_lite_app.t
@@ -1,6 +1,5 @@
use Mojo::Base -strict;

# Disable IPv6 and libev
BEGIN {
$ENV{MOJO_NO_IPV6} = 1;
$ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll';
Expand Down
1 change: 0 additions & 1 deletion t/mojolicious/tag_helper_lite_app.t
@@ -1,6 +1,5 @@
use Mojo::Base -strict;

# Disable IPv6 and libev
BEGIN {
$ENV{MOJO_NO_IPV6} = 1;
$ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll';
Expand Down
1 change: 0 additions & 1 deletion t/mojolicious/testing_app.t
@@ -1,6 +1,5 @@
use Mojo::Base -strict;

# Disable IPv6 and libev
BEGIN {
$ENV{MOJO_MODE} = 'testing';
$ENV{MOJO_NO_IPV6} = 1;
Expand Down
1 change: 0 additions & 1 deletion t/mojolicious/tls_lite_app.t
@@ -1,6 +1,5 @@
use Mojo::Base -strict;

# Disable IPv6 and libev
BEGIN {
$ENV{MOJO_NO_IPV6} = 1;
$ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll';
Expand Down

0 comments on commit 4964945

Please sign in to comment.