=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 {
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.
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;
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 => (
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('?');
()
}
+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;
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;
} "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";
}
};
# 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);
}