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