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