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';
17 traits => [qw(Getopt)],
21 documentation => q{Force debug mode},
25 traits => [qw(Getopt)],
29 # N.B. undef (the default) means we bind on all interfaces on the host.
30 documentation => 'Specify a hostname or IP on this host for the server to bind to',
34 traits => [qw(Getopt)],
39 documentation => 'Fork the server to be able to serve multiple requests at once',
43 traits => [qw(Getopt)],
48 Catalyst::Utils::env_value(shift->application_name, 'port') || 3000
50 documentation => 'Specify a different listening port (to the default port 3000)',
54 traits => [qw(Getopt)],
58 documentation => 'Specify a pidfile',
62 traits => [qw(Getopt)],
67 documentation => 'Support keepalive',
71 traits => [qw(Getopt)],
76 documentation => 'Run in the background',
80 traits => [qw(Getopt)],
85 Catalyst::Utils::env_value(shift->application_name, 'reload') || 0;
87 documentation => 'use Catalyst::Restarter to detect code changes and restart the application',
90 has restart_directory => (
91 traits => [qw(Getopt)],
92 cmd_aliases => [ 'rdir', 'restartdirectory' ],
95 documentation => 'Restarter directory to watch',
96 predicate => '_has_restart_directory',
99 has restart_delay => (
100 traits => [qw(Getopt)],
104 documentation => 'Set a restart delay',
105 predicate => '_has_restart_delay',
109 use Moose::Util::TypeConstraints;
111 my $tc = subtype as RegexpRef;
112 coerce $tc, from Str, via { qr/$_/ };
114 MooseX::Getopt::OptionTypeMap->add_option_type_to_map($tc => '=s');
116 has restart_regex => (
117 traits => [qw(Getopt)],
122 documentation => 'Restart regex',
123 predicate => '_has_restart_regex',
127 has follow_symlinks => (
128 traits => [qw(Getopt)],
129 cmd_aliases => 'sym',
133 documentation => 'Follow symbolic links',
134 predicate => '_has_follow_symlinks',
137 sub _restarter_args {
142 start_sub => sub { $self->_run_application },
143 ($self->_has_follow_symlinks ? (follow_symlinks => $self->follow_symlinks) : ()),
144 ($self->_has_restart_delay ? (sleep_interval => $self->restart_delay) : ()),
145 ($self->_has_restart_directory ? (directories => $self->restart_directory) : ()),
146 ($self->_has_restart_regex ? (filter => $self->restart_regex) : ()),
150 has restarter_class => (
156 Catalyst::Utils::env_value($self->application_name, 'RESTARTER') || 'Catalyst::Restarter';
163 local $ENV{CATALYST_DEBUG} = 1
166 if ( $self->restart ) {
167 die "Cannot run in the background and also watch for changed files.\n"
168 if $self->background;
170 # If we load this here, then in the case of a restarter, it does not
171 # need to be reloaded for each restart.
174 # If this isn't done, then the Catalyst::Devel tests for the restarter
176 $| = 1 if $ENV{HARNESS_ACTIVE};
178 Catalyst::Utils::load_class($self->restarter_class);
180 my $subclass = $self->restarter_class->pick_subclass;
182 my $restarter = $subclass->new(
183 $self->_restarter_args()
186 $restarter->run_and_watch;
189 $self->_run_application;
195 sub _application_args {
202 map { $_ => $self->$_ } qw/
214 __PACKAGE__->meta->make_immutable;
220 Catalyst::Script::Server - Catalyst test server
224 myapp_server.pl [options]
227 -d --debug force debug mode
228 -f --fork handle each request in a new process
230 --help display this help and exits
231 -h --host host (defaults to all)
232 -p --port port (defaults to 3000)
233 -k --keepalive enable keep-alive connections
234 -r --restart restart when files get modified
236 --rd --restart_delay delay between file checks
237 (ignored if you have Linux::Inotify2 installed)
238 --rr --restart_regex regex match files that trigger
239 a restart when modified
240 (defaults to '\.yml$|\.yaml$|\.conf|\.pm$')
241 --rdir --restart_directory the directory to search for
242 modified files, can be set multiple times
243 (defaults to '[SCRIPT_DIR]/..')
244 --sym --follow_symlinks follow symlinks in search directories
245 (defaults to false. this is a no-op on Win32)
246 --bg --background run the process in the background
247 --pid --pidfile specify filename for pid file
250 perldoc Catalyst::Manual
251 perldoc Catalyst::Manual::Intro
255 Run a Catalyst test server for this application.
259 Catalyst Contributors, see Catalyst.pm
263 This library is free software. You can redistribute it and/or modify
264 it under the same terms as Perl itself.