1 package Catalyst::Script::Server;
3 use MooseX::Types::Common::Numeric qw/PositiveInt/;
4 use MooseX::Types::Moose qw/ArrayRef Str Bool Int RegexpRef/;
6 use namespace::autoclean;
8 sub _plack_engine_name { 'Standalone' }
10 with 'Catalyst::ScriptRole';
12 __PACKAGE__->meta->get_attribute('help')->cmd_aliases('?');
15 traits => [qw(Getopt)],
19 documentation => q{Force debug mode},
23 traits => [qw(Getopt)],
27 # N.B. undef (the default) means we bind on all interfaces on the host.
28 documentation => 'Specify a hostname or 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 Catalyst::Utils::env_value(shift->application_name, 'port') || 3000
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 Catalyst::Utils::env_value(shift->application_name, 'reload') || 0;
85 documentation => 'use Catalyst::Restarter to detect code changes and restart the application',
88 has restart_directory => (
89 traits => [qw(Getopt)],
90 cmd_aliases => [ 'rdir', 'restartdirectory' ],
93 documentation => 'Restarter directory to watch',
94 predicate => '_has_restart_directory',
97 has restart_delay => (
98 traits => [qw(Getopt)],
102 documentation => 'Set a restart delay',
103 predicate => '_has_restart_delay',
107 use Moose::Util::TypeConstraints;
109 my $tc = subtype as RegexpRef;
110 coerce $tc, from Str, via { qr/$_/ };
112 MooseX::Getopt::OptionTypeMap->add_option_type_to_map($tc => '=s');
114 has restart_regex => (
115 traits => [qw(Getopt)],
120 documentation => 'Restart regex',
121 predicate => '_has_restart_regex',
125 has follow_symlinks => (
126 traits => [qw(Getopt)],
127 cmd_aliases => 'sym',
131 documentation => 'Follow symbolic links',
132 predicate => '_has_follow_symlinks',
135 sub _restarter_args {
140 start_sub => sub { $self->_run_application },
141 ($self->_has_follow_symlinks ? (follow_symlinks => $self->follow_symlinks) : ()),
142 ($self->_has_restart_delay ? (sleep_interval => $self->restart_delay) : ()),
143 ($self->_has_restart_directory ? (directories => $self->restart_directory) : ()),
144 ($self->_has_restart_regex ? (filter => $self->restart_regex) : ()),
151 local $ENV{CATALYST_DEBUG} = 1
154 if ( $self->restart ) {
155 die "Cannot run in the background and also watch for changed files.\n"
156 if $self->background;
158 # If we load this here, then in the case of a restarter, it does not
159 # need to be reloaded for each restart.
162 # If this isn't done, then the Catalyst::Devel tests for the restarter
164 $| = 1 if $ENV{HARNESS_ACTIVE};
166 require Catalyst::Restarter;
168 my $subclass = Catalyst::Restarter->pick_subclass;
170 my $restarter = $subclass->new(
171 $self->_restarter_args()
174 $restarter->run_and_watch;
177 $self->_run_application;
183 sub _plack_loader_args {
188 keepalive => $self->keepalive ? 100 : 1,
192 sub _application_args {
199 map { $_ => $self->$_ } qw/
211 __PACKAGE__->meta->make_immutable;
217 Catalyst::Script::Server - Catalyst test server
221 myapp_server.pl [options]
224 -d --debug force debug mode
225 -f --fork handle each request in a new process
227 --help display this help and exits
228 -h --host host (defaults to all)
229 -p --port port (defaults to 3000)
230 -k --keepalive enable keep-alive connections
231 -r --restart restart when files get modified
233 --rd --restart_delay delay between file checks
234 (ignored if you have Linux::Inotify2 installed)
235 --rr --restart_regex regex match files that trigger
236 a restart when modified
237 (defaults to '\.yml$|\.yaml$|\.conf|\.pm$')
238 --rdir --restart_directory the directory to search for
239 modified files, can be set mulitple times
240 (defaults to '[SCRIPT_DIR]/..')
241 --sym --follow_symlinks follow symlinks in search directories
242 (defaults to false. this is a no-op on Win32)
243 --bg --background run the process in the background
244 --pid --pidfile specify filename for pid file
247 perldoc Catalyst::Manual
248 perldoc Catalyst::Manual::Intro
252 Run a Catalyst test server for this application.
256 Catalyst Contributors, see Catalyst.pm
260 This library is free software. You can redistribute it and/or modify
261 it under the same terms as Perl itself.