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