fork now has a short option
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Script / Server.pm
CommitLineData
0ba6e8aa 1package Catalyst::Script::Server;
2
53b08cf9 3BEGIN {
4 $ENV{CATALYST_ENGINE} ||= 'HTTP';
5 $ENV{CATALYST_SCRIPT_GEN} = 31;
6 require Catalyst::Engine::HTTP;
7}
5b923b0b 8
a3ca4468 9use FindBin qw/$Bin/;
10use lib "$Bin/../lib";
11use Pod::Usage;
12use Moose;
13use Catalyst::Engine::HTTP;
14use namespace::clean -except => [ qw(meta) ];
15
16with 'MooseX::Getopt';
17
e46bf32c 18has help => (
19 traits => [qw(Getopt)],
90b481b1 20 cmd_aliases => 'h',
e46bf32c 21 isa => 'Bool',
22 is => 'ro',
23 required => 0,
90b481b1 24 default => 0,
e46bf32c 25);
26
27has host => ( isa => 'Str', is => 'ro', required => 0, default => "localhost" );
90b481b1 28
29has fork => (
30 traits => [qw(Getopt)],
31 cmd_aliases => 'f',
32 isa => 'Bool',
33 is => 'ro',
34 required => 0
35);
36
e46bf32c 37has listen => ( isa => 'Int', is => 'ro', required => 0, default => "3000" );
615fee7c 38has pidfile => ( isa => 'Str', is => 'ro', required => 0 );
e46bf32c 39has keepalive => ( isa => 'Bool', is => 'ro', required => 0, default => 0 );
615fee7c 40has background => ( isa => 'Bool', is => 'ro', required => 0 );
41has app => ( isa => 'Str', is => 'ro', required => 1 );
42has restart => ( isa => 'Bool', is => 'ro', required => 0 );
43has restart_delay => ( isa => 'Int', is => 'ro', required => 0 );
44has restart_regex => ( isa => 'Str', is => 'ro', required => 0 );
45has follow_symlinks => ( isa => 'Bool', is => 'ro', required => 0 );
a3ca4468 46
47my @argv = @ARGV;
48
49sub run {
50 my $self = shift;
51
52 pod2usage() if $self->help;
53 my $app = $self->app;
54 Class::MOP::load_class($app);
55 $app->run(
56 $self->listen, $self->host,
57 {
58 'fork' => $self->fork,
59 keepalive => $self->keepalive,
60 background => $self->background,
61 pidfile => $self->pidfile,
615fee7c 62 keepalive => $self->keepalive,
63 restart => $self->restart,
64 restart_delay => $self->restart_delay,
65 restart_regex => qr/$self->restart_regex/,
c1c59374 66# FIXME restart_directory => $self->restart_directory,
615fee7c 67 follow_symlinks => $self->follow_symlinks,
a3ca4468 68 }
69 );
70
71}
5b923b0b 72
5b923b0b 73
0ba6e8aa 741;
e46bf32c 75
76=head1 NAME
77
78[% appprefix %]_server.pl - Catalyst Testserver
79
80=head1 SYNOPSIS
81
82[% appprefix %]_server.pl [options]
83
84 Options:
85 -d -debug force debug mode
86 -f -fork handle each request in a new process
87 (defaults to false)
88 -? -help display this help and exits
89 -host host (defaults to all)
90 -p -port port (defaults to 3000)
91 -k -keepalive enable keep-alive connections
92 -r -restart restart when files get modified
93 (defaults to false)
94 -rd -restartdelay delay between file checks
95 (ignored if you have Linux::Inotify2 installed)
96 -rr -restartregex regex match files that trigger
97 a restart when modified
98 (defaults to '\.yml$|\.yaml$|\.conf|\.pm$')
99 -restartdirectory the directory to search for
100 modified files, can be set mulitple times
101 (defaults to '[SCRIPT_DIR]/..')
102 -follow_symlinks follow symlinks in search directories
103 (defaults to false. this is a no-op on Win32)
104 -background run the process in the background
105 -pidfile specify filename for pid file
106
107 See also:
108 perldoc Catalyst::Manual
109 perldoc Catalyst::Manual::Intro
110
111=head1 DESCRIPTION
112
113Run a Catalyst Testserver for this application.
114
115=head1 AUTHORS
116
117Catalyst Contributors, see Catalyst.pm
118
119=head1 COPYRIGHT
120
121This library is free software. You can redistribute it and/or modify
122it under the same terms as Perl itself.
123
124=cut