Fix the fcgi script tests.
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Script / FastCGI.pm
1 package Catalyst::Script::FastCGI;
2 use Moose;
3 use MooseX::Types::Moose qw/Str Bool Int/;
4 use Data::OptList;
5 use namespace::autoclean;
6
7 sub _plack_engine_name { 'FCGI' }
8
9 with 'Catalyst::ScriptRole';
10
11 has listen => (
12     traits        => [qw(Getopt)],
13     cmd_aliases   => 'l',
14     isa           => Str,
15     is            => 'ro',
16     documentation => 'Specify a listening port/socket',
17 );
18
19 has pidfile => (
20     traits        => [qw(Getopt)],
21     cmd_aliases   => [qw/pid p/],
22     isa           => Str,
23     is            => 'ro',
24     documentation => 'Specify a pidfile',
25 );
26
27 has daemon => (
28     traits        => [qw(Getopt)],
29     isa           => Bool,
30     is            => 'ro',
31     cmd_aliases   => [qw/d detach/], # Eww, detach is here as we fucked it up.. Deliberately not documented
32     documentation => 'Daemonize (go into the background)',
33 );
34
35 has manager => (
36     traits        => [qw(Getopt)],
37     isa           => Str,
38     is            => 'ro',
39     cmd_aliases   => 'M',
40     documentation => 'Use a different FastCGI process manager class',
41 );
42
43 has keeperr => (
44     traits        => [qw(Getopt)],
45     cmd_aliases   => 'e',
46     isa           => Bool,
47     is            => 'ro',
48     documentation => 'Log STDERR',
49 );
50
51 has nproc => (
52     traits        => [qw(Getopt)],
53     cmd_aliases   => 'n',
54     isa           => Int,
55     is            => 'ro',
56     documentation => 'Specify a number of child processes',
57 );
58
59 sub _plack_loader_args {
60     my ($self) = shift;
61     return (
62         map { $_->[0] => $self->${ \($_->[1] ? $_->[1]->[0] : $_->[0]) } }
63         Data::OptList::mkopt([
64             qw/pidfile listen manager nproc keep_stderr/,
65             detach => [ 'daemon'],
66         ])
67     );
68 }
69
70 sub _application_args {
71     my ($self) = shift;
72     return (
73         $self->listen,
74         {
75             nproc   => $self->nproc,
76             pidfile => $self->pidfile,
77             manager => $self->manager,
78             detach  => $self->daemon,
79             keep_stderr => $self->keeperr,
80         }
81     );
82 }
83
84 __PACKAGE__->meta->make_immutable;
85
86 =head1 NAME
87
88 Catalyst::Script::FastCGI - The FastCGI Catalyst Script
89
90 =head1 SYNOPSIS
91
92   myapp_fastcgi.pl [options]
93
94  Options:
95    -? --help      display this help and exits
96    -l --listen    Socket path to listen on
97                   (defaults to standard input)
98                   can be HOST:PORT, :PORT or a
99                   filesystem path
100    -n --nproc     specify number of processes to keep
101                   to serve requests (defaults to 1,
102                   requires -listen)
103    -p --pidfile   specify filename for pid file
104                   (requires -listen)
105    -d --daemon    daemonize (requires -listen)
106    -M --manager   specify alternate process manager
107                   (FCGI::ProcManager sub-class)
108                   or empty string to disable
109    -e --keeperr   send error messages to STDOUT, not
110                   to the webserver
111
112 =head1 DESCRIPTION
113
114 Run a Catalyst application as fastcgi.
115
116 =head1 AUTHORS
117
118 Catalyst Contributors, see Catalyst.pm
119
120 =head1 COPYRIGHT
121
122 This library is free software. You can redistribute it and/or modify it under
123 the same terms as Perl itself.
124
125 =cut