Skip to content

Commit

Permalink
fixed Windows bug in asset.t and added support for MOJO_LISTEN enviro…
Browse files Browse the repository at this point in the history
…nment variable
  • Loading branch information
kraih committed Mar 6, 2012
1 parent a920d72 commit 7d78aed
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 26 deletions.
3 changes: 3 additions & 0 deletions Changes
@@ -1,8 +1,11 @@
This file documents the revision history for Perl extension Mojolicious.

2.58 2012-03-06 00:00:00
- Added support for MOJO_LISTEN environment variable.
- Removed listen attribute from Mojo::Server::Morbo.
- Improved documentation.
- Fixed small caching bug in Morbo file watcher.
- Fixed Windows bug in "asset.t".

2.57 2012-03-03 00:00:00
- Replaced protection from excessively large form values in
Expand Down
14 changes: 8 additions & 6 deletions lib/Mojo/Server/Daemon.pm
Expand Up @@ -15,11 +15,12 @@ use constant BONJOUR => $ENV{MOJO_NO_BONJOUR}

use constant DEBUG => $ENV{MOJO_DAEMON_DEBUG} || 0;

has [qw/backlog group listen silent user/];
has [qw/backlog group silent user/];
has inactivity_timeout => sub { $ENV{MOJO_INACTIVITY_TIMEOUT} // 15 };
has ioloop => sub { Mojo::IOLoop->singleton };
has max_clients => 1000;
has max_requests => 25;
has ioloop => sub { Mojo::IOLoop->singleton };
has listen => sub { [split /,/, $ENV{MOJO_LISTEN} || 'http://*:3000'] };
has max_clients => 1000;
has max_requests => 25;

sub DESTROY {
my $self = shift;
Expand Down Expand Up @@ -73,7 +74,7 @@ sub setuidgid {

sub start {
my $self = shift;
$self->_listen($_) for @{$self->listen || ['http://*:3000']};
$self->_listen($_) for @{$self->listen};
$self->ioloop->max_connections($self->max_clients);
}

Expand Down Expand Up @@ -417,7 +418,8 @@ singleton.
my $listen = $daemon->listen;
$daemon = $daemon->listen(['https://localhost:3000']);
List of one or more locations to listen on, defaults to C<http://*:3000>.
List of one or more locations to listen on, defaults to the value of the
C<MOJO_LISTEN> environment variable or C<http://*:3000>.
# Listen on two ports with HTTP and HTTPS at the same time
$daemon->listen(['http://*:3000', 'https://*:4000']);
Expand Down
11 changes: 1 addition & 10 deletions lib/Mojo/Server/Morbo.pm
Expand Up @@ -8,8 +8,7 @@ use POSIX 'WNOHANG';

use constant DEBUG => $ENV{MORBO_DEBUG} || 0;

has listen => sub { [] };
has watch => sub { [qw/lib templates/] };
has watch => sub { [qw/lib templates/] };

# "All in all, this is one day Mittens the kitten won’t soon forget.
# Kittens give Morbo gas.
Expand Down Expand Up @@ -112,7 +111,6 @@ sub _spawn {
my $daemon = Mojo::Server::Daemon->new;
$daemon->load_app($self->watch->[0]);
$daemon->silent(1) if $ENV{MORBO_REV} > 1;
$daemon->listen($self->listen) if @{$self->listen};
$daemon->start;
my $loop = $daemon->ioloop;
$loop->recurring(
Expand Down Expand Up @@ -157,13 +155,6 @@ C<MOJO_NO_BONJOUR>, C<MOJO_NO_IPV6> and C<MOJO_NO_TLS> environment variables.
L<Mojo::Server::Morbo> implements the following attributes.
=head2 C<listen>
my $listen = $morbo->listen;
$morbo = $morbo->listen(['http://*:3000']);
List of one or more locations to listen on, defaults to C<http://*:3000>.
=head2 C<watch>
my $watch = $morbo->watch;
Expand Down
3 changes: 2 additions & 1 deletion lib/Mojolicious/Command/daemon.pm
Expand Up @@ -17,7 +17,8 @@ These options are available:
-i, --inactivity <seconds> Set inactivity timeout, defaults to the value
of MOJO_INACTIVITY_TIMEOUT or 15.
-l, --listen <location> Set one or more locations you want to listen
on, defaults to "http://*:3000".
on, defaults to the value of MOJO_LISTEN or
"http://*:3000".
-p, --proxy Activate reverse proxy support, defaults to
the value of MOJO_REVERSE_PROXY.
-r, --requests <number> Set maximum number of requests per keep-alive
Expand Down
7 changes: 4 additions & 3 deletions script/morbo
Expand Up @@ -43,7 +43,8 @@ usage: $0 [OPTIONS] [APPLICATION]
These options are available:
-h, --help Show this message.
-l, --listen <location> Set one or more locations you want to listen
on, defaults to "http://*:3000".
on, defaults to the value of MOJO_LISTEN or
"http://*:3000".
-v, --verbose Print details about what files changed to
STDOUT.
-w, --watch <directory/file> Set one or more directories and files to
Expand All @@ -56,9 +57,9 @@ EOF
# "With Halley's Comet out of ice, Earth is experiencing a sudden case of
# global warming.
# Morbo is pleased but sticky."
$ENV{MOJO_LISTEN} = join(',', @listen) if @listen;
my $morbo = Mojo::Server::Morbo->new;
$morbo->listen(\@listen) if @listen;
$morbo->watch(\@watch) if @watch;
$morbo->watch(\@watch) if @watch;
$morbo->run($app);

__END__
Expand Down
17 changes: 16 additions & 1 deletion t/mojo/app.t
Expand Up @@ -6,7 +6,7 @@ BEGIN {
$ENV{MOJO_IOWATCHER} = 'Mojo::IOWatcher';
}

use Test::More tests => 53;
use Test::More tests => 56;

# "I was so bored I cut the pony tail off the guy in front of us.
# Look at me, I'm a grad student.
Expand All @@ -30,6 +30,21 @@ use_ok 'Mojolicious';
is(Mojo::Server::Daemon->new->inactivity_timeout, 0, 'right value');
}

# Listen
{
is_deeply(Mojo::Server::Daemon->new->listen,
['http://*:3000'], 'right value');
local $ENV{MOJO_LISTEN} = 'http://localhost:8080';
is_deeply(Mojo::Server::Daemon->new->listen,
['http://localhost:8080'], 'right value');
$ENV{MOJO_LISTEN} = 'http://*:80,https://*:443';
is_deeply(
Mojo::Server::Daemon->new->listen,
['http://*:80', 'https://*:443'],
'right value'
);
}

# Logger
my $logger = Mojo::Log->new;
my $app = Mojo->new({log => $logger});
Expand Down
22 changes: 17 additions & 5 deletions t/mojo/asset.t
@@ -1,6 +1,6 @@
use Mojo::Base -strict;

use Test::More tests => 57;
use Test::More tests => 65;

# "And now, in the spirit of the season: start shopping.
# And for every dollar of Krusty merchandise you buy,
Expand Down Expand Up @@ -108,18 +108,30 @@ $mem = Mojo::Asset::Memory->new;
$mem->add_chunk('abc');
my $tmp = Mojo::Asset::File->new;
$tmp->add_chunk('x');
$mem->move_to($tmp->path);
is $mem->slurp, 'abc', 'right content';
$path = $tmp->path;
ok -e $path, 'file exists';
undef $tmp;
ok !-e $path, 'file has been cleaned up';
$mem->move_to($path);
is $mem->slurp, 'abc', 'right content';
ok -e $path, 'file exists';
unlink $path;
ok !-e $path, 'file has been cleaned up';

# Move file asset to file
$file = Mojo::Asset::File->new;
$file->add_chunk('bcd');
$tmp = Mojo::Asset::File->new;
$tmp->add_chunk('x');
$file->move_to($tmp->path);
is $file->slurp, 'bcd', 'right content';
$path = $tmp->path;
ok -e $path, 'file exists';
undef $tmp;
ok !-e $path, 'file has been cleaned up';
$file->move_to($path);
is $file->slurp, 'bcd', 'right content';
ok -e $path, 'file exists';
unlink $path;
ok !-e $path, 'file has been cleaned up';

# Upgrade
my $asset = Mojo::Asset::Memory->new(max_memory_size => 5, auto_upgrade => 1);
Expand Down

0 comments on commit 7d78aed

Please sign in to comment.