Merge trunk into here, fix tests to pass again with the newer versions of Plack
[catagits/Catalyst-Runtime.git] / lib / Catalyst / ScriptRole.pm
index 535ed3d..4d93e57 100644 (file)
@@ -3,6 +3,7 @@ use Moose::Role;
 use MooseX::Types::Moose qw/Str Bool/;
 use Pod::Usage;
 use MooseX::Getopt;
+use Plack::Loader;
 use namespace::autoclean;
 
 with 'MooseX::Getopt' => {
@@ -55,11 +56,23 @@ sub _application_args {
     ()
 }
 
+sub _plack_loader_args {
+    my @app_args = shift->_application_args;
+    return (port => $app_args[0]);
+}
+
 sub _run_application {
     my $self = shift;
     my $app = $self->application_name;
     Class::MOP::load_class($app);
-    $app->run($self->_application_args);
+    my $server;
+    if (my $e = $self->can('_plack_engine_name') ) {
+        $server = Plack::Loader->load($self->$e, $self->_plack_loader_args);
+    }
+    else {
+        $server = Plack::Loader->auto($self->_plack_loader_args);
+    }
+    $app->run($self->_application_args, $server);
 }
 
 1;