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