| 1 | package FCGI::EV::Std::Nonblock; | ||||||||||
| 2 | 1 | ▶ | use 5.010001; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use utf8; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 1 | our $VERSION = 'v2.0.1'; | |||||||||
| 9 | |||||||||||
| 10 | 1 | ▶ | use Scalar::Util qw( weaken refaddr ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 1 | ▶ | use FCGI::EV::Std; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 1 | $FCGI::EV::Std::BLOCKING= 0; | |||||||||
| 14 | 1 | $FCGI::EV::Std::MAIN = \&new; | |||||||||
| 15 | 1 | $FCGI::EV::Std::HUP = \&HUP; | |||||||||
| 16 | |||||||||||
| 17 | 1 | my $CB_START = \&main::START; | |||||||||
| 18 | 1 | my $CB_PRE = \&main::PRE; | |||||||||
| 19 | 1 | my $CB_POST = \&main::POST; | |||||||||
| 20 | 1 | my $CB_ERROR = \&main::ERROR; | |||||||||
| 21 | #my $HUP = undef; | ||||||||||
| 22 | |||||||||||
| 23 | 1 | my (%Active, %Server); | |||||||||
| 24 | |||||||||||
| 25 | |||||||||||
| 26 | 0 | ▶ | sub new { | ||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 27 | 0 | my ($server) = @_; | |||||||||
| 28 | 0 | my $self = bless {}, __PACKAGE__; | |||||||||
| 29 | 0 | $Active{ refaddr($self) } = $server; | |||||||||
| 30 | 0 | $Server{ refaddr($server) } = $self; | |||||||||
| 31 | 0 | weaken( $Active{ refaddr($self) } ); | |||||||||
| 32 | 0 | $self->_wrapper($CB_START); | |||||||||
| 33 | 0 | return; | |||||||||
| 34 | } | ||||||||||
| 35 | |||||||||||
| 36 | 0 | ▶ | sub done { | ||||||||
|
Subroutine
done: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 37 | 0 | my ($self) = @_; | |||||||||
| 38 | 0 | ▶ | if (exists $Active{ refaddr($self) }) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | 0 | my $server = delete $Active{ refaddr($self) }; | |||||||||
| 40 | 0 | ▶ | if ($server) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 41 | 0 | delete $Server{ refaddr($server) }; | |||||||||
| 42 | 0 | $server->stdout(q{}, 1); | |||||||||
| 43 | } | ||||||||||
| 44 | } | ||||||||||
| 45 | else { | ||||||||||
| 46 | 0 | croak 'this request already done()'; | |||||||||
| 47 | } | ||||||||||
| 48 | 0 | return; | |||||||||
| 49 | } | ||||||||||
| 50 | |||||||||||
| 51 | 0 | ▶ | sub HUP { | ||||||||
|
Subroutine
HUP: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 52 | 0 | my ($server) = @_; | |||||||||
| 53 | 0 | ▶ | return if !$server; # may happens during global destruction | ||||||||
|
Branch: 1 branch
| |||||||||||
| 54 | 0 | ▶ | if (exists $Server{ refaddr($server) }) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 55 | 0 | my $self = delete $Server{ refaddr($server) }; | |||||||||
| 56 | # $HUP && $HUP->($self); | ||||||||||
| 57 | } | ||||||||||
| 58 | 0 | return; | |||||||||
| 59 | } | ||||||||||
| 60 | |||||||||||
| 61 | 0 | ▶ | sub send { ## no critic (ProhibitBuiltinHomonyms) | ||||||||
|
Subroutine
send: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 62 | 0 | my ($self, $buf) = @_; | |||||||||
| 63 | 0 | my $server = $Active{ refaddr($self) }; | |||||||||
| 64 | 0 | ▶ | if ($server) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 65 | 0 | $server->stdout($buf, 0); | |||||||||
| 66 | } | ||||||||||
| 67 | 0 | return; | |||||||||
| 68 | } | ||||||||||
| 69 | |||||||||||
| 70 | 0 | ▶ | sub wrap_cb { | ||||||||
|
Subroutine
wrap_cb: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 71 | 0 | my ($self, $cb, @p) = @_; | |||||||||
| 72 | 0 | weaken(my $this = $self); | |||||||||
| 73 | 0 | ▶ | return sub { $this && $this->_wrapper($cb, @p, @_) }; | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||
| 74 | } | ||||||||||
| 75 | |||||||||||
| 76 | 0 | ▶ | sub _wrapper { | ||||||||
|
Subroutine
_wrapper: not called CC=3 SCAR=24.8
| |||||||||||
| 77 | 0 | my ($this, $cb, @p) = @_; | |||||||||
| 78 | |||||||||||
| 79 | 0 | $CB_PRE->($this); | |||||||||
| 80 | 0 | ▶ | my $err = eval { $cb->($this, @p); 1 } ? undef : $@; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 81 | 0 | $CB_POST->($this); | |||||||||
| 82 | |||||||||||
| 83 | 0 | ▶ | if (defined $err) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 84 | 0 | $CB_ERROR->($this, $err); | |||||||||
| 85 | } | ||||||||||
| 86 | 0 | return; | |||||||||
| 87 | } | ||||||||||
| 88 | |||||||||||
| 89 | |||||||||||
| 90 | 1 | 1; # Magic true value required at end of module | |||||||||
| 91 | __END__ | ||||||||||