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';
18 #extends qw(MooseX::App::Cmd);
21 traits => [qw(Getopt)],
25 documentation => qq{ force debug mode }
29 traits => [qw(Getopt)],
33 documentation => qq{ display this help and exits },
39 default => "localhost",
40 documentation => qq{ specify a host for the server to run on }
44 traits => [qw(Getopt)],
48 documentation => qq{ fork the server }
52 traits => [qw(Getopt)],
57 documentation => qq{ specify a different listening port }
61 traits => [qw(Getopt)],
65 documentation => qq{ specify a pidfile }
69 traits => [qw(Getopt)],
73 documentation => qq{ server keepalive },
78 traits => [qw(Getopt)],
82 documentation => qq{ run in the background }
89 traits => [qw(NoGetopt)],
95 traits => [qw(Getopt)],
99 documentation => qq{ use Catalyst::Restarter to detect code changes }
102 has restart_directory => (
103 traits => [qw(Getopt)],
104 cmd_aliases => 'rdir',
105 isa => 'ArrayRef[Str]',
107 predicate => '_has_restart_directory',
108 documentation => qq{ restarter directory to watch }
111 has restart_delay => (
112 traits => [qw(Getopt)],
113 cmd_aliases => 'rdel',
116 predicate => '_has_restart_delay',
117 documentation => qq{ set a restart delay }
120 has restart_regex => (
121 traits => [qw(Getopt)],
122 cmd_aliases => 'rxp',
125 predicate => '_has_restart_regex',
126 documentation => qq{ restart regex }
129 has follow_symlinks => (
130 traits => [qw(Getopt)],
131 cmd_aliases => 'sym',
134 predicate => '_has_follow_symlinks',
135 documentation => qq{ follow symbolic links }
150 $self->usage if $self->help;
152 if ( $self->debug ) {
153 $ENV{CATALYST_DEBUG} = 1;
156 # If we load this here, then in the case of a restarter, it does not
157 # need to be reloaded for each restart.
160 # If this isn't done, then the Catalyst::Devel tests for the restarter
162 $| = 1 if $ENV{HARNESS_ACTIVE};
164 if ( $self->restart ) {
165 die "Cannot run in the background and also watch for changed files.\n"
166 if $self->background;
168 require Catalyst::Restarter;
170 my $subclass = Catalyst::Restarter->pick_subclass;
173 $args{follow_symlinks} = $self->follow_symlinks
174 if $self->_has_follow_symlinks;
175 $args{directories} = $self->restart_directory
176 if $self->_has_restart_directory;
177 $args{sleep_interval} = $self->restart_delay
178 if $self->_has_restart_delay;
179 $args{filter} = qr/$self->restart_regex/
180 if $self->_has_restart_regex;
182 my $restarter = $subclass->new(
184 start_sub => sub { $self->_run },
185 argv => \$self->ARGV,
188 $restarter->run_and_watch;
200 my $app = $self->app;
201 Class::MOP::load_class($app);
204 $self->listen, $self->host,
206 'fork' => $self->fork,
207 keepalive => $self->keepalive,
208 background => $self->background,
209 pidfile => $self->pidfile,
210 keepalive => $self->keepalive,
211 follow_symlinks => $self->follow_symlinks,
217 __PACKAGE__->meta->make_immutable;
223 [% appprefix %]_server.pl - Catalyst Testserver
227 [% appprefix %]_server.pl [options]
230 -d --debug force debug mode
231 -f --fork handle each request in a new process
233 -h --help display this help and exits
234 --host host (defaults to all)
235 -p --port port (defaults to 3000)
236 -k --keepalive enable keep-alive connections
237 -r --restart restart when files get modified
239 --rd --restartdelay delay between file checks
240 (ignored if you have Linux::Inotify2 installed)
241 --rr --restartregex regex match files that trigger
242 a restart when modified
243 (defaults to '\.yml$|\.yaml$|\.conf|\.pm$')
244 --rdir --restartdirectory the directory to search for
245 modified files, can be set mulitple times
246 (defaults to '[SCRIPT_DIR]/..')
247 --sym --follow_symlinks follow symlinks in search directories
248 (defaults to false. this is a no-op on Win32)
249 --bg --background run the process in the background
250 --pid --pidfile specify filename for pid file
253 perldoc Catalyst::Manual
254 perldoc Catalyst::Manual::Intro
258 Run a Catalyst Testserver for this application.
262 Catalyst Contributors, see Catalyst.pm
266 This library is free software. You can redistribute it and/or modify
267 it under the same terms as Perl itself.