File Coverage

lib/Egg/Request/FastCGI.pm
Criterion Covered Total %
statement 7 9 77.7
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 10 12 83.3


line stmt bran cond sub pod time code
1             package Egg::Request::FastCGI;
2             #
3             # Masatoshi Mizuno E<lt>lusheE<64>cpan.orgE<gt>
4             #
5             # $Id: FastCGI.pm 337 2008-05-14 12:30:09Z lushe $
6             #
7 1     1   366 use strict;
  1         2  
  1         29  
8 1     1   5 use warnings;
  1         2  
  1         22  
9 1     1   1852 use CGI::Fast;
  0            
  0            
10             use base qw/ Egg::Request::CGI /;
11              
12             our $VERSION = '3.00';
13              
14             sub _init_handler {
15             my($class, $e)= @_;
16             my $p= $e->namespace;
17             my $name_uc= uc($p);
18             my($count, $life_count, $life_time, $reboot);
19             if ($count= $ENV{"${name_uc}_FCGI_LIFE_COUNT"}) {
20             $life_count= sub { --$count > 0 ? 1: 0 };
21             }
22             if (my $ltime= $ENV{"${name_uc}_FCGI_LIFE_TIME"}) {
23             $ltime+= time;
24             $life_time= sub { $ltime > time ? 1: 0 };
25             }
26             if (my $rl= $ENV{"${name_uc}_FCGI_REBOOT"}) {
27             my $name= $rl ne 1 ? $rl: 'reboot';
28             $reboot= sub { $_[0]->param($name) ? 0: 1 };
29             }
30             $reboot ||= sub { 1 };
31             $life_count ||= sub { 1 };
32             $life_time ||= sub { 1 };
33             no strict 'refs'; ## no critic
34             no warnings 'redefine';
35             *{"${p}::handler"}= sub {
36             while (my $fcgi= CGI::Fast->new) {
37             $p->run($fcgi);
38             $reboot->($fcgi) || last;
39             $life_count->() || last;
40             $life_time->() || last;
41             }
42             };
43             @_;
44             }
45              
46             1;
47              
48             __END__
49              
50             =head1 NAME
51              
52             Egg::Request::FastCGI - Request class to use FastCGI.
53              
54             =head1 SYNOPSIS
55              
56             Example is dispatch.fcgi
57              
58             #!/usr/bin/perl
59             BEGIN {
60             $ENV{MYAPP_REQUEST_CLASS} = 'Egg::Request::FastCGI';
61             $ENV{MYAPP_FCGI_LIFE_COUNT} = 200;
62             $ENV{MYAPP_FCGI_LIFE_TIME} = 1800;
63             $ENV{MYAPP_FCGI_REBOOT} = 'boot';
64             };
65             use MyApp;
66             MyApp->handler;
67              
68             =head1 DESCRIPTION
69              
70             It is a request class to use FastCGI.
71              
72             To make it loaded from Egg::Request, environment variable PROJECT_NAME_REQUEST_CLASS
73             is defined beforehand.
74              
75             BEGIN{
76             $ENV{MYAPP_REQUEST_CLASS}= 'Egg::Request::FastCGI';
77             };
78              
79             Moreover, the following environment variables are accepted, and define it similarly
80             in the BEGIN block, please when setting it.
81              
82             =over 4
83              
84             =item * [PROJECT_NAME]_FCGI_LIFE_COUNT
85              
86             After the frequency is processed being set, the process is ended.
87              
88             =item * [PROJECT_NAME]_FCGI_LIFE_TIME
89              
90             The process of each set number of seconds is ended.
91              
92             =item * [PROJECT_NAME]_FCGI_REBOOT
93              
94             The process is dropped at once when request query of the name is effective when
95             the name of request query is set.
96             1 When is set, it is assumed the one that 'reboot' of default was specified.
97             For instance, the process falls after outputting contents when assuming
98             http://ho.com/?reboot=1.
99             Contents are output according to the process that started newly when being
100             request it next time.
101             Please do not forget the invalidated thing in the real thing operation because
102             this is a setting for debug.
103              
104             * Please note no movement the intention when you do debug by starting two or more
105             processes.
106              
107             =back
108              
109             This module only sets up the handler for L<CGI::Fast>.
110              
111             Processing requesting original has succeeded to L<Egg::Request::CGI>.
112              
113             =head1 SEE ALSO
114              
115             L<Egg::Release>,
116             L<Egg::Request>,
117             L<Egg::Request::CGI>,
118             L<CGI::Fast>,
119              
120             =head1 AUTHOR
121              
122             Masatoshi Mizuno E<lt>lusheE<64>cpan.orgE<gt>
123              
124             =head1 COPYRIGHT AND LICENSE
125              
126             Copyright (C) 2008 Bee Flag, Corp. E<lt>L<http://egg.bomcity.com/>E<gt>.
127              
128             This library is free software; you can redistribute it and/or modify
129             it under the same terms as Perl itself, either Perl version 5.8.6 or,
130             at your option, any later version of Perl 5 you may have available.
131              
132             =cut
133