Skip to content

Commit

Permalink
added daemon attribute to Mojo::Server::Morbo
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Mar 10, 2015
1 parent 37cee57 commit 6cd7658
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
3 changes: 2 additions & 1 deletion Changes
@@ -1,6 +1,7 @@

6.02 2015-03-09
- Improved portability of Morbo.
- Added daemon attribute to Mojo::Server::Morbo.
- Improved portability of Mojo::Server::Morbo.
- Fixed empty template handling in Mojo::Template.

6.01 2015-03-03
Expand Down
16 changes: 12 additions & 4 deletions lib/Mojo/Server/Morbo.pm
Expand Up @@ -8,7 +8,8 @@ use Mojo::Home;
use Mojo::Server::Daemon;
use POSIX 'WNOHANG';

has watch => sub { [qw(lib templates)] };
has daemon => sub { Mojo::Server::Daemon->new };
has watch => sub { [qw(lib templates)] };

sub check {
my $self = shift;
Expand Down Expand Up @@ -39,9 +40,9 @@ sub run {
$self->{modified} = 1;

# Prepare and cache listen sockets for smooth restarting
$self->{daemon} = Mojo::Server::Daemon->new->start->stop;
$self->daemon->start->stop;

$self->_manage while !$self->{finished} || $self->{worker};
$self->_manage until $self->{finished} && !$self->{worker};
exit 0;
}

Expand Down Expand Up @@ -83,7 +84,7 @@ sub _spawn {
return if $pid;

# Worker
my $daemon = $self->{daemon};
my $daemon = $self->daemon;
$daemon->load_app($self->watch->[0]);
$daemon->ioloop->recurring(1 => sub { shift->stop unless kill 0, $manager });
$daemon->run;
Expand Down Expand Up @@ -140,6 +141,13 @@ Shut down server immediately.
L<Mojo::Server::Morbo> implements the following attributes.
=head2 daemon
my $daemon = $morbo->daemon;
$morbo = $morbo->daemon(Mojo::Server::Daemon->new);
L<Mojo::Server::Daemon> object this server manages.
=head2 watch
my $watch = $morbo->watch;
Expand Down
2 changes: 1 addition & 1 deletion script/morbo
Expand Up @@ -18,9 +18,9 @@ if ($help || !$app) {
die Mojolicious::Command->new->extract_usage;
}

$ENV{MOJO_LISTEN} = join ',', @listen if @listen;
require Mojo::Server::Morbo;
my $morbo = Mojo::Server::Morbo->new;
$morbo->daemon->listen(\@listen) if @listen;
$morbo->watch(\@watch) if @watch;
$morbo->run($app);

Expand Down

0 comments on commit 6cd7658

Please sign in to comment.