[Catalyst-commits] r12614 - in Catalyst-Runtime/5.80/branches/psgi: lib/Catalyst lib/Catalyst/Script t/aggregate

t0m at dev.catalyst.perl.org t0m at dev.catalyst.perl.org
Mon Jan 11 23:36:52 GMT 2010


Author: t0m
Date: 2010-01-11 23:36:52 +0000 (Mon, 11 Jan 2010)
New Revision: 12614

Modified:
   Catalyst-Runtime/5.80/branches/psgi/lib/Catalyst/Engine.pm
   Catalyst-Runtime/5.80/branches/psgi/lib/Catalyst/Script/CGI.pm
   Catalyst-Runtime/5.80/branches/psgi/lib/Catalyst/Script/FastCGI.pm
   Catalyst-Runtime/5.80/branches/psgi/lib/Catalyst/Script/Server.pm
   Catalyst-Runtime/5.80/branches/psgi/lib/Catalyst/ScriptRole.pm
   Catalyst-Runtime/5.80/branches/psgi/t/aggregate/unit_core_script_cgi.t
   Catalyst-Runtime/5.80/branches/psgi/t/aggregate/unit_core_script_fastcgi.t
   Catalyst-Runtime/5.80/branches/psgi/t/aggregate/unit_core_script_server.t
Log:
Move everything back out into the scriptrole, allow the scripts to force their engine..

Modified: Catalyst-Runtime/5.80/branches/psgi/lib/Catalyst/Engine.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/psgi/lib/Catalyst/Engine.pm	2010-01-11 23:18:08 UTC (rev 12613)
+++ Catalyst-Runtime/5.80/branches/psgi/lib/Catalyst/Engine.pm	2010-01-11 23:36:52 UTC (rev 12614)
@@ -750,9 +750,9 @@
 =cut
 
 sub run {
-    my ($self, $app, @args) = @_;
+    my ($self, $app, $server, @args) = @_;
     # FIXME - Do something sensible with the options we're passed
-    $self->_run_psgi_app($self->_build_psgi_app($app, @args), @args);
+    $server->run($self->_build_psgi_app($app, @args));
 }
 
 sub _build_psgi_app {
@@ -781,12 +781,6 @@
     return $psgi_app;
 }
 
-sub _run_psgi_app {
-    my ($self, $psgi_app, @args) = @_;
-    # FIXME - Need to be able to specify engine and pass options..
-    Plack::Loader->auto(port => $args[0])->run($psgi_app);
-}
-
 =head2 $self->write($c, $buffer)
 
 Writes the buffer to the client.

Modified: Catalyst-Runtime/5.80/branches/psgi/lib/Catalyst/Script/CGI.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/psgi/lib/Catalyst/Script/CGI.pm	2010-01-11 23:18:08 UTC (rev 12613)
+++ Catalyst-Runtime/5.80/branches/psgi/lib/Catalyst/Script/CGI.pm	2010-01-11 23:36:52 UTC (rev 12614)
@@ -1,8 +1,9 @@
 package Catalyst::Script::CGI;
 use Moose;
-BEGIN { $ENV{CATALYST_ENGINE} ||= 'CGI' }
 use namespace::autoclean;
 
+sub _plack_engine_name { 'CGI' }
+
 with 'Catalyst::ScriptRole';
 
 __PACKAGE__->meta->make_immutable;

Modified: Catalyst-Runtime/5.80/branches/psgi/lib/Catalyst/Script/FastCGI.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/psgi/lib/Catalyst/Script/FastCGI.pm	2010-01-11 23:18:08 UTC (rev 12613)
+++ Catalyst-Runtime/5.80/branches/psgi/lib/Catalyst/Script/FastCGI.pm	2010-01-11 23:36:52 UTC (rev 12614)
@@ -1,10 +1,10 @@
 package Catalyst::Script::FastCGI;
-
-BEGIN { $ENV{CATALYST_ENGINE} ||= 'FastCGI' }
 use Moose;
 use MooseX::Types::Moose qw/Str Bool Int/;
 use namespace::autoclean;
 
+sub _plack_engine_name { 'FCGI' }
+
 with 'Catalyst::ScriptRole';
 
 has listen => (

Modified: Catalyst-Runtime/5.80/branches/psgi/lib/Catalyst/Script/Server.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/psgi/lib/Catalyst/Script/Server.pm	2010-01-11 23:18:08 UTC (rev 12613)
+++ Catalyst-Runtime/5.80/branches/psgi/lib/Catalyst/Script/Server.pm	2010-01-11 23:36:52 UTC (rev 12614)
@@ -1,16 +1,12 @@
 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;
 
+sub _plack_engine_name { 'Standalone' }
+
 with 'Catalyst::ScriptRole';
 
 __PACKAGE__->meta->get_attribute('help')->cmd_aliases('?');

Modified: Catalyst-Runtime/5.80/branches/psgi/lib/Catalyst/ScriptRole.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/psgi/lib/Catalyst/ScriptRole.pm	2010-01-11 23:18:08 UTC (rev 12613)
+++ Catalyst-Runtime/5.80/branches/psgi/lib/Catalyst/ScriptRole.pm	2010-01-11 23:36:52 UTC (rev 12614)
@@ -56,11 +56,23 @@
     ()
 }
 
+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($server, $self->_application_args);
 }
 
 1;

Modified: Catalyst-Runtime/5.80/branches/psgi/t/aggregate/unit_core_script_cgi.t
===================================================================
--- Catalyst-Runtime/5.80/branches/psgi/t/aggregate/unit_core_script_cgi.t	2010-01-11 23:18:08 UTC (rev 12613)
+++ Catalyst-Runtime/5.80/branches/psgi/t/aggregate/unit_core_script_cgi.t	2010-01-11 23:36:52 UTC (rev 12614)
@@ -15,6 +15,8 @@
     Catalyst::Script::CGI->new_with_options(application_name => 'TestAppToTestScripts')->run;
 } "new_with_options";
 shift @TestAppToTestScripts::RUN_ARGS;
+my $server = shift @TestAppToTestScripts::RUN_ARGS;
+like ref($server), qr/^Plack::Server/, 'Is a Plack Server';
 is_deeply \@TestAppToTestScripts::RUN_ARGS, [], "no args";
 
 done_testing;

Modified: Catalyst-Runtime/5.80/branches/psgi/t/aggregate/unit_core_script_fastcgi.t
===================================================================
--- Catalyst-Runtime/5.80/branches/psgi/t/aggregate/unit_core_script_fastcgi.t	2010-01-11 23:18:08 UTC (rev 12613)
+++ Catalyst-Runtime/5.80/branches/psgi/t/aggregate/unit_core_script_fastcgi.t	2010-01-11 23:36:52 UTC (rev 12614)
@@ -51,6 +51,8 @@
     } "new_with_options";
     # First element of RUN_ARGS will be the script name, which we don't care about
     shift @TestAppToTestScripts::RUN_ARGS;
+    my $server = shift @TestAppToTestScripts::RUN_ARGS;
+    like ref($server), qr/^Plack::Server/, 'Is a Plack Server';
     is_deeply \@TestAppToTestScripts::RUN_ARGS, $resultarray, "is_deeply comparison";
 }
 

Modified: Catalyst-Runtime/5.80/branches/psgi/t/aggregate/unit_core_script_server.t
===================================================================
--- Catalyst-Runtime/5.80/branches/psgi/t/aggregate/unit_core_script_server.t	2010-01-11 23:18:08 UTC (rev 12613)
+++ Catalyst-Runtime/5.80/branches/psgi/t/aggregate/unit_core_script_server.t	2010-01-11 23:36:52 UTC (rev 12614)
@@ -89,6 +89,8 @@
     };
     # First element of RUN_ARGS will be the script name, which we don't care about
     shift @TestAppToTestScripts::RUN_ARGS;
+    my $server = shift @TestAppToTestScripts::RUN_ARGS;
+    like ref($server), qr/^Plack::Server/, 'Is a Plack Server';
     is_deeply \@TestAppToTestScripts::RUN_ARGS, $resultarray, "is_deeply comparison " . join(' ', @$argstring);
 }
 




More information about the Catalyst-commits mailing list