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