1 package Catalyst::Script::Server;
4 $ENV{CATALYST_ENGINE} ||= 'HTTP';
5 require Catalyst::Engine::HTTP;
9 use MooseX::Types::Moose qw/ArrayRef Str Bool Int/;
10 use namespace::autoclean;
12 with 'Catalyst::ScriptRole';
14 __PACKAGE__->meta->get_attribute('help')->cmd_aliases('?');
17 traits => [qw(Getopt)],
21 documentation => q{Force debug mode},
25 traits => [qw(Getopt)],
29 default => 'localhost',
30 documentation => 'Specify an IP on this host for the server to bind to',
34 traits => [qw(Getopt)],
39 documentation => 'Fork the server to be able to serve multiple requests at once',
43 traits => [qw(Getopt)],
48 documentation => 'Specify a different listening port (to the default port 3000)',
52 traits => [qw(Getopt)],
56 documentation => 'Specify a pidfile',
60 traits => [qw(Getopt)],
65 documentation => 'Support keepalive',
69 traits => [qw(Getopt)],
74 documentation => 'Run in the background',
78 traits => [qw(Getopt)],
83 documentation => 'use Catalyst::Restarter to detect code changes and restart the application',
86 has restart_directory => (
87 traits => [qw(Getopt)],
88 cmd_aliases => 'rdir',
91 documentation => 'Restarter directory to watch',
92 predicate => '_has_restart_directory',
95 has restart_delay => (
96 traits => [qw(Getopt)],
100 documentation => 'Set a restart delay',
101 predicate => '_has_restart_delay',
104 has restart_regex => (
105 traits => [qw(Getopt)],
109 documentation => 'Restart regex',
110 predicate => '_has_restart_regex',
113 has follow_symlinks => (
114 traits => [qw(Getopt)],
115 cmd_aliases => 'sym',
119 documentation => 'Follow symbolic links',
122 sub _restarter_args {
125 $args{follow_symlinks} = $self->follow_symlinks
126 if $self->follow_symlinks;
127 $args{directories} = $self->restart_directory
128 if $self->_has_restart_directory;
129 $args{sleep_interval} = $self->restart_delay
130 if $self->_has_restart_delay;
131 if ($self->_has_restart_regex) {
132 my $regex = $self->restart_regex;
133 $args{filter} = qr/$regex/;
135 $args{start_sub} = sub { $self->_run_application };
136 $args{argv} = $self->ARGV;
143 local $ENV{CATALYST_DEBUG} = 1
146 if ( $self->restart ) {
147 die "Cannot run in the background and also watch for changed files.\n"
148 if $self->background;
150 # If we load this here, then in the case of a restarter, it does not
151 # need to be reloaded for each restart.
154 # If this isn't done, then the Catalyst::Devel tests for the restarter
156 $| = 1 if $ENV{HARNESS_ACTIVE};
158 require Catalyst::Restarter;
160 my $subclass = Catalyst::Restarter->pick_subclass;
163 my $restarter = $subclass->new(
164 $self->_restarter_args()
167 $restarter->run_and_watch;
170 $self->_run_application;
176 sub _application_args {
182 map { $_ => $self->$_ } qw/
194 __PACKAGE__->meta->make_immutable;
200 Catalyst::Script::Server - Catalyst test server
204 myapp_server.pl [options]
207 -d --debug force debug mode
208 -f --fork handle each request in a new process
210 --help display this help and exits
211 -h --host host (defaults to all)
212 -p --port port (defaults to 3000)
213 -k --keepalive enable keep-alive connections
214 -r --restart restart when files get modified
216 --rd --restartdelay delay between file checks
217 (ignored if you have Linux::Inotify2 installed)
218 --rr --restartregex regex match files that trigger
219 a restart when modified
220 (defaults to '\.yml$|\.yaml$|\.conf|\.pm$')
221 --rdir --restartdirectory the directory to search for
222 modified files, can be set mulitple times
223 (defaults to '[SCRIPT_DIR]/..')
224 --sym --follow_symlinks follow symlinks in search directories
225 (defaults to false. this is a no-op on Win32)
226 --bg --background run the process in the background
227 --pid --pidfile specify filename for pid file
230 perldoc Catalyst::Manual
231 perldoc Catalyst::Manual::Intro
235 Run a Catalyst test server for this application.
239 Catalyst Contributors, see Catalyst.pm
243 This library is free software. You can redistribute it and/or modify
244 it under the same terms as Perl itself.