1 package Catalyst::Script::Server;
4 $ENV{CATALYST_ENGINE} ||= 'HTTP';
5 require Catalyst::Engine::HTTP;
9 use Catalyst::Restarter;
10 use MooseX::Types::Moose qw/ArrayRef Str Bool Int/;
11 use namespace::autoclean;
13 with 'Catalyst::ScriptRole';
16 traits => [qw(Getopt)],
20 documentation => q{Force debug mode},
24 traits => [qw(Getopt)],
27 default => 'localhost',
28 documentation => 'Specify a host for the server to run on',
32 traits => [qw(Getopt)],
36 documentation => 'Fork the server',
40 traits => [qw(Getopt)],
45 documentation => 'Specify a different listening port',
49 traits => [qw(Getopt)],
53 documentation => 'Specify a pidfile',
57 traits => [qw(Getopt)],
61 documentation => 'Server keepalive',
66 traits => [qw(Getopt)],
70 documentation => 'Run in the background',
74 traits => [qw(Getopt)],
78 documentation => 'use Catalyst::Restarter to detect code changes',
81 has restart_directory => (
82 traits => [qw(Getopt)],
83 cmd_aliases => 'rdir',
86 predicate => '_has_restart_directory',
87 documentation => 'Restarter directory to watch',
90 has restart_delay => (
91 traits => [qw(Getopt)],
92 cmd_aliases => 'rdel',
95 predicate => '_has_restart_delay',
96 documentation => 'Set a restart delay',
99 has restart_regex => (
100 traits => [qw(Getopt)],
101 cmd_aliases => 'rxp',
104 predicate => '_has_restart_regex',
105 documentation => 'Restart regex',
108 has follow_symlinks => (
109 traits => [qw(Getopt)],
110 cmd_aliases => 'sym',
113 predicate => '_has_follow_symlinks',
114 documentation => 'Follow symbolic links',
121 if ( $self->debug ) {
122 $ENV{CATALYST_DEBUG} = 1;
125 # If we load this here, then in the case of a restarter, it does not
126 # need to be reloaded for each restart.
129 # If this isn't done, then the Catalyst::Devel tests for the restarter
131 $| = 1 if $ENV{HARNESS_ACTIVE};
133 if ( $self->restart ) {
134 die "Cannot run in the background and also watch for changed files.\n"
135 if $self->background;
137 require Catalyst::Restarter;
139 my $subclass = Catalyst::Restarter->pick_subclass;
142 $args{follow_symlinks} = $self->follow_symlinks
143 if $self->_has_follow_symlinks;
144 $args{directories} = $self->restart_directory
145 if $self->_has_restart_directory;
146 $args{sleep_interval} = $self->restart_delay
147 if $self->_has_restart_delay;
148 $args{filter} = qr/$self->restart_regex/
149 if $self->_has_restart_regex;
151 my $restarter = $subclass->new(
153 start_sub => sub { $self->_run },
154 argv => \$self->ARGV,
157 $restarter->run_and_watch;
160 $self->_run_application;
166 sub _application_args {
172 map { $_ => $self->$_ } qw/
184 __PACKAGE__->meta->make_immutable;
190 [% appprefix %]_server.pl - Catalyst Testserver
194 [% appprefix %]_server.pl [options]
197 -d --debug force debug mode
198 -f --fork handle each request in a new process
200 -h --help display this help and exits
201 --host host (defaults to all)
202 -p --port port (defaults to 3000)
203 -k --keepalive enable keep-alive connections
204 -r --restart restart when files get modified
206 --rd --restartdelay delay between file checks
207 (ignored if you have Linux::Inotify2 installed)
208 --rr --restartregex regex match files that trigger
209 a restart when modified
210 (defaults to '\.yml$|\.yaml$|\.conf|\.pm$')
211 --rdir --restartdirectory the directory to search for
212 modified files, can be set mulitple times
213 (defaults to '[SCRIPT_DIR]/..')
214 --sym --follow_symlinks follow symlinks in search directories
215 (defaults to false. this is a no-op on Win32)
216 --bg --background run the process in the background
217 --pid --pidfile specify filename for pid file
220 perldoc Catalyst::Manual
221 perldoc Catalyst::Manual::Intro
225 Run a Catalyst Testserver for this application.
229 Catalyst Contributors, see Catalyst.pm
233 This library is free software. You can redistribute it and/or modify
234 it under the same terms as Perl itself.