fasterized
[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;
4ebd5ecf 13#use Catalyst::Engine::HTTP;
59804176 14use namespace::autoclean;
a3ca4468 15
16with 'MooseX::Getopt';
17
f59a9d1b 18has debug => (
19 traits => [qw(Getopt)],
20 cmd_aliases => 'd',
21 isa => 'Bool',
22 is => 'ro',
2e81e132 23 documentation => qq{
24 -d --debug force debug mode
25 }
f59a9d1b 26
27);
28
e46bf32c 29has help => (
30 traits => [qw(Getopt)],
90b481b1 31 cmd_aliases => 'h',
e46bf32c 32 isa => 'Bool',
33 is => 'ro',
2e81e132 34 documentation => qq{
35 -h --help display this help and exits
36 },
e46bf32c 37);
38
41b55019 39has host => (
40 isa => 'Str',
41 is => 'ro',
50d48a87 42 ,
41b55019 43 default => "localhost"
44);
90b481b1 45
46has fork => (
47 traits => [qw(Getopt)],
48 cmd_aliases => 'f',
49 isa => 'Bool',
50 is => 'ro',
50d48a87 51
90b481b1 52);
53
204c6935 54has listen => (
55 traits => [qw(Getopt)],
56 cmd_aliases => 'l',
57 isa => 'Int',
58 is => 'ro',
50d48a87 59 ,
204c6935 60 default => "3000"
61);
62
41b55019 63has pidfile => (
64 traits => [qw(Getopt)],
b6aaf142 65 cmd_aliases => 'pid',
41b55019 66 isa => 'Str',
67 is => 'ro',
50d48a87 68
41b55019 69);
70
bd31e11f 71has keepalive => (
72 traits => [qw(Getopt)],
73 cmd_aliases => 'k',
74 isa => 'Bool',
75 is => 'ro',
50d48a87 76 ,
8bae939b 77
bd31e11f 78);
79
3954573c 80has background => (
81 traits => [qw(Getopt)],
82 cmd_aliases => 'bg',
83 isa => 'Bool',
84 is => 'ro',
3954573c 85);
86
4ebd5ecf 87
80a909c2 88has _app => (
89 reader => 'app',
90 init_arg => 'app',
91 traits => [qw(NoGetopt)],
4b3881d4 92 isa => 'Str',
93 is => 'ro',
4b3881d4 94);
95
8f01ed5f 96has restart => (
97 traits => [qw(Getopt)],
98 cmd_aliases => 'r',
99 isa => 'Bool',
100 is => 'ro',
50d48a87 101
8f01ed5f 102);
103
70871584 104has restart_delay => (
105 traits => [qw(Getopt)],
106 cmd_aliases => 'rdel',
107 isa => 'Int',
108 is => 'ro',
50d48a87 109
70871584 110);
111
ee7aabd6 112has restart_regex => (
113 traits => [qw(Getopt)],
114 cmd_aliases => 'rxp',
115 isa => 'Str',
116 is => 'ro',
50d48a87 117
ee7aabd6 118);
119
bbd42ac8 120has follow_symlinks => (
121 traits => [qw(Getopt)],
122 cmd_aliases => 'sym',
123 isa => 'Bool',
124 is => 'ro',
50d48a87 125
bbd42ac8 126);
a3ca4468 127
8bae939b 128sub usage {
129 my ($self) = shift;
130
131 return pod2usage();
132
133}
134
a3ca4468 135my @argv = @ARGV;
136
137sub run {
138 my $self = shift;
139
8bae939b 140 $self->usage if $self->help;
a3ca4468 141 my $app = $self->app;
142 Class::MOP::load_class($app);
143 $app->run(
144 $self->listen, $self->host,
145 {
4b3881d4 146 'fork' => $self->fork,
147 keepalive => $self->keepalive,
148 background => $self->background,
149 pidfile => $self->pidfile,
615fee7c 150 keepalive => $self->keepalive,
151 restart => $self->restart,
152 restart_delay => $self->restart_delay,
153 restart_regex => qr/$self->restart_regex/,
c1c59374 154# FIXME restart_directory => $self->restart_directory,
615fee7c 155 follow_symlinks => $self->follow_symlinks,
a3ca4468 156 }
157 );
158
159}
5b923b0b 160
2e81e132 161no Moose;
162__PACKAGE__->meta->make_immutable;
5b923b0b 163
0ba6e8aa 1641;
e46bf32c 165
166=head1 NAME
167
168[% appprefix %]_server.pl - Catalyst Testserver
169
170=head1 SYNOPSIS
171
172[% appprefix %]_server.pl [options]
173
174 Options:
4b3881d4 175 -d --debug force debug mode
176 -f --fork handle each request in a new process
e46bf32c 177 (defaults to false)
4b3881d4 178 -h --help display this help and exits
179 --host host (defaults to all)
180 -p --port port (defaults to 3000)
181 -k --keepalive enable keep-alive connections
182 -r --restart restart when files get modified
183 (defaults to false)
184 --rd --restartdelay delay between file checks
e46bf32c 185 (ignored if you have Linux::Inotify2 installed)
4b3881d4 186 --rr --restartregex regex match files that trigger
e46bf32c 187 a restart when modified
188 (defaults to '\.yml$|\.yaml$|\.conf|\.pm$')
4b3881d4 189 --rdir --restartdirectory the directory to search for
e46bf32c 190 modified files, can be set mulitple times
191 (defaults to '[SCRIPT_DIR]/..')
4b3881d4 192 --sym --follow_symlinks follow symlinks in search directories
e46bf32c 193 (defaults to false. this is a no-op on Win32)
4b3881d4 194 --bg --background run the process in the background
195 --pid --pidfile specify filename for pid file
e46bf32c 196
197 See also:
198 perldoc Catalyst::Manual
199 perldoc Catalyst::Manual::Intro
200
201=head1 DESCRIPTION
202
203Run a Catalyst Testserver for this application.
204
205=head1 AUTHORS
206
207Catalyst Contributors, see Catalyst.pm
208
209=head1 COPYRIGHT
210
211This library is free software. You can redistribute it and/or modify
212it under the same terms as Perl itself.
213
214=cut