Std/Nonblock.pm

filter: Statementstmt 44.1% 30 / 68 Branchbran 0.0% 0 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 50.0% 7 / 14 Podpod 60.0% 3 / 5 totaltotal 38.8% 40 / 103 CC 9 SCAR 18.7
CC
9
Cov
36%
done
12.0
HUP
12.0
_wrapper
12.0
CRAP 6.5
« Std.pm ↑ Summary
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
BranchTrueFalseTotal
if (exists $Active{builtin::refaddr($self)}) { } 0 0 0
39 0 my $server = delete $Active{ refaddr($self) };
40 0 ▶ if ($server) {
Branch: 1 branch
BranchTrueFalseTotal
if ($server) 0 0 0
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
BranchTrueFalseTotal
unless $server 0 0 0
54 0 ▶ if (exists $Server{ refaddr($server) }) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $Server{builtin::refaddr($server)}) 0 0 0
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
BranchTrueFalseTotal
if ($server) 0 0 0
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
BranchTrueFalseTotal
$this and $this->_wrapper($cb, @p, @_) 0 0 0
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
BranchTrueFalseTotal
eval { do { &$cb($this, @p); 1 } } ? : 0 0 0
81 0 $CB_POST->($this);
82  
83 0 ▶ if (defined $err) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $err) 0 0 0
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__
« Std.pm ↑ Summary