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';
15 traits => [qw(Getopt)],
19 documentation => q{Force debug mode},
23 traits => [qw(Getopt)],
27 default => 'localhost',
28 documentation => 'Specify an IP on this host for the server to bind to',
32 traits => [qw(Getopt)],
37 documentation => 'Fork the server to be able to serve multiple requests at once',
41 traits => [qw(Getopt)],
46 documentation => 'Specify a different listening port (to the default port 3000)',
50 traits => [qw(Getopt)],
54 documentation => 'Specify a pidfile',
58 traits => [qw(Getopt)],
63 documentation => 'Support keepalive',
67 traits => [qw(Getopt)],
72 documentation => 'Run in the background',
76 traits => [qw(Getopt)],
81 documentation => 'use Catalyst::Restarter to detect code changes and restart the application',
84 has restart_directory => (
85 traits => [qw(Getopt)],
86 cmd_aliases => 'rdir',
89 documentation => 'Restarter directory to watch',
90 predicate => '_has_restart_directory',
93 has restart_delay => (
94 traits => [qw(Getopt)],
98 documentation => 'Set a restart delay',
99 predicate => '_has_restart_delay',
102 has restart_regex => (
103 traits => [qw(Getopt)],
107 documentation => 'Restart regex',
108 predicate => '_has_restart_regex',
111 has follow_symlinks => (
112 traits => [qw(Getopt)],
113 cmd_aliases => 'sym',
117 documentation => 'Follow symbolic links',
123 local $ENV{CATALYST_DEBUG} = 1
126 if ( $self->restart ) {
127 die "Cannot run in the background and also watch for changed files.\n"
128 if $self->background;
130 # If we load this here, then in the case of a restarter, it does not
131 # need to be reloaded for each restart.
134 # If this isn't done, then the Catalyst::Devel tests for the restarter
136 $| = 1 if $ENV{HARNESS_ACTIVE};
138 require Catalyst::Restarter;
140 my $subclass = Catalyst::Restarter->pick_subclass;
143 $args{follow_symlinks} = $self->follow_symlinks
144 if $self->follow_symlinks;
145 $args{directories} = $self->restart_directory
146 if $self->_has_restart_directory;
147 $args{sleep_interval} = $self->restart_delay
148 if $self->_has_restart_delay;
149 $args{filter} = qr/$self->restart_regex/
150 if $self->_has_restart_regex;
152 my $restarter = $subclass->new(
154 start_sub => sub { $self->_run_application },
158 $restarter->run_and_watch;
161 $self->_run_application;
167 sub _application_args {
173 map { $_ => $self->$_ } qw/
185 __PACKAGE__->meta->make_immutable;
191 Catalyst::Script::Server - Catalyst test server
195 myapp_server.pl [options]
198 -d --debug force debug mode
199 -f --fork handle each request in a new process
201 -h --help display this help and exits
202 --host host (defaults to all)
203 -p --port port (defaults to 3000)
204 -k --keepalive enable keep-alive connections
205 -r --restart restart when files get modified
207 --rd --restartdelay delay between file checks
208 (ignored if you have Linux::Inotify2 installed)
209 --rr --restartregex regex match files that trigger
210 a restart when modified
211 (defaults to '\.yml$|\.yaml$|\.conf|\.pm$')
212 --rdir --restartdirectory the directory to search for
213 modified files, can be set mulitple times
214 (defaults to '[SCRIPT_DIR]/..')
215 --sym --follow_symlinks follow symlinks in search directories
216 (defaults to false. this is a no-op on Win32)
217 --bg --background run the process in the background
218 --pid --pidfile specify filename for pid file
221 perldoc Catalyst::Manual
222 perldoc Catalyst::Manual::Intro
226 Run a Catalyst test server for this application.
230 Catalyst Contributors, see Catalyst.pm
234 This library is free software. You can redistribute it and/or modify
235 it under the same terms as Perl itself.