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