fixed test server, blech
[catagits/Catalyst-Runtime.git] / t / TestApp / script / testapp_server.pl
CommitLineData
e81ebbfd 1package TestApp::Script::Server;
cc999ce2 2
3use Catalyst::Engine::HTTP;
e81ebbfd 4use TestApp;
cc999ce2 5use Moose;
6
7with 'MooseX::GetOpt';
8
9has argv => ( isa => 'ArrayRef', is => 'ro', required => 1 );
10has [qw/ fork background keepalive /] => ( isa => 'Bool', is => 'ro', required => 1, default => 0 );
11has pidfile => ( isa => 'Str', required => 0, is => 'ro' );
12
13sub run {
14 my $self = shift;
e81ebbfd 15 TestApp->run(
cc999ce2 16 $port, $host,
17 {
18 argv => $self->argv,
19 'fork' => $self->fork,
20 keepalive => $self->keepalive,
21 background => $self->background,
22 pidfile => $self->pidfile,
23 }
24 );
25}
26
27pod2usage(1) if $help;
28
29if ( $debug ) {
30 $ENV{CATALYST_DEBUG} = 1;
31}
32
33# If we load this here, then in the case of a restarter, it does not
34# need to be reloaded for each restart.
35require Catalyst;
36
37# If this isn't done, then the Catalyst::Devel tests for the restarter
38# fail.
39$| = 1 if $ENV{HARNESS_ACTIVE};
40
41my $runner = sub {
42 # This is require instead of use so that the above environment
43 # variables can be set at runtime.
44 require TestApp;
45
46 TestApp->run(
47 $port, $host,
48 {
49 argv => \@argv,
50 'fork' => $fork,
51 keepalive => $keepalive,
52 background => $background,
53 pidfile => $pidfile,
54 }
55 );
56};
57
58if ( $restart ) {
59 die "Cannot run in the background and also watch for changed files.\n"
60 if $background;
61
62 require Catalyst::Restarter;
63
64 my $subclass = Catalyst::Restarter->pick_subclass;
65
66 my %args;
67 $args{follow_symlinks} = 1
68 if $follow_symlinks;
69 $args{directories} = $watch_directory
70 if defined $watch_directory;
71 $args{sleep_interval} = $check_interval
72 if defined $check_interval;
73 $args{filter} = qr/$file_regex/
74 if defined $file_regex;
75
76 my $restarter = $subclass->new(
77 %args,
78 start_sub => $runner,
79 );
80
81 $restarter->run_and_watch;
82}
83else {
84 $runner->();
85}
86
87__PACKAGE__->new_with_options->run;
88
89
90
911;
92
93=head1 NAME
94
95testapp_server.pl - Catalyst Testserver
96
97=head1 SYNOPSIS
98
99testapp_server.pl [options]
100
101 Options:
102 -d -debug force debug mode
103 -f -fork handle each request in a new process
104 (defaults to false)
105 -? -help display this help and exits
106 -host host (defaults to all)
107 -p -port port (defaults to 3000)
108 -k -keepalive enable keep-alive connections
109 -r -restart restart when files get modified
110 (defaults to false)
111 -rd -restartdelay delay between file checks
112 (ignored if you have Linux::Inotify2 installed)
113 -rr -restartregex regex match files that trigger
114 a restart when modified
115 (defaults to '\.yml$|\.yaml$|\.conf|\.pm$')
116 -restartdirectory the directory to search for
117 modified files, can be set mulitple times
118 (defaults to '[SCRIPT_DIR]/..')
119 -follow_symlinks follow symlinks in search directories
120 (defaults to false. this is a no-op on Win32)
121 -background run the process in the background
122 -pidfile specify filename for pid file
123
124 See also:
125 perldoc Catalyst::Manual
126 perldoc Catalyst::Manual::Intro
127
128=head1 DESCRIPTION
129
130Run a Catalyst Testserver for this application.
131
132=head1 AUTHORS
133
134Catalyst Contributors, see Catalyst.pm
135
136=head1 COPYRIGHT
137
138This library is free software. You can redistribute it and/or modify
139it under the same terms as Perl itself.
140
141=cut