X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FScript%2FServer.pm;h=799ec430f6292138d3cb5dbd2061a0e9dcde8360;hb=df894348b6f8e0bea1b3d0576aad28027ee930df;hp=3afb63266adc47b2c327932d5681c4162c469309;hpb=000641983bc2af88ef662606c75535dde8381051;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/Script/Server.pm b/lib/Catalyst/Script/Server.pm index 3afb632..799ec43 100644 --- a/lib/Catalyst/Script/Server.pm +++ b/lib/Catalyst/Script/Server.pm @@ -3,6 +3,7 @@ use Moose; use MooseX::Types::Common::Numeric qw/PositiveInt/; use MooseX::Types::Moose qw/ArrayRef Str Bool Int RegexpRef/; use Catalyst::Utils; +use Try::Tiny; use namespace::autoclean; with 'Catalyst::ScriptRole'; @@ -46,31 +47,44 @@ has port => ( use Moose::Util::TypeConstraints; class_type 'MooseX::Daemonize::Pid::File'; -subtype 'MyStr', as Str, where { 1 }; # FIXME - Fuck ugly! -coerce 'MooseX::Daemonize::Pid::File', from 'MyStr', via { - Class::MOP::load_class("MooseX::Daemonize::Pid::File"); +subtype 'Catalyst::Script::Server::Types::Pidfile', + as 'MooseX::Daemonize::Pid::File'; + +coerce 'Catalyst::Script::Server::Types::Pidfile', from Str, via { + try { Class::MOP::load_class("MooseX::Daemonize::Pid::File") } + catch { + warn("Could not load MooseX::Daemonize::Pid::File, needed for --pid option\n"); + exit 1; + }; MooseX::Daemonize::Pid::File->new( file => $_ ); }; MooseX::Getopt::OptionTypeMap->add_option_type_to_map( - 'MooseX::Daemonize::Pid::File' => '=s', + 'Catalyst::Script::Server::Types::Pidfile' => '=s', ); has pidfile => ( traits => [qw(Getopt)], cmd_aliases => 'pid', - isa => 'MooseX::Daemonize::Pid::File', + isa => 'Catalyst::Script::Server::Types::Pidfile', is => 'ro', documentation => 'Specify a pidfile', coerce => 1, predicate => '_has_pidfile', ); +# Override MooseX::Daemonize +sub dont_close_all_files { 1 } sub BUILD { my $self = shift; if ($self->background) { # FIXME - This is evil. Should we just add MX::Daemonize to the deps? - Class::MOP::load_class('MooseX::Daemonize::Core'); + try { Class::MOP::load_class('MooseX::Daemonize::Core'); Class::MOP::load_class('POSIX') } + catch { + warn("MooseX::Daemonize is needed for the --background option\n"); + exit 1; + }; MooseX::Daemonize::Core->meta->apply($self); + POSIX::close($_) foreach (0..2); } } @@ -124,7 +138,7 @@ has restart_delay => ( { use Moose::Util::TypeConstraints; - my $tc = subtype as RegexpRef; + my $tc = subtype 'Catalyst::Script::Server::Types::RegexpRef', as RegexpRef; coerce $tc, from Str, via { qr/$_/ }; MooseX::Getopt::OptionTypeMap->add_option_type_to_map($tc => '=s'); @@ -152,7 +166,7 @@ has follow_symlinks => ( sub _plack_engine_name { my $self = shift; - return $self->fork ? 'Starman' : $self->keepalive ? 'Starman' : 'Standalone'; + return $self->fork || $self->keepalive ? 'Starman' : 'Standalone'; } sub _restarter_args { @@ -249,13 +263,13 @@ sub _plack_loader_args { ); } -sub _application_args { - my ($self) = shift; +around _application_args => sub { + my ($orig, $self) = @_; return ( $self->port, $self->host, { - argv => $self->ARGV, + %{ $self->$orig }, map { $_ => $self->$_ } qw/ fork keepalive @@ -263,13 +277,14 @@ sub _application_args { pidfile keepalive follow_symlinks + port + host /, }, ); -} +}; __PACKAGE__->meta->make_immutable; - 1; =head1 NAME @@ -311,6 +326,10 @@ Catalyst::Script::Server - Catalyst test server Run a Catalyst test server for this application. +=head1 SEE ALSO + +L + =head1 AUTHORS Catalyst Contributors, see Catalyst.pm