Change Catalsyt _parse_attrs so that when sub attr handlers:
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Script / Server.pm
index 328773c..799ec43 100644 (file)
@@ -48,8 +48,8 @@ has port => (
 use Moose::Util::TypeConstraints;
 class_type 'MooseX::Daemonize::Pid::File';
 subtype 'Catalyst::Script::Server::Types::Pidfile',
-    as 'MooseX::Daemonize::Pid::File',
-    where { 1 };
+    as 'MooseX::Daemonize::Pid::File';
+
 coerce 'Catalyst::Script::Server::Types::Pidfile', from Str, via {
     try { Class::MOP::load_class("MooseX::Daemonize::Pid::File") }
     catch {
@@ -71,17 +71,20 @@ has pidfile => (
     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?
-        try { 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);
     }
 }
 
@@ -163,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 {
@@ -260,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
@@ -274,13 +277,14 @@ sub _application_args {
                 pidfile
                 keepalive
                 follow_symlinks
+                port
+                host
             /,
         },
     );
-}
+};
 
 __PACKAGE__->meta->make_immutable;
-
 1;
 
 =head1 NAME
@@ -322,6 +326,10 @@ Catalyst::Script::Server - Catalyst test server
 
 Run a Catalyst test server for this application.
 
+=head1 SEE ALSO
+
+L<Catalyst::ScriptRunner>
+
 =head1 AUTHORS
 
 Catalyst Contributors, see Catalyst.pm