fixed Server
[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            => ( isa => 'Bool',   is => 'ro', required => 0, default => sub { 0 } );
19 has host            => ( isa => 'Str',    is => 'ro', required => 0, default => sub { "localhost" } );
20 has fork            => ( isa => 'Bool',   is => 'ro', required => 0 );
21 has listen          => ( isa => 'Int',    is => 'ro', required => 0, default => sub{ 3000 } );
22 has pidfile         => ( isa => 'Str',    is => 'ro', required => 0 );
23 has keepalive       => ( isa => 'Bool',   is => 'ro', required => 0, default => sub { 0 } );
24 has background      => ( isa => 'Bool',   is => 'ro', required => 0 );
25 has app             => ( isa => 'Str',    is => 'ro', required => 1 );
26 has restart         => ( isa => 'Bool',   is => 'ro', required => 0 );
27 has restart_delay   => ( isa => 'Int',    is => 'ro', required => 0 );
28 has restart_regex   => ( isa => 'Str',    is => 'ro', required => 0 );
29 has follow_symlinks => ( isa => 'Bool',   is => 'ro', required => 0 );
30
31 my @argv = @ARGV;
32
33 sub run {
34     my $self = shift;
35     
36     pod2usage() if $self->help;
37     my $app = $self->app;
38     Class::MOP::load_class($app);
39     $app->run(
40         $self->listen, $self->host,
41         {  
42            'fork'     => $self->fork,
43            keepalive  => $self->keepalive,
44            background => $self->background,
45            pidfile    => $self->pidfile,
46            keepalive         => $self->keepalive,
47            restart           => $self->restart,
48            restart_delay     => $self->restart_delay,
49            restart_regex     => qr/$self->restart_regex/,
50 # FIXME    restart_directory => $self->restart_directory,
51            follow_symlinks   => $self->follow_symlinks,
52         }  
53     );
54
55 }
56
57
58 1;