package Catalyst::Script::Server;
-
-BEGIN {
- $ENV{CATALYST_ENGINE} ||= 'HTTP';
- require Catalyst::Engine::HTTP;
-}
-
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';
+sub _plack_engine_name { 'Standalone' }
-__PACKAGE__->meta->get_attribute('help')->cmd_aliases('?');
+with 'Catalyst::ScriptRole';
has debug => (
traits => [qw(Getopt)],
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 => (
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)',
);
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',
my $subclass = Catalyst::Restarter->pick_subclass;
-
my $restarter = $subclass->new(
$self->_restarter_args()
);
}
+sub _plack_loader_args {
+ my ($self) = shift;
+ return (
+ port => $self->port,
+ host => $self->host,
+ keepalive => $self->keepalive ? 100 : 1,
+ server_ready => sub {
+ my ($args) = @_;
+
+ my $name = $args->{server_software} || ref($args); # $args is $server
+ my $host = $args->{host} || 0;
+ my $proto = $args->{proto} || 'http';
+
+ print STDERR "$name: Accepting connections at $proto://$host:$args->{port}/\n";
+ },
+ );
+}
+
sub _application_args {
my ($self) = shift;
return (
$self->port,
$self->host,
{
+ argv => $self->ARGV,
map { $_ => $self->$_ } qw/
fork
keepalive
-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)