File Coverage

blib/lib/Catalyst/Script/FastCGI.pm
Criterion Covered Total %
statement 25 25 100.0
branch 6 6 100.0
condition n/a
subroutine 8 8 100.0
pod 0 1 0.0
total 39 40 97.5


line stmt bran cond sub pod time code
1             use Moose;
2 2     2   62688 use Data::OptList;
  2         385834  
  2         10  
3 2     2   12437 use namespace::clean -except => [ 'meta' ];
  2         5  
  2         18  
4 2     2   567  
  2         5489  
  2         19  
5              
6 15     15   44 with 'Catalyst::ScriptRole';
7              
8             has listen => (
9             traits => [qw(Getopt)],
10             cmd_aliases => 'l',
11             isa => 'Str',
12             is => 'ro',
13             documentation => 'Specify a listening port/socket',
14             );
15              
16             has pidfile => (
17             traits => [qw(Getopt)],
18             cmd_aliases => [qw/pid p/],
19             isa => 'Str',
20             is => 'ro',
21             documentation => 'Specify a pidfile',
22             );
23              
24             has daemon => (
25             traits => [qw(Getopt)],
26             isa => 'Bool',
27             is => 'ro',
28             cmd_aliases => [qw/d detach/], # Eww, detach is here as we fucked it up.. Deliberately not documented
29             documentation => 'Daemonize (go into the background)',
30             );
31              
32             has manager => (
33             traits => [qw(Getopt)],
34             isa => 'Str',
35             is => 'ro',
36             cmd_aliases => 'M',
37             documentation => 'Use a different FastCGI process manager class',
38             );
39              
40             has keeperr => (
41             traits => [qw(Getopt)],
42             cmd_aliases => 'e',
43             isa => 'Bool',
44             is => 'ro',
45             documentation => 'Log STDERR',
46             );
47              
48             has nproc => (
49             traits => [qw(Getopt)],
50             cmd_aliases => 'n',
51             isa => 'Int',
52             is => 'ro',
53             documentation => 'Specify a number of child processes',
54             );
55              
56             has proc_title => (
57             traits => [qw(Getopt)],
58             isa => 'Str',
59             is => 'ro',
60             lazy => 1,
61             builder => '_build_proc_title',
62             documentation => 'Set the process title',
63             );
64              
65             my ($self) = @_;
66             return sprintf 'perl-fcgi-pm [%s]', $self->application_name;
67             }
68 14     14   28  
69 14         372 my ($self) = @_;
70             $self->proc_title;
71             }
72              
73 15     15 0 275324 # Munge the 'listen' arg so that Plack::Handler::FCGI will accept it.
74 15         494 my ($self) = @_;
75              
76             if (defined (my $listen = $self->listen)) {
77             return [ $listen ];
78             } else {
79 15     15   30 return undef;
80             }
81 15 100       351 }
82 2         12  
83             my ($self) = shift;
84 13         73  
85             my $opts = Data::OptList::mkopt([
86             qw/manager nproc proc_title/,
87             pid => [ 'pidfile' ],
88             daemonize => [ 'daemon' ],
89 15     15   26 keep_stderr => [ 'keeperr' ],
90             listen => [ '_listen' ],
91 15         92 ]);
92              
93             my %args = map { $_->[0] => $self->${ \($_->[1] ? $_->[1]->[0] : $_->[0]) } } @$opts;
94              
95             # Plack::Handler::FCGI thinks manager => undef means "use no manager".
96             delete $args{'manager'} unless defined $args{'manager'};
97              
98             return %args;
99 15 100       1320 }
  105         155  
  105         2405  
100              
101             around _application_args => sub {
102 15 100       51 my ($orig, $self) = @_;
103             return (
104 15         123 $self->listen,
105             {
106             %{ $self->$orig },
107             nproc => $self->nproc,
108             pidfile => $self->pidfile,
109             manager => $self->manager,
110             detach => $self->daemon,
111             keep_stderr => $self->keeperr,
112             proc_title => $self->proc_title,
113             }
114             );
115             };
116              
117             __PACKAGE__->meta->make_immutable;
118             1;
119              
120             =head1 NAME
121              
122             Catalyst::Script::FastCGI - The FastCGI Catalyst Script
123              
124             =head1 SYNOPSIS
125              
126             myapp_fastcgi.pl [options]
127              
128             Options:
129             -? --help display this help and exits
130             -l --listen Socket path to listen on
131             (defaults to standard input)
132             can be HOST:PORT, :PORT or a
133             filesystem path
134             -n --nproc specify number of processes to keep
135             to serve requests (defaults to 1,
136             requires -listen)
137             -p --pidfile specify filename for pid file
138             (requires -listen)
139             -d --daemon daemonize (requires -listen)
140             -M --manager specify alternate process manager
141             (FCGI::ProcManager sub-class)
142             or empty string to disable
143             -e --keeperr send error messages to STDOUT, not
144             to the webserver
145             --proc_title set the process title
146              
147             =head1 DESCRIPTION
148              
149             Run a Catalyst application as fastcgi.
150              
151             =head1 SEE ALSO
152              
153             L<Catalyst::ScriptRunner>
154              
155             =head1 AUTHORS
156              
157             Catalyst Contributors, see Catalyst.pm
158              
159             =head1 COPYRIGHT
160              
161             This library is free software. You can redistribute it and/or modify it under
162             the same terms as Perl itself.
163              
164             =cut