Spy/Interface.pm

filter: Statementstmt 100% 48 / 48 Branchbran 100% 4 / 4 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 16 / 16 Podpod 0.0% 0 / 9 totaltotal 86.2% 69 / 80 SCAR 13.9
CC
4
Cov
98%
_increment_call_iterator
2.0
next_called_with
2.0
was_called
2.0
CRAP 4.0
« Spy/Method.pm ↑ Summary Spy/Observer.pm »
1 package Test::Spy::Interface;
2 6 $Test::Spy::Interface::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::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 6 ▶use Mooish::AttributeBuilder -standard;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 6 requires qw(
11 call_history
12 _clear_call_history
13 );
14  
15 has field '_call_iterator' => (
16 writer => 1,
17 clearer => 1,
18 predicate => 1,
19 5 ▶ lazy => sub { 0 },
Subroutine __ANON__: called CC=1 SCAR=0.0
20 6 );
21  
22 sub _increment_call_iterator
23 {
24 7 ▶ my ($self, $count) = @_;
Subroutine _increment_call_iterator: called CC=2 SCAR=7.0
25 7 ▶ $count //= 1;
Condition50%1/2
$count //= 1
l!l
07
MC/DC0%0/1
$count //= 1
$count
Truth table50%1/2
A
A= $count
Aresult
11
00
26  
27 7 $self->_set_call_iterator($self->_call_iterator + $count);
28  
29 7 return;
30 }
31  
32 sub called_times
33 {
34 26 ▶ my ($self) = @_;
Subroutine called_times: called CC=1 SCAR=0.0
Pod undocumented
35  
36 26 return scalar @{$self->call_history};
37 }
38  
39 sub called_with
40 {
41 16 ▶ my ($self) = @_;
Subroutine called_with: called CC=1 SCAR=0.0
Pod undocumented
42  
43 16 return $self->call_history->[$self->_call_iterator];
44 }
45  
46 sub first_called_with
47 {
48 1 ▶ my ($self) = @_;
Subroutine first_called_with: called CC=1 SCAR=0.0
Pod undocumented
49  
50 1 $self->_set_call_iterator(0);
51 1 return $self->called_with;
52 }
53  
54 sub next_called_with
55 {
56 9 ▶ my ($self) = @_;
Subroutine next_called_with: called CC=2 SCAR=6.9
Pod undocumented
57  
58 9 ▶ $self->_increment_call_iterator
Branch: 1 branch
BranchTrueFalseTotal
if $self->_has_call_iterator 7 2 9
59 if $self->_has_call_iterator;
60  
61 9 return $self->called_with;
62 }
63  
64 sub last_called_with
65 {
66 2 ▶ my ($self) = @_;
Subroutine last_called_with: called CC=1 SCAR=0.0
Pod undocumented
67  
68 2 $self->_set_call_iterator($self->called_times - 1);
69 2 return $self->called_with;
70 }
71  
72 sub was_called
73 {
74 22 ▶ my ($self, $times) = @_;
Subroutine was_called: called CC=2 SCAR=6.9
Pod undocumented
75  
76 22 ▶ return $self->called_times == $times if defined $times;
Branch: 1 branch
BranchTrueFalseTotal
if defined $times 19 3 22
77 3 return $self->called_times > 0;
78 }
79  
80 sub wasnt_called
81 {
82 3 ▶ my ($self) = @_;
Subroutine wasnt_called: called CC=1 SCAR=0.0
Pod undocumented
83  
84 3 return $self->was_called(0);
85 }
86  
87 sub was_called_once
88 {
89 5 ▶ my ($self) = @_;
Subroutine was_called_once: called CC=1 SCAR=0.0
Pod undocumented
90  
91 5 return $self->was_called(1);
92 }
93  
94 sub clear
95 {
96 14 ▶ my ($self) = @_;
Subroutine clear: called CC=1 SCAR=0.0
Pod undocumented
97  
98 14 $self->_clear_call_history;
99 14 $self->_clear_call_iterator;
100  
101 14 return $self;
102 }
103  
104 6 1;
105  
« Spy/Method.pm ↑ Summary Spy/Observer.pm »