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