Spore/Role/Middleware.pm

filter: Statementstmt 100% 39 / 39 Branchbran 91.6% 11 / 12 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 10 / 10 Podpod 0.0% 0 / 3 totaltotal 91.3% 63 / 69 CC 8 SCAR 8.3
CC
8
Cov
96%
enable_if
4.0
_complete_mw_name
3.0
_load_middleware
2.0
CRAP 2.3
« Spore/Response.pm ↑ Summary Spore/Role.pm »
1 package Net::HTTP::Spore::Role::Middleware;
2 26 $Net::HTTP::Spore::Role::Middleware::VERSION = '0.09';
3 26 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 26 ▶use Class::Load;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 26 ▶use Scalar::Util qw/blessed/;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 has middlewares => (
8 is => 'rw',
9 isa => 'ArrayRef',
10 traits => ['Array'],
11 lazy => 1,
12 23 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
13 26 auto_deref => 1,
14 handles => { _add_middleware => 'push', _filter_middlewares => 'grep' },
15 );
16  
17 43 ▶sub _load_middleware {
Subroutine _load_middleware: called CC=2 SCAR=6.9
18 43 my ( $self, $mw, $cond, @args ) = @_;
19  
20 43 ▶ Class::Load::load_class($mw) unless blessed($mw);
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($mw) 41 2 43
21  
22 41 my $code = $mw->wrap( $cond, @args );
23 41 $self->_trace_msg('== enabling middleware %s', $mw);
24 41 $self->_add_middleware($code);
25 }
26  
27 41 ▶sub _complete_mw_name {
Subroutine _complete_mw_name: called CC=3 SCAR=11.0
28 41 my ($self, $mw) = @_;
29  
30 41 ▶ if ($mw =~ /^\+/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($mw =~ /^\+/) { } 1 40 41
elsif (not $mw =~ /Net\:\:HTTP\:\:Spore\:\:Middleware/) { } 40 0 40
31 1 $mw =~ s/^\+//;
32 }
33 elsif ($mw !~ /Net\:\:HTTP\:\:Spore\:\:Middleware/) {
34 40 $mw = "Net::HTTP::Spore::Middleware::".$mw;
35 }
36  
37 41 return $mw;
38 }
39  
40 43 ▶sub enable {
Subroutine enable: called CC=2 SCAR=6.9
Pod undocumented
41 43 my ($self, $mw, @args) = @_;
42  
43 43 ▶ confess "middleware name is missing" unless $mw;
Branch: 1 branch
BranchTrueFalseTotal
unless $mw 1 42 43
44  
45 42 ▶ $self->enable_if(sub{1}, $mw, @args);
Subroutine __ANON__: called CC=1 SCAR=0.0
46 40 $self;
47 }
48  
49 44 ▶sub enable_if {
Subroutine enable_if: called CC=4 SCAR=13.9
Pod undocumented
50 44 my ($self, $cond, $mw, @args) = @_;
51  
52 44 ▶ confess "condition must be a code ref" if (!$cond || ref $cond ne 'CODE');
Branch: 1 branch
BranchTrueFalseTotal
if not $cond or ref $cond ne "CODE" 1 43 44
Condition66%2/3
not $cond or ref $cond ne "CODE"
l!l&&r!l&&!r
0143
MC/DC50%1/2
not $cond or ref $cond ne "CODE"
not $cond ref $cond ne "CODE"
Truth table66%2/3
not(A) or B
A= not $condB= ref $cond ne "CODE"
ABresult
1X1
011
000
53  
54 43 ▶ if(ref($mw) eq 'CODE'){ # anonymous middleware
Branch: 1 branch
BranchTrueFalseTotal
if (ref $mw eq 'CODE') { } 2 41 43
55 2 Class::Load::load_class('Net::HTTP::Spore::Middleware');
56 2 my $anon = Class::MOP::Class->create_anon_class(
57 superclasses => ['Net::HTTP::Spore::Middleware'],
58 methods => {
59 call => $mw
60 }
61 );
62 2 $mw = $anon->new_object;
63 } else {
64 41 $mw = $self->_complete_mw_name($mw);
65 }
66 43 $self->_load_middleware($mw, $cond, @args);
67 41 $self;
68 }
69  
70 1 ▶sub reset_middlewares {
Subroutine reset_middlewares: called CC=1 SCAR=0.0
Pod undocumented
71 1 my $self = shift;
72 1 $self->middlewares([]);
73 }
74  
75 26 1;
76  
77 __END__
« Spore/Response.pm ↑ Summary Spore/Role.pm »