| 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')
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')
| |||||||||||||||||||||||||
| 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'
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'
| |||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||
| 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)
$self->{"stubs"}[$i] or $self->{"stubs"}[-1]
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]
| |||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||
| 33 | 27 | ▶ | if ($self->is_http_res($stub)) { | ||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||
| 34 | 24 | return $stub; | |||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||
| 36 | elsif (ref($stub) eq 'CODE') { | ||||||||||||||||||||||||
| 37 | 3 | return $stub->($req); | |||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||
| 41 | 7 | 1; | |||||||||||||||||||||||