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