1 package Catalyst::Script::Server;
4 $ENV{CATALYST_ENGINE} ||= 'HTTP';
5 $ENV{CATALYST_SCRIPT_GEN} = 31;
6 require Catalyst::Engine::HTTP;
10 use lib "$Bin/../lib";
13 use Catalyst::Restarter;
14 use MooseX::Types::Moose qw/Str Bool Int/;
15 use namespace::autoclean;
17 with 'MooseX::Getopt';
20 traits => [qw(Getopt)],
24 documentation => qq{ force debug mode }
28 traits => [qw(Getopt)],
32 documentation => qq{ display this help and exits },
38 default => "localhost",
39 documentation => qq{ specify a host for the server to run on }
43 traits => [qw(Getopt)],
47 documentation => qq{ fork the server }
51 traits => [qw(Getopt)],
56 documentation => qq{ specify a different listening port }
60 traits => [qw(Getopt)],
64 documentation => qq{ specify a pidfile }
68 traits => [qw(Getopt)],
72 documentation => qq{ server keepalive },
77 traits => [qw(Getopt)],
81 documentation => qq{ run in the background }
88 traits => [qw(NoGetopt)],
94 traits => [qw(Getopt)],
98 documentation => qq{ use Catalyst::Restarter to detect code changes }
101 has restart_directory => (
102 traits => [qw(Getopt)],
103 cmd_aliases => 'rdir',
104 isa => 'ArrayRef[Str]',
106 predicate => '_has_restart_directory',
107 documentation => qq{ restarter directory to watch }
110 has restart_delay => (
111 traits => [qw(Getopt)],
112 cmd_aliases => 'rdel',
115 predicate => '_has_restart_delay',
116 documentation => qq{ set a restart delay }
119 has restart_regex => (
120 traits => [qw(Getopt)],
121 cmd_aliases => 'rxp',
124 predicate => '_has_restart_regex',
125 documentation => qq{ restart regex }
128 has follow_symlinks => (
129 traits => [qw(Getopt)],
130 cmd_aliases => 'sym',
133 predicate => '_has_follow_symlinks',
134 documentation => qq{ follow symbolic links }
149 $self->usage if $self->help;
151 if ( $self->debug ) {
152 $ENV{CATALYST_DEBUG} = 1;
155 # If we load this here, then in the case of a restarter, it does not
156 # need to be reloaded for each restart.
159 # If this isn't done, then the Catalyst::Devel tests for the restarter
161 $| = 1 if $ENV{HARNESS_ACTIVE};
163 if ( $self->restart ) {
164 die "Cannot run in the background and also watch for changed files.\n"
165 if $self->background;
167 require Catalyst::Restarter;
169 my $subclass = Catalyst::Restarter->pick_subclass;
172 $args{follow_symlinks} = $self->follow_symlinks
173 if $self->_has_follow_symlinks;
174 $args{directories} = $self->restart_directory
175 if $self->_has_restart_directory;
176 $args{sleep_interval} = $self->restart_delay
177 if $self->_has_restart_delay;
178 $args{filter} = qr/$self->restart_regex/
179 if $self->_has_restart_regex;
181 my $restarter = $subclass->new(
183 start_sub => sub { $self->_run },
184 argv => \$self->ARGV,
187 $restarter->run_and_watch;
199 my $app = $self->app;
200 Class::MOP::load_class($app);
203 $self->listen, $self->host,
205 'fork' => $self->fork,
206 keepalive => $self->keepalive,
207 background => $self->background,
208 pidfile => $self->pidfile,
209 keepalive => $self->keepalive,
210 follow_symlinks => $self->follow_symlinks,
216 __PACKAGE__->meta->make_immutable;
222 [% appprefix %]_server.pl - Catalyst Testserver
226 [% appprefix %]_server.pl [options]
229 -d --debug force debug mode
230 -f --fork handle each request in a new process
232 -h --help display this help and exits
233 --host host (defaults to all)
234 -p --port port (defaults to 3000)
235 -k --keepalive enable keep-alive connections
236 -r --restart restart when files get modified
238 --rd --restartdelay delay between file checks
239 (ignored if you have Linux::Inotify2 installed)
240 --rr --restartregex regex match files that trigger
241 a restart when modified
242 (defaults to '\.yml$|\.yaml$|\.conf|\.pm$')
243 --rdir --restartdirectory the directory to search for
244 modified files, can be set mulitple times
245 (defaults to '[SCRIPT_DIR]/..')
246 --sym --follow_symlinks follow symlinks in search directories
247 (defaults to false. this is a no-op on Win32)
248 --bg --background run the process in the background
249 --pid --pidfile specify filename for pid file
252 perldoc Catalyst::Manual
253 perldoc Catalyst::Manual::Intro
257 Run a Catalyst Testserver for this application.
261 Catalyst Contributors, see Catalyst.pm
265 This library is free software. You can redistribute it and/or modify
266 it under the same terms as Perl itself.