Commit | Line | Data |
788804c2 |
1 | #!/usr/bin/env perl |
2 | |
3 | BEGIN { |
4 | $ENV{CATALYST_ENGINE} ||= 'HTTP'; |
5 | $ENV{CATALYST_SCRIPT_GEN} = 39; |
6 | require Catalyst::Engine::HTTP; |
7 | } |
8 | |
9 | use strict; |
10 | use warnings; |
11 | use Getopt::Long; |
12 | use Pod::Usage; |
13 | use FindBin; |
14 | use lib "$FindBin::Bin/../lib"; |
15 | |
16 | my $debug = 0; |
17 | my $fork = 0; |
18 | my $help = 0; |
19 | my $host = undef; |
20 | my $port = $ENV{TESTAPP_PORT} || $ENV{CATALYST_PORT} || 3000; |
21 | my $keepalive = 0; |
22 | my $restart = $ENV{TESTAPP_RELOAD} || $ENV{CATALYST_RELOAD} || 0; |
23 | my $background = 0; |
24 | my $pidfile = undef; |
25 | |
26 | my $check_interval; |
27 | my $file_regex; |
28 | my $watch_directory; |
29 | my $follow_symlinks; |
30 | |
31 | my @argv = @ARGV; |
32 | |
33 | GetOptions( |
34 | 'debug|d' => \$debug, |
35 | 'fork|f' => \$fork, |
36 | 'help|?' => \$help, |
37 | 'host=s' => \$host, |
38 | 'port|p=s' => \$port, |
39 | 'keepalive|k' => \$keepalive, |
40 | 'restart|r' => \$restart, |
41 | 'restartdelay|rd=s' => \$check_interval, |
42 | 'restartregex|rr=s' => \$file_regex, |
43 | 'restartdirectory=s@' => \$watch_directory, |
44 | 'followsymlinks' => \$follow_symlinks, |
45 | 'background' => \$background, |
46 | 'pidfile=s' => \$pidfile, |
47 | ); |
48 | |
49 | pod2usage(1) if $help; |
50 | |
51 | if ( $debug ) { |
52 | $ENV{CATALYST_DEBUG} = 1; |
53 | } |
54 | |
55 | # If we load this here, then in the case of a restarter, it does not |
56 | # need to be reloaded for each restart. |
57 | require Catalyst; |
58 | |
59 | # If this isn't done, then the Catalyst::Devel tests for the restarter |
60 | # fail. |
61 | $| = 1 if $ENV{HARNESS_ACTIVE}; |
62 | |
63 | my $runner = sub { |
64 | # This is require instead of use so that the above environment |
65 | # variables can be set at runtime. |
66 | require TestApp; |
67 | |
68 | TestApp->run( |
69 | $port, $host, |
70 | { |
71 | argv => \@argv, |
72 | 'fork' => $fork, |
73 | keepalive => $keepalive, |
74 | background => $background, |
75 | pidfile => $pidfile, |
76 | } |
77 | ); |
78 | }; |
79 | |
80 | if ( $restart ) { |
81 | die "Cannot run in the background and also watch for changed files.\n" |
82 | if $background; |
83 | |
84 | require Catalyst::Restarter; |
85 | |
86 | my $subclass = Catalyst::Restarter->pick_subclass; |
87 | |
88 | my %args; |
89 | $args{follow_symlinks} = 1 |
90 | if $follow_symlinks; |
91 | $args{directories} = $watch_directory |
92 | if defined $watch_directory; |
93 | $args{sleep_interval} = $check_interval |
94 | if defined $check_interval; |
95 | $args{filter} = qr/$file_regex/ |
96 | if defined $file_regex; |
97 | |
98 | my $restarter = $subclass->new( |
99 | %args, |
100 | start_sub => $runner, |
101 | argv => \@argv, |
102 | ); |
103 | |
104 | $restarter->run_and_watch; |
105 | } |
106 | else { |
107 | $runner->(); |
108 | } |
109 | |
110 | 1; |
111 | |
112 | =head1 NAME |
113 | |
114 | testapp_server.pl - Catalyst Testserver |
115 | |
116 | =head1 SYNOPSIS |
117 | |
118 | testapp_server.pl [options] |
119 | |
120 | Options: |
121 | -d -debug force debug mode |
122 | -f -fork handle each request in a new process |
123 | (defaults to false) |
124 | -? -help display this help and exits |
125 | -host host (defaults to all) |
126 | -p -port port (defaults to 3000) |
127 | -k -keepalive enable keep-alive connections |
128 | -r -restart restart when files get modified |
129 | (defaults to false) |
130 | -rd -restartdelay delay between file checks |
131 | (ignored if you have Linux::Inotify2 installed) |
132 | -rr -restartregex regex match files that trigger |
133 | a restart when modified |
134 | (defaults to '\.yml$|\.yaml$|\.conf|\.pm$') |
135 | -restartdirectory the directory to search for |
136 | modified files, can be set mulitple times |
137 | (defaults to '[SCRIPT_DIR]/..') |
138 | -follow_symlinks follow symlinks in search directories |
139 | (defaults to false. this is a no-op on Win32) |
140 | -background run the process in the background |
141 | -pidfile specify filename for pid file |
142 | |
143 | See also: |
144 | perldoc Catalyst::Manual |
145 | perldoc Catalyst::Manual::Intro |
146 | |
147 | =head1 DESCRIPTION |
148 | |
149 | Run a Catalyst Testserver for this application. |
150 | |
151 | =head1 AUTHORS |
152 | |
153 | Catalyst Contributors, see Catalyst.pm |
154 | |
155 | =head1 COPYRIGHT |
156 | |
157 | This library is free software. You can redistribute it and/or modify |
158 | it under the same terms as Perl itself. |
159 | |
160 | =cut |
e5b6823d |
161 | #!/usr/local/bin/perl -w |
162 | |
163 | BEGIN { |
164 | $ENV{CATALYST_ENGINE} ||= 'HTTP'; |
1200a1ee |
165 | $ENV{CATALYST_SCRIPT_GEN} = 31; |
e5b6823d |
166 | require Catalyst::Engine::HTTP; |
167 | } |
168 | |
169 | use strict; |
170 | use warnings; |
171 | use Getopt::Long; |
172 | use Pod::Usage; |
173 | use FindBin; |
174 | use lib "$FindBin::Bin/../lib"; |
175 | |
176 | my $debug = 0; |
177 | my $fork = 0; |
178 | my $help = 0; |
179 | my $host = undef; |
180 | my $port = $ENV{TESTAPP_PORT} || $ENV{CATALYST_PORT} || 3000; |
181 | my $keepalive = 0; |
182 | my $restart = $ENV{TESTAPP_RELOAD} || $ENV{CATALYST_RELOAD} || 0; |
183 | my $restart_delay = 1; |
1200a1ee |
184 | my $restart_regex = '(?:/|^)(?!\.#).+(?:\.yml$|\.yaml$|\.conf|\.pm)$'; |
e5b6823d |
185 | my $restart_directory = undef; |
1200a1ee |
186 | my $follow_symlinks = 0; |
e5b6823d |
187 | |
188 | my @argv = @ARGV; |
189 | |
190 | GetOptions( |
191 | 'debug|d' => \$debug, |
192 | 'fork' => \$fork, |
193 | 'help|?' => \$help, |
194 | 'host=s' => \$host, |
195 | 'port=s' => \$port, |
196 | 'keepalive|k' => \$keepalive, |
197 | 'restart|r' => \$restart, |
198 | 'restartdelay|rd=s' => \$restart_delay, |
199 | 'restartregex|rr=s' => \$restart_regex, |
1200a1ee |
200 | 'restartdirectory=s@' => \$restart_directory, |
201 | 'followsymlinks' => \$follow_symlinks, |
e5b6823d |
202 | ); |
203 | |
204 | pod2usage(1) if $help; |
205 | |
206 | if ( $restart && $ENV{CATALYST_ENGINE} eq 'HTTP' ) { |
207 | $ENV{CATALYST_ENGINE} = 'HTTP::Restarter'; |
208 | } |
209 | if ( $debug ) { |
210 | $ENV{CATALYST_DEBUG} = 1; |
211 | } |
212 | |
213 | # This is require instead of use so that the above environment |
214 | # variables can be set at runtime. |
215 | require TestApp; |
216 | |
217 | TestApp->run( $port, $host, { |
218 | argv => \@argv, |
219 | 'fork' => $fork, |
220 | keepalive => $keepalive, |
221 | restart => $restart, |
222 | restart_delay => $restart_delay, |
223 | restart_regex => qr/$restart_regex/, |
224 | restart_directory => $restart_directory, |
1200a1ee |
225 | follow_symlinks => $follow_symlinks, |
e5b6823d |
226 | } ); |
227 | |
228 | 1; |
229 | |
230 | =head1 NAME |
231 | |
232 | testapp_server.pl - Catalyst Testserver |
233 | |
234 | =head1 SYNOPSIS |
235 | |
236 | testapp_server.pl [options] |
237 | |
238 | Options: |
239 | -d -debug force debug mode |
240 | -f -fork handle each request in a new process |
241 | (defaults to false) |
242 | -? -help display this help and exits |
243 | -host host (defaults to all) |
244 | -p -port port (defaults to 3000) |
245 | -k -keepalive enable keep-alive connections |
246 | -r -restart restart when files get modified |
247 | (defaults to false) |
248 | -rd -restartdelay delay between file checks |
249 | -rr -restartregex regex match files that trigger |
250 | a restart when modified |
1200a1ee |
251 | (defaults to '\.yml$|\.yaml$|\.conf|\.pm$') |
e5b6823d |
252 | -restartdirectory the directory to search for |
1200a1ee |
253 | modified files, can be set mulitple times |
254 | (defaults to '[SCRIPT_DIR]/..') |
255 | -follow_symlinks follow symlinks in search directories |
256 | (defaults to false. this is a no-op on Win32) |
e5b6823d |
257 | See also: |
258 | perldoc Catalyst::Manual |
259 | perldoc Catalyst::Manual::Intro |
260 | |
261 | =head1 DESCRIPTION |
262 | |
263 | Run a Catalyst Testserver for this application. |
264 | |
265 | =head1 AUTHOR |
266 | |
267 | Sebastian Riedel, C<sri@oook.de> |
268 | Maintained by the Catalyst Core Team. |
269 | |
270 | =head1 COPYRIGHT |
271 | |
272 | This library is free software, you can redistribute it and/or modify |
273 | it under the same terms as Perl itself. |
274 | |
275 | =cut |