Conditional/Stubs.pm

filter: Statementstmt 100% 25 / 25 Branchbran 66.6% 4 / 6 Conditioncond 63.6% 7 / 11 MC/DCmcdc 16.6% 1 / 6 Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 5 totaltotal 73.7% 45 / 61 CC 8 SCAR 10.3
CC
8
Cov
86%
execute
5.2
is_http_res
2.0
is_stub
2.0
CRAP 2.8
↑ Summary Conditional.pm »
1 package Test::Mock::LWP::Conditional::Stubs;
2  
3 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 7 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 11 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
8 11 my $class = shift;
9 11 return bless +{ count => 0, stubs => [] }, $class;
10 }
11  
12 42 ▶sub is_http_res {
Subroutine is_http_res: called CC=2 SCAR=7.1
Pod undocumented
13 42 my ($self, $res) = @_;
14 42 ▶ return blessed($res) && $res->isa('HTTP::Response');
Condition66%2/3
builtin::blessed($res) && $res->isa('HTTP::Response')
!ll&&!rl&&r
5037
MC/DC50%1/2
builtin::blessed($res) && $res->isa('HTTP::Response')
builtin::blessed($res) $res->isa('HTTP::Response')
Truth table66%2/3
A && B
A= builtin::blessed($res)B= $res->isa('HTTP::Response')
ABresult
0X0
100
111
15 }
16  
17 15 ▶sub is_stub {
Subroutine is_stub: called CC=2 SCAR=7.1
Pod undocumented
18 15 my ($self, $stub) = @_;
19 15 ▶ return $self->is_http_res($stub) || ref($stub) eq 'CODE';
Condition66%2/3
$self->is_http_res($stub) || ref $stub eq 'CODE'
l!l&&r!l&&!r
1320
MC/DC0%0/2
$self->is_http_res($stub) || ref $stub eq 'CODE'
$self->is_http_res($stub) ref $stub eq 'CODE'
Truth table66%2/3
A || B
A= $self->is_http_res($stub)B= ref $stub eq 'CODE'
ABresult
1X1
011
000
20 }
21  
22 15 ▶sub add {
Subroutine add: called CC=2 SCAR=7.1
Pod undocumented
23 15 my ($self, $stub) = @_;
24 15 ▶ push @{$self->{stubs}}, $stub if $self->is_stub($stub);
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_stub($stub) 15 0 15
25 }
26  
27 27 ▶sub execute {
Subroutine execute: called CC=5 SCAR=16.5
Pod undocumented
28 27 my ($self, $req) = @_;
29  
30 27 my $i = $self->{count}++;
31 27 ▶ my $stub = $self->{stubs}->[$i] || $self->{stubs}->[-1] || return;
Condition60%3/5
$self->{'stubs'}[$i] || $self->{'stubs'}[-1] || (return)
l!l
270
$self->{"stubs"}[$i] or $self->{"stubs"}[-1]
l!l&&r!l&&!r
15120
MC/DC0%0/2
$self->{'stubs'}[$i] || $self->{'stubs'}[-1] || (return)
$self->{"stubs"}[$i] $self->{"stubs"}[-1]
Truth table66%2/3
A or B
A= $self->{"stubs"}[$i]B= $self->{"stubs"}[-1]
ABresult
1X1
011
000
32  
33 27 ▶ if ($self->is_http_res($stub)) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->is_http_res($stub)) { } 24 3 27
elsif (ref $stub eq 'CODE') { } 3 0 3
34 24 return $stub;
35 }
36 elsif (ref($stub) eq 'CODE') {
37 3 return $stub->($req);
38 }
39 }
40  
41 7 1;
↑ Summary Conditional.pm »