background now has a short opshun
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Script / Server.pm
CommitLineData
0ba6e8aa 1package Catalyst::Script::Server;
2
53b08cf9 3BEGIN {
4 $ENV{CATALYST_ENGINE} ||= 'HTTP';
5 $ENV{CATALYST_SCRIPT_GEN} = 31;
6 require Catalyst::Engine::HTTP;
7}
5b923b0b 8
a3ca4468 9use FindBin qw/$Bin/;
10use lib "$Bin/../lib";
11use Pod::Usage;
12use Moose;
13use Catalyst::Engine::HTTP;
14use namespace::clean -except => [ qw(meta) ];
15
16with 'MooseX::Getopt';
17
e46bf32c 18has help => (
19 traits => [qw(Getopt)],
90b481b1 20 cmd_aliases => 'h',
e46bf32c 21 isa => 'Bool',
22 is => 'ro',
23 required => 0,
90b481b1 24 default => 0,
e46bf32c 25);
26
41b55019 27has host => (
28 isa => 'Str',
29 is => 'ro',
30 required => 0,
31 default => "localhost"
32);
90b481b1 33
34has fork => (
35 traits => [qw(Getopt)],
36 cmd_aliases => 'f',
37 isa => 'Bool',
38 is => 'ro',
39 required => 0
40);
41
204c6935 42has listen => (
43 traits => [qw(Getopt)],
44 cmd_aliases => 'l',
45 isa => 'Int',
46 is => 'ro',
47 required => 0,
48 default => "3000"
49);
50
41b55019 51has pidfile => (
52 traits => [qw(Getopt)],
b6aaf142 53 cmd_aliases => 'pid',
41b55019 54 isa => 'Str',
55 is => 'ro',
56 required => 0
57);
58
bd31e11f 59has keepalive => (
60 traits => [qw(Getopt)],
61 cmd_aliases => 'k',
62 isa => 'Bool',
63 is => 'ro',
64 required => 0,
65 default => 0
66);
67
3954573c 68has background => (
69 traits => [qw(Getopt)],
70 cmd_aliases => 'bg',
71 isa => 'Bool',
72 is => 'ro',
73 required => 0
74);
75
bd31e11f 76has app => ( isa => 'Str', is => 'ro', required => 1 ); # THIS IS FUCKING RETARDED HALP PLZ
615fee7c 77has restart => ( isa => 'Bool', is => 'ro', required => 0 );
78has restart_delay => ( isa => 'Int', is => 'ro', required => 0 );
79has restart_regex => ( isa => 'Str', is => 'ro', required => 0 );
80has follow_symlinks => ( isa => 'Bool', is => 'ro', required => 0 );
a3ca4468 81
82my @argv = @ARGV;
83
84sub run {
85 my $self = shift;
86
87 pod2usage() if $self->help;
88 my $app = $self->app;
89 Class::MOP::load_class($app);
90 $app->run(
91 $self->listen, $self->host,
92 {
93 'fork' => $self->fork,
94 keepalive => $self->keepalive,
95 background => $self->background,
96 pidfile => $self->pidfile,
615fee7c 97 keepalive => $self->keepalive,
98 restart => $self->restart,
99 restart_delay => $self->restart_delay,
100 restart_regex => qr/$self->restart_regex/,
c1c59374 101# FIXME restart_directory => $self->restart_directory,
615fee7c 102 follow_symlinks => $self->follow_symlinks,
a3ca4468 103 }
104 );
105
106}
5b923b0b 107
5b923b0b 108
0ba6e8aa 1091;
e46bf32c 110
111=head1 NAME
112
113[% appprefix %]_server.pl - Catalyst Testserver
114
115=head1 SYNOPSIS
116
117[% appprefix %]_server.pl [options]
118
119 Options:
120 -d -debug force debug mode
121 -f -fork handle each request in a new process
122 (defaults to false)
123 -? -help display this help and exits
124 -host host (defaults to all)
125 -p -port port (defaults to 3000)
126 -k -keepalive enable keep-alive connections
127 -r -restart restart when files get modified
128 (defaults to false)
129 -rd -restartdelay delay between file checks
130 (ignored if you have Linux::Inotify2 installed)
131 -rr -restartregex regex match files that trigger
132 a restart when modified
133 (defaults to '\.yml$|\.yaml$|\.conf|\.pm$')
134 -restartdirectory the directory to search for
135 modified files, can be set mulitple times
136 (defaults to '[SCRIPT_DIR]/..')
137 -follow_symlinks follow symlinks in search directories
138 (defaults to false. this is a no-op on Win32)
139 -background run the process in the background
140 -pidfile specify filename for pid file
141
142 See also:
143 perldoc Catalyst::Manual
144 perldoc Catalyst::Manual::Intro
145
146=head1 DESCRIPTION
147
148Run a Catalyst Testserver for this application.
149
150=head1 AUTHORS
151
152Catalyst Contributors, see Catalyst.pm
153
154=head1 COPYRIGHT
155
156This library is free software. You can redistribute it and/or modify
157it under the same terms as Perl itself.
158
159=cut