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';
19 documentation => q{Force debug mode},
25 default => 'localhost',
26 documentation => 'Specify a host for the server to run on',
33 documentation => 'Fork the server',
41 documentation => 'Specify a different listening port',
48 documentation => 'Specify a pidfile',
55 documentation => 'Server keepalive',
63 documentation => 'Run in the background',
70 documentation => 'use Catalyst::Restarter to detect code changes',
73 has restart_directory => (
74 cmd_aliases => 'rdir',
77 predicate => '_has_restart_directory',
78 documentation => 'Restarter directory to watch',
81 has restart_delay => (
82 cmd_aliases => 'rdel',
85 predicate => '_has_restart_delay',
86 documentation => 'Set a restart delay',
89 has restart_regex => (
90 traits => [qw(Getopt)],
94 predicate => '_has_restart_regex',
95 documentation => 'Restart regex',
98 has follow_symlinks => (
99 traits => [qw(Getopt)],
100 cmd_aliases => 'sym',
103 predicate => '_has_follow_symlinks',
104 documentation => 'Follow symbolic links',
111 if ( $self->debug ) {
112 $ENV{CATALYST_DEBUG} = 1;
115 # If we load this here, then in the case of a restarter, it does not
116 # need to be reloaded for each restart.
119 # If this isn't done, then the Catalyst::Devel tests for the restarter
121 $| = 1 if $ENV{HARNESS_ACTIVE};
123 if ( $self->restart ) {
124 die "Cannot run in the background and also watch for changed files.\n"
125 if $self->background;
127 require Catalyst::Restarter;
129 my $subclass = Catalyst::Restarter->pick_subclass;
132 $args{follow_symlinks} = $self->follow_symlinks
133 if $self->_has_follow_symlinks;
134 $args{directories} = $self->restart_directory
135 if $self->_has_restart_directory;
136 $args{sleep_interval} = $self->restart_delay
137 if $self->_has_restart_delay;
138 $args{filter} = qr/$self->restart_regex/
139 if $self->_has_restart_regex;
141 my $restarter = $subclass->new(
143 start_sub => sub { $self->_run },
144 argv => \$self->ARGV,
147 $restarter->run_and_watch;
150 $self->_run_application;
156 sub _application_args {
162 map { $_ => $self->$_ } qw/
174 __PACKAGE__->meta->make_immutable;
180 [% appprefix %]_server.pl - Catalyst Testserver
184 [% appprefix %]_server.pl [options]
187 -d --debug force debug mode
188 -f --fork handle each request in a new process
190 -h --help display this help and exits
191 --host host (defaults to all)
192 -p --port port (defaults to 3000)
193 -k --keepalive enable keep-alive connections
194 -r --restart restart when files get modified
196 --rd --restartdelay delay between file checks
197 (ignored if you have Linux::Inotify2 installed)
198 --rr --restartregex regex match files that trigger
199 a restart when modified
200 (defaults to '\.yml$|\.yaml$|\.conf|\.pm$')
201 --rdir --restartdirectory the directory to search for
202 modified files, can be set mulitple times
203 (defaults to '[SCRIPT_DIR]/..')
204 --sym --follow_symlinks follow symlinks in search directories
205 (defaults to false. this is a no-op on Win32)
206 --bg --background run the process in the background
207 --pid --pidfile specify filename for pid file
210 perldoc Catalyst::Manual
211 perldoc Catalyst::Manual::Intro
215 Run a Catalyst Testserver for this application.
219 Catalyst Contributors, see Catalyst.pm
223 This library is free software. You can redistribute it and/or modify
224 it under the same terms as Perl itself.