From: Tomas Doran Date: Mon, 11 Jan 2010 23:36:52 +0000 (+0000) Subject: Move everything back out into the scriptrole, allow the scripts to force their engine.. X-Git-Tag: 5.89000~46 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=c821df216d6d7e7e0386516e43c0c09fd4a295e7 Move everything back out into the scriptrole, allow the scripts to force their engine.. --- diff --git a/lib/Catalyst/Engine.pm b/lib/Catalyst/Engine.pm index c8e9c7c..62dc3bc 100644 --- a/lib/Catalyst/Engine.pm +++ b/lib/Catalyst/Engine.pm @@ -750,9 +750,9 @@ Start the engine. Implemented by the various engine classes. =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 @@ sub _build_psgi_app { 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. diff --git a/lib/Catalyst/Script/CGI.pm b/lib/Catalyst/Script/CGI.pm index e80a5f7..7e53ba5 100644 --- a/lib/Catalyst/Script/CGI.pm +++ b/lib/Catalyst/Script/CGI.pm @@ -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; diff --git a/lib/Catalyst/Script/FastCGI.pm b/lib/Catalyst/Script/FastCGI.pm index 271d575..0029995 100644 --- a/lib/Catalyst/Script/FastCGI.pm +++ b/lib/Catalyst/Script/FastCGI.pm @@ -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 => ( diff --git a/lib/Catalyst/Script/Server.pm b/lib/Catalyst/Script/Server.pm index 4fc199b..5b8e3c1 100644 --- a/lib/Catalyst/Script/Server.pm +++ b/lib/Catalyst/Script/Server.pm @@ -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('?'); diff --git a/lib/Catalyst/ScriptRole.pm b/lib/Catalyst/ScriptRole.pm index 153c55e..af47fd2 100644 --- a/lib/Catalyst/ScriptRole.pm +++ b/lib/Catalyst/ScriptRole.pm @@ -56,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($server, $self->_application_args); } 1; diff --git a/t/aggregate/unit_core_script_cgi.t b/t/aggregate/unit_core_script_cgi.t index ba187e1..f39e377 100644 --- a/t/aggregate/unit_core_script_cgi.t +++ b/t/aggregate/unit_core_script_cgi.t @@ -15,6 +15,8 @@ lives_ok { 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; diff --git a/t/aggregate/unit_core_script_fastcgi.t b/t/aggregate/unit_core_script_fastcgi.t index b5d3ea4..01e4339 100644 --- a/t/aggregate/unit_core_script_fastcgi.t +++ b/t/aggregate/unit_core_script_fastcgi.t @@ -51,6 +51,8 @@ sub testOption { } "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"; } diff --git a/t/aggregate/unit_core_script_server.t b/t/aggregate/unit_core_script_server.t index c75cec6..d901354 100644 --- a/t/aggregate/unit_core_script_server.t +++ b/t/aggregate/unit_core_script_server.t @@ -89,6 +89,8 @@ sub testOption { }; # 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); }