1 package Catalyst::Script::Server;
4 $ENV{CATALYST_ENGINE} ||= 'HTTP';
5 require Catalyst::Engine::HTTP;
9 use MooseX::Types::Common::Numeric qw/PositiveInt/;
10 use MooseX::Types::Moose qw/ArrayRef Str Bool Int RegexpRef/;
12 use namespace::autoclean;
14 with 'Catalyst::ScriptRole';
16 __PACKAGE__->meta->get_attribute('help')->cmd_aliases('?');
19 traits => [qw(Getopt)],
23 documentation => q{Force debug mode},
27 traits => [qw(Getopt)],
31 # N.B. undef (the default) means we bind on all interfaces on the host.
32 documentation => 'Specify a hostname or IP on this host for the server to bind to',
36 traits => [qw(Getopt)],
41 documentation => 'Fork the server to be able to serve multiple requests at once',
45 traits => [qw(Getopt)],
51 $ENV{ Catalyst::Utils::class2env($self->application_name . '_PORT')}||3000
53 documentation => 'Specify a different listening port (to the default port 3000)',
57 traits => [qw(Getopt)],
61 documentation => 'Specify a pidfile',
65 traits => [qw(Getopt)],
70 documentation => 'Support keepalive',
74 traits => [qw(Getopt)],
79 documentation => 'Run in the background',
83 traits => [qw(Getopt)],
88 documentation => 'use Catalyst::Restarter to detect code changes and restart the application',
91 has restart_directory => (
92 traits => [qw(Getopt)],
93 cmd_aliases => [ 'rdir', 'restartdirectory' ],
96 documentation => 'Restarter directory to watch',
97 predicate => '_has_restart_directory',
100 has restart_delay => (
101 traits => [qw(Getopt)],
105 documentation => 'Set a restart delay',
106 predicate => '_has_restart_delay',
110 use Moose::Util::TypeConstraints;
112 my $tc = subtype as RegexpRef;
113 coerce $tc, from Str, via { qr/$_/ };
115 MooseX::Getopt::OptionTypeMap->add_option_type_to_map($tc => '=s');
117 has restart_regex => (
118 traits => [qw(Getopt)],
123 documentation => 'Restart regex',
124 predicate => '_has_restart_regex',
128 has follow_symlinks => (
129 traits => [qw(Getopt)],
130 cmd_aliases => 'sym',
134 documentation => 'Follow symbolic links',
135 predicate => '_has_follow_symlinks',
138 sub _restarter_args {
143 start_sub => sub { $self->_run_application },
144 ($self->_has_follow_symlinks ? (follow_symlinks => $self->follow_symlinks) : ()),
145 ($self->_has_restart_delay ? (sleep_interval => $self->restart_delay) : ()),
146 ($self->_has_restart_directory ? (directories => $self->restart_directory) : ()),
147 ($self->_has_restart_regex ? (filter => $self->restart_regex) : ()),
154 local $ENV{CATALYST_DEBUG} = 1
157 if ( $self->restart ) {
158 die "Cannot run in the background and also watch for changed files.\n"
159 if $self->background;
161 # If we load this here, then in the case of a restarter, it does not
162 # need to be reloaded for each restart.
165 # If this isn't done, then the Catalyst::Devel tests for the restarter
167 $| = 1 if $ENV{HARNESS_ACTIVE};
169 require Catalyst::Restarter;
171 my $subclass = Catalyst::Restarter->pick_subclass;
173 my $restarter = $subclass->new(
174 $self->_restarter_args()
177 $restarter->run_and_watch;
180 $self->_run_application;
186 sub _application_args {
192 map { $_ => $self->$_ } qw/
204 __PACKAGE__->meta->make_immutable;
210 Catalyst::Script::Server - Catalyst test server
214 myapp_server.pl [options]
217 -d --debug force debug mode
218 -f --fork handle each request in a new process
220 --help display this help and exits
221 -h --host host (defaults to all)
222 -p --port port (defaults to 3000)
223 -k --keepalive enable keep-alive connections
224 -r --restart restart when files get modified
226 --rd --restart_delay delay between file checks
227 (ignored if you have Linux::Inotify2 installed)
228 --rr --restart_regex regex match files that trigger
229 a restart when modified
230 (defaults to '\.yml$|\.yaml$|\.conf|\.pm$')
231 --rdir --restart_directory the directory to search for
232 modified files, can be set mulitple times
233 (defaults to '[SCRIPT_DIR]/..')
234 --sym --follow_symlinks follow symlinks in search directories
235 (defaults to false. this is a no-op on Win32)
236 --bg --background run the process in the background
237 --pid --pidfile specify filename for pid file
240 perldoc Catalyst::Manual
241 perldoc Catalyst::Manual::Intro
245 Run a Catalyst test server for this application.
249 Catalyst Contributors, see Catalyst.pm
253 This library is free software. You can redistribute it and/or modify
254 it under the same terms as Perl itself.