1 package Catalyst::Script::Server;
4 $ENV{CATALYST_ENGINE} ||= 'HTTP';
5 require Catalyst::Engine::HTTP;
9 use MooseX::Types::Common::Numeric qw/PositiveInt/;
10 use MooseX::Types::Moose qw/ArrayRef Str Bool Int RegexpRef/;
12 use namespace::autoclean;
14 with 'Catalyst::ScriptRole';
16 __PACKAGE__->meta->get_attribute('help')->cmd_aliases('?');
19 traits => [qw(Getopt)],
23 documentation => q{Force debug mode},
27 traits => [qw(Getopt)],
31 # N.B. undef (the default) means we bind on all interfaces on the host.
32 documentation => 'Specify a hostname or IP on this host for the server to bind to',
36 traits => [qw(Getopt)],
41 documentation => 'Fork the server to be able to serve multiple requests at once',
45 traits => [qw(Getopt)],
50 Catalyst::Utils::env_value(shift->application_name, 'port') || 3000
52 documentation => 'Specify a different listening port (to the default port 3000)',
56 traits => [qw(Getopt)],
60 documentation => 'Specify a pidfile',
64 traits => [qw(Getopt)],
69 documentation => 'Support keepalive',
73 traits => [qw(Getopt)],
78 documentation => 'Run in the background',
82 traits => [qw(Getopt)],
87 Catalyst::Utils::env_value(shift->application_name, 'reload') || 0;
89 documentation => 'use Catalyst::Restarter to detect code changes and restart the application',
92 has restart_directory => (
93 traits => [qw(Getopt)],
94 cmd_aliases => [ 'rdir', 'restartdirectory' ],
97 documentation => 'Restarter directory to watch',
98 predicate => '_has_restart_directory',
101 has restart_delay => (
102 traits => [qw(Getopt)],
106 documentation => 'Set a restart delay',
107 predicate => '_has_restart_delay',
111 use Moose::Util::TypeConstraints;
113 my $tc = subtype as RegexpRef;
114 coerce $tc, from Str, via { qr/$_/ };
116 MooseX::Getopt::OptionTypeMap->add_option_type_to_map($tc => '=s');
118 has restart_regex => (
119 traits => [qw(Getopt)],
124 documentation => 'Restart regex',
125 predicate => '_has_restart_regex',
129 has follow_symlinks => (
130 traits => [qw(Getopt)],
131 cmd_aliases => 'sym',
135 documentation => 'Follow symbolic links',
136 predicate => '_has_follow_symlinks',
139 sub _restarter_args {
144 start_sub => sub { $self->_run_application },
145 ($self->_has_follow_symlinks ? (follow_symlinks => $self->follow_symlinks) : ()),
146 ($self->_has_restart_delay ? (sleep_interval => $self->restart_delay) : ()),
147 ($self->_has_restart_directory ? (directories => $self->restart_directory) : ()),
148 ($self->_has_restart_regex ? (filter => $self->restart_regex) : ()),
155 local $ENV{CATALYST_DEBUG} = 1
158 if ( $self->restart ) {
159 die "Cannot run in the background and also watch for changed files.\n"
160 if $self->background;
162 # If we load this here, then in the case of a restarter, it does not
163 # need to be reloaded for each restart.
166 # If this isn't done, then the Catalyst::Devel tests for the restarter
168 $| = 1 if $ENV{HARNESS_ACTIVE};
170 require Catalyst::Restarter;
172 my $subclass = Catalyst::Restarter->pick_subclass;
174 my $restarter = $subclass->new(
175 $self->_restarter_args()
178 $restarter->run_and_watch;
181 $self->_run_application;
187 sub _application_args {
194 map { $_ => $self->$_ } qw/
206 __PACKAGE__->meta->make_immutable;
212 Catalyst::Script::Server - Catalyst test server
216 myapp_server.pl [options]
219 -d --debug force debug mode
220 -f --fork handle each request in a new process
222 --help display this help and exits
223 -h --host host (defaults to all)
224 -p --port port (defaults to 3000)
225 -k --keepalive enable keep-alive connections
226 -r --restart restart when files get modified
228 --rd --restart_delay delay between file checks
229 (ignored if you have Linux::Inotify2 installed)
230 --rr --restart_regex regex match files that trigger
231 a restart when modified
232 (defaults to '\.yml$|\.yaml$|\.conf|\.pm$')
233 --rdir --restart_directory the directory to search for
234 modified files, can be set mulitple times
235 (defaults to '[SCRIPT_DIR]/..')
236 --sym --follow_symlinks follow symlinks in search directories
237 (defaults to false. this is a no-op on Win32)
238 --bg --background run the process in the background
239 --pid --pidfile specify filename for pid file
242 perldoc Catalyst::Manual
243 perldoc Catalyst::Manual::Intro
247 Run a Catalyst test server for this application.
251 Catalyst Contributors, see Catalyst.pm
255 This library is free software. You can redistribute it and/or modify
256 it under the same terms as Perl itself.