fixed test server, blech
[catagits/Catalyst-Runtime.git] / t / TestApp / script / testapp_server.pl
1 package TestApp::Script::Server;
2
3 use Catalyst::Engine::HTTP;
4 use TestApp;
5 use Moose;
6
7 with 'MooseX::GetOpt';
8
9 has argv => ( isa => 'ArrayRef', is => 'ro', required => 1 );
10 has [qw/ fork background keepalive /] => ( isa => 'Bool', is => 'ro', required => 1, default => 0 );
11 has pidfile => ( isa => 'Str', required => 0, is => 'ro' );
12
13 sub run {
14     my $self = shift;
15     TestApp->run(
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
27 pod2usage(1) if $help;
28
29 if ( $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.
35 require 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
41 my $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
58 if ( $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 }
83 else {
84     $runner->();
85 }
86
87 __PACKAGE__->new_with_options->run;
88
89
90
91 1;
92
93 =head1 NAME
94
95 testapp_server.pl - Catalyst Testserver
96
97 =head1 SYNOPSIS
98
99 testapp_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
130 Run a Catalyst Testserver for this application.
131
132 =head1 AUTHORS
133
134 Catalyst Contributors, see Catalyst.pm
135
136 =head1 COPYRIGHT
137
138 This library is free software. You can redistribute it and/or modify
139 it under the same terms as Perl itself.
140
141 =cut