| 1 | package Test::Spy::Method; | ||||||||||
| 2 | 6 | $Test::Spy::Method::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 Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 6 | ▶ | use Mooish::AttributeBuilder -standard; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 6 | ▶ | use Carp qw(croak); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 6 | has field '_throws' => ( | |||||||||
| 12 | writer => 1, | ||||||||||
| 13 | clearer => 1, | ||||||||||
| 14 | ); | ||||||||||
| 15 | |||||||||||
| 16 | 6 | has field '_calls' => ( | |||||||||
| 17 | writer => 1, | ||||||||||
| 18 | clearer => 1, | ||||||||||
| 19 | ); | ||||||||||
| 20 | |||||||||||
| 21 | 6 | has field '_returns' => ( | |||||||||
| 22 | writer => 1, | ||||||||||
| 23 | clearer => 1, | ||||||||||
| 24 | ); | ||||||||||
| 25 | |||||||||||
| 26 | 6 | has field '_returns_list' => ( | |||||||||
| 27 | writer => 1, | ||||||||||
| 28 | clearer => 1, | ||||||||||
| 29 | ); | ||||||||||
| 30 | |||||||||||
| 31 | 6 | extends 'Test::Spy::Observer'; | |||||||||
| 32 | |||||||||||
| 33 | sub _forget | ||||||||||
| 34 | { | ||||||||||
| 35 | 9 | ▶ | my ($self) = @_; | ||||||||
|
Subroutine
_forget: called CC=1 SCAR=0.0
| |||||||||||
| 36 | |||||||||||
| 37 | 9 | $self->_clear_returns; | |||||||||
| 38 | 9 | $self->_clear_returns_list; | |||||||||
| 39 | 9 | $self->_clear_calls; | |||||||||
| 40 | 9 | $self->_clear_throws; | |||||||||
| 41 | |||||||||||
| 42 | 9 | return; | |||||||||
| 43 | } | ||||||||||
| 44 | |||||||||||
| 45 | sub should_return | ||||||||||
| 46 | { | ||||||||||
| 47 | 7 | ▶ | my ($self, @values) = @_; | ||||||||
|
Subroutine
should_return: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 48 | |||||||||||
| 49 | 7 | $self->_forget; | |||||||||
| 50 | |||||||||||
| 51 | 7 | ▶ | if (@values == 1) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 52 | 5 | $self->_set_returns($values[0]); | |||||||||
| 53 | } | ||||||||||
| 54 | else { | ||||||||||
| 55 | 2 | $self->_set_returns_list([@values]); | |||||||||
| 56 | } | ||||||||||
| 57 | |||||||||||
| 58 | 7 | return $self->clear; | |||||||||
| 59 | } | ||||||||||
| 60 | |||||||||||
| 61 | sub should_call | ||||||||||
| 62 | { | ||||||||||
| 63 | 1 | ▶ | my ($self, $sub) = @_; | ||||||||
|
Subroutine
should_call: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||
| 64 | |||||||||||
| 65 | 1 | ▶ | croak 'should_call expects a coderef' | ||||||||
|
Branch: 1 branch
| |||||||||||
| 66 | unless ref $sub eq 'CODE'; | ||||||||||
| 67 | |||||||||||
| 68 | 1 | $self->_forget; | |||||||||
| 69 | |||||||||||
| 70 | 1 | $self->_set_calls($sub); | |||||||||
| 71 | |||||||||||
| 72 | 1 | return $self->clear; | |||||||||
| 73 | } | ||||||||||
| 74 | |||||||||||
| 75 | sub should_throw | ||||||||||
| 76 | { | ||||||||||
| 77 | 1 | ▶ | my ($self, $exception) = @_; | ||||||||
|
Subroutine
should_throw: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 78 | |||||||||||
| 79 | 1 | $self->_forget; | |||||||||
| 80 | |||||||||||
| 81 | 1 | $self->_set_throws($exception); | |||||||||
| 82 | |||||||||||
| 83 | 1 | return $self->clear; | |||||||||
| 84 | } | ||||||||||
| 85 | |||||||||||
| 86 | sub _called | ||||||||||
| 87 | { | ||||||||||
| 88 | 35 | ▶ | my ($self, $inner_self, @params) = @_; | ||||||||
|
Subroutine
_called: called CC=4 SCAR=13.9
| |||||||||||
| 89 | |||||||||||
| 90 | 35 | $self->SUPER::_called($inner_self, @params); | |||||||||
| 91 | |||||||||||
| 92 | 35 | ▶ | die $self->_throws | ||||||||
|
Branch: 1 branch
| |||||||||||
| 93 | if defined $self->_throws; | ||||||||||
| 94 | |||||||||||
| 95 | 34 | ▶ | return $self->_calls->($inner_self, @params) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 96 | if $self->_calls; | ||||||||||
| 97 | |||||||||||
| 98 | 33 | ▶ | return @{$self->_returns_list} | ||||||||
|
Branch: 1 branch
| |||||||||||
| 99 | if $self->_returns_list; | ||||||||||
| 100 | |||||||||||
| 101 | 31 | return $self->_returns; | |||||||||
| 102 | } | ||||||||||
| 103 | |||||||||||
| 104 | 6 | 1; | |||||||||
| 105 | |||||||||||