Spy/Object.pm

filter: Statementstmt 98.1% 53 / 54 Branchbran 89.2% 25 / 28 Conditioncond 83.3% 15 / 18 MC/DCmcdc 72.7% 8 / 11 Subroutinesub 84.6% 11 / 13 Podpod 0.0% 0 / 4 totaltotal 87.5% 112 / 128 CC 22 SCAR 14.3
CC
22
Cov
93%
AUTOLOAD
7.0
can
5.0
__imitates
5.0
CRAP 4.2
↑ Summary Spy.pm »
1 package Test::Spy::Object;
2 7 $Test::Spy::Object::VERSION = '0.005';
3 7 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 7 ▶use Carp qw(croak carp);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 7 our $AUTOLOAD;
10  
11 sub can
12 6 ▶{
Subroutine can: called CC=5 SCAR=16.2
Pod undocumented
13 6 my ($self, $name) = @_;
14  
15 6 my $could = $self->SUPER::can($name);
16 6 ▶ return $could if $could;
Branch: 1 branch
BranchTrueFalseTotal
if $could 0 6 6
17  
18 return undef
19 unless $self->{__spy}->_mocked_subs->{$name}
20 6 ▶ || ($self->{__base} && $self->{__base}->can($name));
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"__spy"}->_mocked_subs->{$name} or $self->{"__base"} and $self->{"__base"}->can($name) 3 3 6
Condition100%6/6
$self->{"__spy"}->_mocked_subs->{$name} or $self->{"__base"} and $self->{"__base"}->can($name)
l!l&&r!l&&!r
213
$self->{"__base"} and $self->{"__base"}->can($name)
!ll&&!rl&&r
121
MC/DC100%3/3
$self->{"__spy"}->_mocked_subs->{$name} or $self->{"__base"} and $self->{"__base"}->can($name)
$self->{"__spy"}->_mocked_subs->{$name} $self->{"__base"} $self->{"__base"}->can($name)
Truth table100%4/4
A or B and C
A= $self->{"__spy"}->_mocked_subs->{$name}B= $self->{"__base"}C= $self->{"__base"}->can($name)
ABCresult
1XX1
0111
00X0
0100
21  
22 0 ▶ return sub { shift->$name(@_) };
Subroutine __ANON__: not called CC=1 SCAR=1.2
23 }
24  
25 sub isa
26 5 ▶{
Subroutine isa: called CC=4 SCAR=13.9
Pod undocumented
27 5 my ($self, $name) = @_;
28  
29 5 ▶ return !!1
Branch: 1 branch
BranchTrueFalseTotal
if $self->SUPER::isa($name) 0 5 5
30 if $self->SUPER::isa($name);
31  
32 return !!1
33 5 ▶ if $self->{__base} && $self->{__base}->isa($name);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"__base"} and $self->{"__base"}->isa($name) 1 4 5
Condition100%3/3
$self->{"__base"} and $self->{"__base"}->isa($name)
!ll&&!rl&&r
311
MC/DC100%2/2
$self->{"__base"} and $self->{"__base"}->isa($name)
$self->{"__base"} $self->{"__base"}->isa($name)
Truth table100%3/3
A and B
A= $self->{"__base"}B= $self->{"__base"}->isa($name)
ABresult
0X0
100
111
34  
35 4 return $self->__imitates($name);
36 }
37  
38 sub does
39 3 ▶{
Subroutine does: called CC=3 SCAR=12.5
Pod undocumented
40 3 my ($self, $name) = @_;
41  
42 return !!1
43 3 ▶ if $self->{__base} && $self->{__base}->does($name);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"__base"} and $self->{"__base"}->does($name) 0 3 3
Condition33%1/3
$self->{"__base"} and $self->{"__base"}->does($name)
!ll&&!rl&&r
300
MC/DC0%0/2
$self->{"__base"} and $self->{"__base"}->does($name)
$self->{"__base"} $self->{"__base"}->does($name)
Truth table33%1/3
A and B
A= $self->{"__base"}B= $self->{"__base"}->does($name)
ABresult
0X0
100
111
44  
45 3 return $self->__imitates($name);
46 }
47  
48 sub DOES
49 5 ▶{
Subroutine DOES: called CC=3 SCAR=11.0
Pod undocumented
50 5 my ($self, $name) = @_;
51  
52 return !!1
53 5 ▶ if $self->{__base} && $self->{__base}->DOES($name);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"__base"} and $self->{"__base"}->DOES($name) 1 4 5
Condition100%3/3
$self->{"__base"} and $self->{"__base"}->DOES($name)
!ll&&!rl&&r
311
MC/DC100%2/2
$self->{"__base"} and $self->{"__base"}->DOES($name)
$self->{"__base"} $self->{"__base"}->DOES($name)
Truth table100%3/3
A and B
A= $self->{"__base"}B= $self->{"__base"}->DOES($name)
ABresult
0X0
100
111
54  
55 4 return $self->__imitates($name);
56 }
57  
58 sub AUTOLOAD
59 45 ▶{
Subroutine AUTOLOAD: called CC=7 SCAR=19.5
60 45 my ($self, @args) = @_;
61  
62 45 my $method = $AUTOLOAD;
63 45 $method =~ s/.*://;
64  
65 45 ▶ if (my $method = $self->{__spy}->_mocked_subs->{$method}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $method = $self->{"__spy"}->_mocked_subs->{$method}) 37 8 45
66 # note: immediate return not to force any context
67 37 ▶ if ($method->isa('Test::Spy::Method')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($method->isa('Test::Spy::Method')) { } 35 2 37
68 35 return $method->_called($self, @args);
69 }
70 else {
71 2 $method->_called($self, @args);
72 }
73 }
74  
75 10 ▶ if ($self->{__base} && (my $sref = $self->{__base}->can($method))) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"__base"} and my $sref = $self->{"__base"}->can($method)) 7 3 10
Condition66%2/3
$self->{"__base"} and my $sref = $self->{"__base"}->can($method)
!ll&&!rl&&r
307
MC/DC50%1/2
$self->{"__base"} and my $sref = $self->{"__base"}->can($method)
$self->{"__base"} my $sref = $self->{"__base"}->can($method)
Truth table66%2/3
A and B
A= $self->{"__base"}B= my $sref = $self->{"__base"}->can($method)
ABresult
0X0
100
111
76 7 return $sref->($self, @args);
77 }
78  
79 3 my $interface = $self->{__spy}->interface;
80  
81 3 ▶ croak "No such method $method on Test::Spy->object"
Branch: 1 branch
BranchTrueFalseTotal
if $interface eq "strict" 1 2 3
82 if $interface eq 'strict';
83  
84 2 ▶ carp "method '$1' was called on Test::Spy->object"
Branch: 1 branch
BranchTrueFalseTotal
if $interface eq "warn" 1 1 2
85 if $interface eq 'warn';
86  
87 1 return undef;
88 }
89  
90 sub __imitates
91 11 ▶{
Subroutine __imitates: called CC=5 SCAR=16.1
92 11 my ($self, $name) = @_;
93  
94 11 ▶ if ($self->{__spy}->has_imitates) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"__spy"}->has_imitates) 9 2 11
95 9 my @imitates = $self->{__spy}->imitates;
96 9 ▶ @imitates = @{$imitates[0]}
Branch: 1 branch
BranchTrueFalseTotal
if ref $imitates[0] eq "ARRAY" 6 3 9
97 if ref $imitates[0] eq 'ARRAY';
98  
99 9 foreach my $type (@imitates) {
100 12 ▶ return !!1 if $type eq $name;
Branch: 1 branch
BranchTrueFalseTotal
if $type eq $name 9 3 12
101 }
102 }
103  
104 2 return !!0;
105 }
106  
107 sub __new
108 25 ▶{
Subroutine __new: called CC=1 SCAR=0.0
109 25 my ($class, %params) = @_;
110 25 my $self = \%params;
111  
112 25 return bless $self, $class;
113 }
114  
115 sub DESTROY
116 0 ▶{
Subroutine DESTROY: not called CC=1 SCAR=0.0
117 }
118  
119 7 1;
120  
↑ Summary Spy.pm »