Skip to content

Commit

Permalink
removed app_class attribute from Mojo::Server
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jun 22, 2012
1 parent df72a6e commit 28a744a
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 22 deletions.
1 change: 1 addition & 0 deletions Changes
Expand Up @@ -3,6 +3,7 @@
- Code name "Rainbow", this is a major release.
- Removed Mojolicious::Plugin::I18N so it can be maintained as a separate
distribution.
- Removed app_class attribute from Mojo::Server.
- Renamed Mojo::CookieJar to Mojo::UserAgent::CookieJar.
- Renamed Mojo::Command to Mojolicious::Command.
- Moved get_all_data and get_data methods from Mojo::Command to
Expand Down
15 changes: 3 additions & 12 deletions lib/Mojo/Server.pm
Expand Up @@ -9,11 +9,10 @@ use Scalar::Util 'blessed';
has app => sub {
my $self = shift;
return $ENV{MOJO_APP} if ref $ENV{MOJO_APP};
if (my $e = Mojo::Loader->load($self->app_class)) { die $e if ref $e }
return $ENV{MOJO_APP} = $self->app_class->new;
my $class = $ENV{MOJO_APP} ||= 'Mojo::HelloWorld';
if (my $e = Mojo::Loader->load($class)) { die $e if ref $e }
return $ENV{MOJO_APP} = $class->new;
};
has app_class =>
sub { ref $ENV{MOJO_APP} || $ENV{MOJO_APP} || 'Mojo::HelloWorld' };

sub new {
my $self = shift->SUPER::new(@_);
Expand Down Expand Up @@ -110,14 +109,6 @@ L<Mojo::Server> implements the following attributes.
Application this server handles, defaults to a L<Mojo::HelloWorld> object.
=head2 C<app_class>
my $app_class = $server->app_class;
$server = $server->app_class('MojoSubclass');
Class of the application this server handles, defaults to the value of the
C<MOJO_APP> environment variable or L<Mojo::HelloWorld>.
=head1 METHODS
L<Mojo::Server> inherits all methods from L<Mojo::EventEmitter> and implements
Expand Down
3 changes: 2 additions & 1 deletion lib/Mojo/UserAgent.pm
Expand Up @@ -48,7 +48,8 @@ sub app {
# Try to detect application
$self->{app} ||= $ENV{MOJO_APP} if ref $ENV{MOJO_APP};
return $self->{app} unless $app;
$self->{app} = ref $app ? $app : $self->_server->app_class($app)->app;
$ENV{MOJO_APP} = $app unless ref $app;
$self->{app} = ref $app ? $app : $self->_server->app;
return $self;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Test/Mojo.pm
Expand Up @@ -23,7 +23,7 @@ sub new {
sub app {
my ($self, $app) = @_;
return $self->ua->app unless $app;
$self->ua->app($ENV{MOJO_APP} = $app);
$self->ua->app($app);
return $self;
}

Expand Down
9 changes: 1 addition & 8 deletions t/mojo/server.t
@@ -1,7 +1,7 @@
use Mojo::Base -strict;

# "Would you kindly shut your noise-hole?"
use Test::More tests => 4;
use Test::More tests => 3;

package Mojo::TestServerViaEnv;
use Mojo::Base 'Mojo';
Expand All @@ -23,13 +23,6 @@ isa_ok $server, 'Mojo::Server', 'right object';
isa_ok $app, 'Mojolicious::Lite', 'right default app';
}

# Test an explicit class name
{
local $ENV{MOJO_APP};
my $app = $server->new(app_class => 'Mojo::TestServerViaApp')->app;
isa_ok $app, 'Mojo::TestServerViaApp', 'right object';
}

# Test setting the class name through the environment
{
local $ENV{MOJO_APP} = 'Mojo::TestServerViaEnv';
Expand Down

0 comments on commit 28a744a

Please sign in to comment.