X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FScript%2FServer.pm;h=e40da5ea021fb8d4e29230b00855b1d5c931cd29;hb=60bfba3ff3546d7e646699b944a75a4b01e50fae;hp=619177d1b538f0a19d4eeea9223772d0059b8e62;hpb=abee32cb2343c5ce0eb3fc92d403d6d535a66e0f;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/Script/Server.pm b/lib/Catalyst/Script/Server.pm index 619177d..e40da5e 100644 --- a/lib/Catalyst/Script/Server.pm +++ b/lib/Catalyst/Script/Server.pm @@ -2,152 +2,121 @@ package Catalyst::Script::Server; BEGIN { $ENV{CATALYST_ENGINE} ||= 'HTTP'; - $ENV{CATALYST_SCRIPT_GEN} = 31; require Catalyst::Engine::HTTP; } -use FindBin qw/$Bin/; -use lib "$Bin/../lib"; -use Pod::Usage; use Moose; use Catalyst::Restarter; -#use Catalyst::Engine::HTTP; +use MooseX::Types::Moose qw/ArrayRef Str Bool Int/; use namespace::autoclean; -with 'MooseX::Getopt'; +with 'Catalyst::ScriptRole'; has debug => ( traits => [qw(Getopt)], cmd_aliases => 'd', - isa => 'Bool', + isa => Bool, is => 'ro', - documentation => qq{ - -d --debug force debug mode - } - -); - -has help => ( - traits => [qw(Getopt)], - cmd_aliases => 'h', - isa => 'Bool', - is => 'ro', - documentation => qq{ - -h --help display this help and exits - }, + documentation => q{Force debug mode}, ); has host => ( - isa => 'Str', + traits => [qw(Getopt)], + isa => Str, is => 'ro', - , - default => "localhost" + default => 'localhost', + documentation => 'Specify a host for the server to run on', ); has fork => ( traits => [qw(Getopt)], cmd_aliases => 'f', - isa => 'Bool', + isa => Bool, is => 'ro', - + documentation => 'Fork the server', ); has listen => ( traits => [qw(Getopt)], cmd_aliases => 'l', - isa => 'Int', + isa => Int, is => 'ro', - , - default => "3000" + default => 3000, + documentation => 'Specify a different listening port', ); has pidfile => ( traits => [qw(Getopt)], cmd_aliases => 'pid', - isa => 'Str', + isa => Str, is => 'ro', - + documentation => 'Specify a pidfile', ); has keepalive => ( traits => [qw(Getopt)], cmd_aliases => 'k', - isa => 'Bool', + isa => Bool, is => 'ro', - , + documentation => 'Server keepalive', ); has background => ( traits => [qw(Getopt)], cmd_aliases => 'bg', - isa => 'Bool', - is => 'ro', -); - - -has _app => ( - reader => 'app', - init_arg => 'app', - traits => [qw(NoGetopt)], - isa => 'Str', + isa => Bool, is => 'ro', + documentation => 'Run in the background', ); has restart => ( traits => [qw(Getopt)], cmd_aliases => 'r', - isa => 'Bool', + isa => Bool, is => 'ro', - + documentation => 'use Catalyst::Restarter to detect code changes', ); has restart_directory => ( traits => [qw(Getopt)], cmd_aliases => 'rdir', - isa => 'ArrayRef[Str]', + isa => ArrayRef[Str], is => 'ro', predicate => '_has_restart_directory', + documentation => 'Restarter directory to watch', ); has restart_delay => ( traits => [qw(Getopt)], cmd_aliases => 'rdel', - isa => 'Int', + isa => Int, is => 'ro', predicate => '_has_restart_delay', + documentation => 'Set a restart delay', ); has restart_regex => ( traits => [qw(Getopt)], cmd_aliases => 'rxp', - isa => 'Str', + isa => Str, is => 'ro', predicate => '_has_restart_regex', + documentation => 'Restart regex', ); has follow_symlinks => ( traits => [qw(Getopt)], cmd_aliases => 'sym', - isa => 'Bool', + isa => Bool, is => 'ro', predicate => '_has_follow_symlinks', + documentation => 'Follow symbolic links', ); -sub usage { - my ($self) = shift; - - return pod2usage(); - -} - -my @argv = @ARGV; - sub run { - my $self = shift; - - $self->usage if $self->help; + my ($self) = shift; if ( $self->debug ) { $ENV{CATALYST_DEBUG} = 1; @@ -181,51 +150,48 @@ sub run { my $restarter = $subclass->new( %args, - start_sub => sub { $self->_run }, + start_sub => sub { $self->_run_application }, argv => $self->ARGV, ); $restarter->run_and_watch; } else { - $self->_run; + $self->_run_application; } } -sub _run { +sub _application_args { my ($self) = shift; - - my $app = $self->app; - Class::MOP::load_class($app); - - $app->run( - $self->listen, $self->host, + return ( + $self->listen, + $self->host, { - 'fork' => $self->fork, - keepalive => $self->keepalive, - background => $self->background, - pidfile => $self->pidfile, - keepalive => $self->keepalive, - follow_symlinks => $self->follow_symlinks, - } + map { $_ => $self->$_ } qw/ + fork + keepalive + background + pidfile + keepalive + follow_symlinks + /, + }, ); } - -no Moose; __PACKAGE__->meta->make_immutable; 1; =head1 NAME -[% appprefix %]_server.pl - Catalyst Testserver +Catalyst::Script::Server - Catalyst test server =head1 SYNOPSIS -[% appprefix %]_server.pl [options] + myapp_server.pl [options] Options: -d --debug force debug mode @@ -256,7 +222,7 @@ __PACKAGE__->meta->make_immutable; =head1 DESCRIPTION -Run a Catalyst Testserver for this application. +Run a Catalyst test server for this application. =head1 AUTHORS