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/;
11 use namespace::autoclean;
13 with 'Catalyst::ScriptRole';
15 __PACKAGE__->meta->get_attribute('help')->cmd_aliases('?');
18 traits => [qw(Getopt)],
22 documentation => q{Force debug mode},
26 traits => [qw(Getopt)],
30 # N.B. undef (the default) means we bind on all interfaces on the host.
31 documentation => 'Specify a hostname or IP on this host for the server to bind to',
35 traits => [qw(Getopt)],
40 documentation => 'Fork the server to be able to serve multiple requests at once',
44 traits => [qw(Getopt)],
49 documentation => 'Specify a different listening port (to the default port 3000)',
53 traits => [qw(Getopt)],
57 documentation => 'Specify a pidfile',
61 traits => [qw(Getopt)],
66 documentation => 'Support keepalive',
70 traits => [qw(Getopt)],
75 documentation => 'Run in the background',
79 traits => [qw(Getopt)],
84 documentation => 'use Catalyst::Restarter to detect code changes and restart the application',
87 has restart_directory => (
88 traits => [qw(Getopt)],
89 cmd_aliases => [ 'rdir', 'restartdirectory' ],
92 documentation => 'Restarter directory to watch',
93 predicate => '_has_restart_directory',
96 has restart_delay => (
97 traits => [qw(Getopt)],
101 documentation => 'Set a restart delay',
102 predicate => '_has_restart_delay',
106 use Moose::Util::TypeConstraints;
108 my $tc = subtype as RegexpRef;
109 coerce $tc, from Str, via { qr/$_/ };
111 MooseX::Getopt::OptionTypeMap->add_option_type_to_map($tc => '=s');
113 has restart_regex => (
114 traits => [qw(Getopt)],
119 documentation => 'Restart regex',
120 predicate => '_has_restart_regex',
124 has follow_symlinks => (
125 traits => [qw(Getopt)],
126 cmd_aliases => 'sym',
130 documentation => 'Follow symbolic links',
131 predicate => '_has_follow_symlinks',
134 sub _restarter_args {
139 start_sub => sub { $self->_run_application },
140 ($self->_has_follow_symlinks ? (follow_symlinks => $self->follow_symlinks) : ()),
141 ($self->_has_restart_delay ? (sleep_interval => $self->restart_delay) : ()),
142 ($self->_has_restart_directory ? (directories => $self->restart_directory) : ()),
143 ($self->_has_restart_regex ? (filter => $self->restart_regex) : ()),
150 local $ENV{CATALYST_DEBUG} = 1
153 if ( $self->restart ) {
154 die "Cannot run in the background and also watch for changed files.\n"
155 if $self->background;
157 # If we load this here, then in the case of a restarter, it does not
158 # need to be reloaded for each restart.
161 # If this isn't done, then the Catalyst::Devel tests for the restarter
163 $| = 1 if $ENV{HARNESS_ACTIVE};
165 require Catalyst::Restarter;
167 my $subclass = Catalyst::Restarter->pick_subclass;
169 my $restarter = $subclass->new(
170 $self->_restarter_args()
173 $restarter->run_and_watch;
176 $self->_run_application;
182 sub _application_args {
188 map { $_ => $self->$_ } qw/
200 __PACKAGE__->meta->make_immutable;
206 Catalyst::Script::Server - Catalyst test server
210 myapp_server.pl [options]
213 -d --debug force debug mode
214 -f --fork handle each request in a new process
216 --help display this help and exits
217 -h --host host (defaults to all)
218 -p --port port (defaults to 3000)
219 -k --keepalive enable keep-alive connections
220 -r --restart restart when files get modified
222 --rd --restart_delay delay between file checks
223 (ignored if you have Linux::Inotify2 installed)
224 --rr --restart_regex regex match files that trigger
225 a restart when modified
226 (defaults to '\.yml$|\.yaml$|\.conf|\.pm$')
227 --rdir --restart_directory the directory to search for
228 modified files, can be set mulitple times
229 (defaults to '[SCRIPT_DIR]/..')
230 --sym --follow_symlinks follow symlinks in search directories
231 (defaults to false. this is a no-op on Win32)
232 --bg --background run the process in the background
233 --pid --pidfile specify filename for pid file
236 perldoc Catalyst::Manual
237 perldoc Catalyst::Manual::Intro
241 Run a Catalyst test server for this application.
245 Catalyst Contributors, see Catalyst.pm
249 This library is free software. You can redistribute it and/or modify
250 it under the same terms as Perl itself.