Spy/Object.pm

filter: Statementstmt 97.6% 42 / 43 Branchbran 90.0% 18 / 20 Conditioncond 80.0% 12 / 15 MC/DCmcdc 55.5% 5 / 9 Subroutinesub 81.8% 9 / 11 Podpod 0.0% 0 / 3 totaltotal 85.1% 86 / 101 SCAR 27.8
CC
16
Cov
92%
AUTOLOAD
7.0
can
5.0
isa
4.1
CRAP 16.1
↑ Summary Spy.pm »
1 package Test::Spy::Object;
2 6 $Test::Spy::Object::VERSION = '0.004';
3 6 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 6 ▶use Carp qw(croak carp);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 6 our $AUTOLOAD;
10  
11 sub can
12 {
13 6 ▶ my ($self, $name) = @_;
Subroutine can: called CC=5 SCAR=16.2
Pod undocumented
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/DC66%2/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 table75%3/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 3 ▶ return sub { shift->$name(@_) };
Subroutine __ANON__: not called CC=1 SCAR=1.2
23 }
24  
25 sub isa
26 {
27 2 ▶ my ($self, $name) = @_;
Subroutine isa: called CC=4 SCAR=14.1
Pod undocumented
28  
29 2 ▶ return !!1
Branch: 1 branch
BranchTrueFalseTotal
if $self->SUPER::isa($name) 0 2 2
30 if $self->SUPER::isa($name);
31  
32 return !!1
33 2 ▶ if $self->{__base} && $self->{__base}->isa($name);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"__base"} and $self->{"__base"}->isa($name) 1 1 2
Condition66%2/3
$self->{"__base"} and $self->{"__base"}->isa($name)
!ll&&!rl&&r
011
MC/DC50%1/2
$self->{"__base"} and $self->{"__base"}->isa($name)
$self->{"__base"} $self->{"__base"}->isa($name)
Truth table66%2/3
A and B
A= $self->{"__base"}B= $self->{"__base"}->isa($name)
ABresult
0X0
100
111
34  
35 1 return !!0;
36 }
37  
38 sub DOES
39 {
40 2 ▶ my ($self, $name) = @_;
Subroutine DOES: called CC=3 SCAR=11.0
Pod undocumented
41  
42 return !!1
43 2 ▶ if $self->{__base} && $self->{__base}->DOES($name);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"__base"} and $self->{"__base"}->DOES($name) 1 1 2
Condition66%2/3
$self->{"__base"} and $self->{"__base"}->DOES($name)
!ll&&!rl&&r
011
MC/DC50%1/2
$self->{"__base"} and $self->{"__base"}->DOES($name)
$self->{"__base"} $self->{"__base"}->DOES($name)
Truth table66%2/3
A and B
A= $self->{"__base"}B= $self->{"__base"}->DOES($name)
ABresult
0X0
100
111
44  
45 1 return !!0;
46 }
47  
48 sub AUTOLOAD
49 {
50 45 ▶ my ($self, @args) = @_;
Subroutine AUTOLOAD: called CC=7 SCAR=19.5
51  
52 45 my $method = $AUTOLOAD;
53 45 $method =~ s/.*://;
54  
55 45 ▶ if (my $method = $self->{__spy}->_mocked_subs->{$method}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $method = $self->{"__spy"}->_mocked_subs->{$method}) 37 8 45
56 # note: immediate return not to force any context
57 37 ▶ if ($method->isa('Test::Spy::Method')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($method->isa('Test::Spy::Method')) { } 35 2 37
58 35 return $method->_called($self, @args);
59 }
60 else {
61 2 $method->_called($self, @args);
62 }
63 }
64  
65 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
66 7 return $sref->($self, @args);
67 }
68  
69 3 my $interface = $self->{__spy}->interface;
70  
71 3 ▶ croak "No such method $method on Test::Spy->object"
Branch: 1 branch
BranchTrueFalseTotal
if $interface eq "strict" 1 2 3
72 if $interface eq 'strict';
73  
74 2 ▶ carp "method '$1' was called on Test::Spy->object"
Branch: 1 branch
BranchTrueFalseTotal
if $interface eq "warn" 1 1 2
75 if $interface eq 'warn';
76  
77 1 return undef;
78 }
79  
80 sub _new
81 {
82 23 ▶ my ($class, %params) = @_;
Subroutine _new: called CC=1 SCAR=0.0
83 23 my $self = \%params;
84  
85 23 return bless $self, $class;
86 }
87  
88 sub DESTROY
89 ▶{
Subroutine DESTROY: not called CC=1 SCAR=0.0
90 }
91  
92 6 1;
93  
↑ Summary Spy.pm »