| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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/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)
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | if $self->SUPER::isa($name); | ||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | return !!1 | ||||||||||||||||||||||||||||||||||||||||||
| 33 | 2 | ▶ | if $self->{__base} && $self->{__base}->isa($name); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"__base"} and $self->{"__base"}->isa($name)
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)
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
$self->{"__base"} and $self->{"__base"}->DOES($name)
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)
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | # note: immediate return not to force any context | ||||||||||||||||||||||||||||||||||||||||||
| 57 | 37 | ▶ | if ($method->isa('Test::Spy::Method')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
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)
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | if $interface eq 'strict'; | ||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 2 | ▶ | carp "method '$1' was called on Test::Spy->object" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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 | |||||||||||||||||||||||||||||||||||||||||||