| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | return undef | ||||||||||||||||||||||||||||||||||||||||||
| 19 | unless $self->{__spy}->_mocked_subs->{$name} | ||||||||||||||||||||||||||||||||||||||||||
| 20 | 6 | ▶ | || ($self->{__base} && $self->{__base}->can($name)); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$self->{"__spy"}->_mocked_subs->{$name} or $self->{"__base"} and $self->{"__base"}->can($name)
$self->{"__base"} and $self->{"__base"}->can($name)
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)
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | if $self->SUPER::isa($name); | ||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | return !!1 | ||||||||||||||||||||||||||||||||||||||||||
| 33 | 5 | ▶ | if $self->{__base} && $self->{__base}->isa($name); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->{"__base"} and $self->{"__base"}->isa($name)
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)
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
$self->{"__base"} and $self->{"__base"}->does($name)
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)
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
$self->{"__base"} and $self->{"__base"}->DOES($name)
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)
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | # note: immediate return not to force any context | ||||||||||||||||||||||||||||||||||||||||||
| 67 | 37 | ▶ | if ($method->isa('Test::Spy::Method')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
$self->{"__base"} and my $sref = $self->{"__base"}->can($method)
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)
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | if $interface eq 'strict'; | ||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | 2 | ▶ | carp "method '$1' was called on Test::Spy->object" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | 9 | my @imitates = $self->{__spy}->imitates; | |||||||||||||||||||||||||||||||||||||||||
| 96 | 9 | ▶ | @imitates = @{$imitates[0]} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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 | |||||||||||||||||||||||||||||||||||||||||||