Fixes port environment, RT#52604
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Script / Server.pm
index df78134..8226af4 100644 (file)
@@ -8,6 +8,7 @@ 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';
@@ -27,8 +28,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 +46,10 @@ has port => (
     cmd_aliases   => 'p',
     isa           => PositiveInt,
     is            => 'ro',
-    default       => 3000,
+    default       => sub {
+        my $self = shift;
+        $ENV{ Catalyst::Utils::class2env($self->application_name . '_PORT')}||3000
+    },
     documentation => 'Specify a different listening port (to the default port 3000)',
 );
 
@@ -86,7 +90,7 @@ has restart => (
 
 has restart_directory => (
     traits        => [qw(Getopt)],
-    cmd_aliases   => 'rdir',
+    cmd_aliases   => [ 'rdir', 'restartdirectory' ],
     isa           => ArrayRef[Str],
     is            => 'ro',
     documentation => 'Restarter directory to watch',
@@ -134,7 +138,7 @@ has follow_symlinks => (
 sub _restarter_args {
     my $self = shift;
 
-    my %args = (
+    return (
         argv => $self->ARGV,
         start_sub => sub { $self->_run_application },
         ($self->_has_follow_symlinks   ? (follow_symlinks => $self->follow_symlinks)   : ()),
@@ -142,8 +146,6 @@ sub _restarter_args {
         ($self->_has_restart_directory ? (directories     => $self->restart_directory) : ()),
         ($self->_has_restart_regex     ? (filter          => $self->restart_regex)     : ()),
     );
-
-    return %args;
 }
 
 sub run {
@@ -168,7 +170,6 @@ sub run {
 
         my $subclass = Catalyst::Restarter->pick_subclass;
 
-        
         my $restarter = $subclass->new(
             $self->_restarter_args()
         );
@@ -222,12 +223,12 @@ 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
+   --rdir --restart_directory  the directory to search for
                       modified files, can be set mulitple times
                       (defaults to '[SCRIPT_DIR]/..')
    --sym  --follow_symlinks   follow symlinks in search directories