X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FScript%2FServer.pm;h=331bdc827b5acc9ccf8d37f65e6fdba06ff8eccb;hb=11606a7487a6ba3f19e3a6350e602e48937c5a34;hp=9438f050a31c0fc8143139f94e0ca4237d23c4d6;hpb=10255473102b269c35c8b9c8d3368bc962aa16e7;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/Script/Server.pm b/lib/Catalyst/Script/Server.pm index 9438f05..331bdc8 100644 --- a/lib/Catalyst/Script/Server.pm +++ b/lib/Catalyst/Script/Server.pm @@ -8,12 +8,11 @@ BEGIN { use Moose; use MooseX::Types::Common::Numeric qw/PositiveInt/; use MooseX::Types::Moose qw/ArrayRef Str Bool Int RegexpRef/; +use Catalyst::Utils; use namespace::autoclean; with 'Catalyst::ScriptRole'; -__PACKAGE__->meta->get_attribute('help')->cmd_aliases('?'); - has debug => ( traits => [qw(Getopt)], cmd_aliases => 'd', @@ -27,8 +26,8 @@ has host => ( cmd_aliases => 'h', isa => Str, is => 'ro', - default => 'localhost', - documentation => 'Specify an IP on this host for the server to bind to', + # N.B. undef (the default) means we bind on all interfaces on the host. + documentation => 'Specify a hostname or IP on this host for the server to bind to', ); has fork => ( @@ -45,7 +44,9 @@ has port => ( cmd_aliases => 'p', isa => PositiveInt, is => 'ro', - default => 3000, + default => sub { + Catalyst::Utils::env_value(shift->application_name, 'port') || 3000 + }, documentation => 'Specify a different listening port (to the default port 3000)', ); @@ -80,13 +81,15 @@ has restart => ( cmd_aliases => 'r', isa => Bool, is => 'ro', - default => 0, + default => sub { + Catalyst::Utils::env_value(shift->application_name, 'reload') || 0; + }, documentation => 'use Catalyst::Restarter to detect code changes and restart the application', ); has restart_directory => ( traits => [qw(Getopt)], - cmd_aliases => 'rdir', + cmd_aliases => [ 'rdir', 'restartdirectory' ], isa => ArrayRef[Str], is => 'ro', documentation => 'Restarter directory to watch', @@ -141,9 +144,22 @@ sub _restarter_args { ($self->_has_restart_delay ? (sleep_interval => $self->restart_delay) : ()), ($self->_has_restart_directory ? (directories => $self->restart_directory) : ()), ($self->_has_restart_regex ? (filter => $self->restart_regex) : ()), + ), + ( + map { $_ => $self->$_ } qw(application_name host port debug pidfile) ); } +has restarter_class => ( + is => 'ro', + isa => Str, + lazy => 1, + default => sub { + my $self = shift; + Catalyst::Utils::env_value($self->application_name, 'RESTARTER') || 'Catalyst::Restarter'; + } +); + sub run { my $self = shift; @@ -162,11 +178,10 @@ sub run { # fail. $| = 1 if $ENV{HARNESS_ACTIVE}; - require Catalyst::Restarter; + Catalyst::Utils::ensure_class_loaded($self->restarter_class); - my $subclass = Catalyst::Restarter->pick_subclass; + my $subclass = $self->restarter_class->pick_subclass; - my $restarter = $subclass->new( $self->_restarter_args() ); @@ -186,6 +201,7 @@ sub _application_args { $self->port, $self->host, { + argv => $self->ARGV, map { $_ => $self->$_ } qw/ fork keepalive @@ -220,13 +236,13 @@ Catalyst::Script::Server - Catalyst test server -k --keepalive enable keep-alive connections -r --restart restart when files get modified (defaults to false) - --rd --restartdelay delay between file checks + --rd --restart_delay delay between file checks (ignored if you have Linux::Inotify2 installed) - --rr --restartregex regex match files that trigger + --rr --restart_regex regex match files that trigger a restart when modified (defaults to '\.yml$|\.yaml$|\.conf|\.pm$') - --rdir --restartdirectory the directory to search for - modified files, can be set mulitple times + --rdir --restart_directory the directory to search for + modified files, can be set multiple times (defaults to '[SCRIPT_DIR]/..') --sym --follow_symlinks follow symlinks in search directories (defaults to false. this is a no-op on Win32)