Skip to content

Commit

Permalink
small optimizations and documentation tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jun 22, 2012
1 parent 28a744a commit ec5e315
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
8 changes: 6 additions & 2 deletions lib/Mojo/Server.pm
Expand Up @@ -7,8 +7,11 @@ use Mojo::Util 'md5_sum';
use Scalar::Util 'blessed';

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

# Try to detect application
return $ENV{MOJO_APP} if ref $ENV{MOJO_APP};

# Load and initialize application
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;
Expand Down Expand Up @@ -107,7 +110,8 @@ L<Mojo::Server> implements the following attributes.
my $app = $server->app;
$server = $server->app(MojoSubclass->new);
Application this server handles, defaults to a L<Mojo::HelloWorld> object.
Application this server handles, defaults to the value of the C<MOJO_APP>
environment variable or a L<Mojo::HelloWorld> object.
=head1 METHODS
Expand Down
10 changes: 5 additions & 5 deletions lib/Mojo/UserAgent.pm
Expand Up @@ -48,18 +48,19 @@ sub app {
# Try to detect application
$self->{app} ||= $ENV{MOJO_APP} if ref $ENV{MOJO_APP};
return $self->{app} unless $app;

# Initialize application if necessary
$ENV{MOJO_APP} = $app unless ref $app;
$self->{app} = ref $app ? $app : $self->_server->app;

return $self;
}

sub app_url {
my $self = shift;

# Prepare application for testing
my $server = $self->_server(@_);
delete $server->{app};
$server->app($self->app);
$self->_server(@_)->app($self->app);

# Build absolute URL for test server
return Mojo::URL->new("$self->{scheme}://localhost:$self->{port}/");
Expand Down Expand Up @@ -799,8 +800,7 @@ implements the following new ones.
$ua = $ua->app(MyApp->new);
Application relative URLs will be processed with, defaults to the value of the
C<MOJO_APP> environment variable, which is usually a L<Mojo> or L<Mojolicious>
object.
C<MOJO_APP> environment variable or a L<Mojo::HelloWorld> object.
# Introspect
say $ua->app->secret;
Expand Down

0 comments on commit ec5e315

Please sign in to comment.