line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
$Test::Spy::VERSION = '0.005'; |
2
|
|
|
|
|
|
|
use v5.10; |
3
|
7
|
|
|
7
|
|
419126
|
use strict; |
|
7
|
|
|
|
|
79
|
|
4
|
7
|
|
|
7
|
|
47
|
use warnings; |
|
7
|
|
|
|
|
12
|
|
|
7
|
|
|
|
|
191
|
|
5
|
7
|
|
|
7
|
|
33
|
|
|
7
|
|
|
|
|
10
|
|
|
7
|
|
|
|
|
183
|
|
6
|
|
|
|
|
|
|
use Moo; |
7
|
7
|
|
|
7
|
|
3278
|
use Mooish::AttributeBuilder -standard; |
|
7
|
|
|
|
|
44860
|
|
|
7
|
|
|
|
|
31
|
|
8
|
7
|
|
|
7
|
|
11783
|
use Carp qw(croak); |
|
7
|
|
|
|
|
11091
|
|
|
7
|
|
|
|
|
43
|
|
9
|
7
|
|
|
7
|
|
788
|
|
|
7
|
|
|
|
|
14
|
|
|
7
|
|
|
|
|
283
|
|
10
|
|
|
|
|
|
|
use Test::Spy::Method; |
11
|
7
|
|
|
7
|
|
2602
|
use Test::Spy::Observer; |
|
7
|
|
|
|
|
21
|
|
|
7
|
|
|
|
|
233
|
|
12
|
7
|
|
|
7
|
|
42
|
use Test::Spy::Object; |
|
7
|
|
|
|
|
10
|
|
|
7
|
|
|
|
|
141
|
|
13
|
7
|
|
|
7
|
|
2712
|
|
|
7
|
|
|
|
|
16
|
|
|
7
|
|
|
|
|
4525
|
|
14
|
|
|
|
|
|
|
has param 'interface' => ( |
15
|
|
|
|
|
|
|
isa => sub { |
16
|
|
|
|
|
|
|
my @allowed = qw(strict lax warn); |
17
|
|
|
|
|
|
|
croak "interface can be any of: @allowed" |
18
|
|
|
|
|
|
|
unless grep { $_[0] eq $_ } @allowed; |
19
|
|
|
|
|
|
|
}, |
20
|
|
|
|
|
|
|
default => sub { 'strict' } |
21
|
|
|
|
|
|
|
); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
has field '_mocked_subs' => ( |
24
|
|
|
|
|
|
|
default => sub { {} }, |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
has field 'object' => ( |
28
|
|
|
|
|
|
|
lazy => 1, |
29
|
|
|
|
|
|
|
clearer => -hidden |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
has option 'context' => ( |
33
|
|
|
|
|
|
|
writer => 1, |
34
|
|
|
|
|
|
|
clearer => 1, |
35
|
|
|
|
|
|
|
); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
has option 'base' => ( |
38
|
|
|
|
|
|
|
writer => 1, |
39
|
|
|
|
|
|
|
trigger => '_clear_object', |
40
|
|
|
|
|
|
|
); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
has option 'imitates' => ( |
43
|
|
|
|
|
|
|
writer => 1, |
44
|
|
|
|
|
|
|
trigger => '_clear_object', |
45
|
|
|
|
|
|
|
); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
with qw(Test::Spy::Interface); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
{ |
50
|
|
|
|
|
|
|
my ($self, $method_name) = @_; |
51
|
|
|
|
|
|
|
|
52
|
1
|
|
|
1
|
|
3
|
croak "method $method_name was not mocked!"; |
53
|
|
|
|
|
|
|
} |
54
|
1
|
|
|
|
|
123
|
|
55
|
|
|
|
|
|
|
{ |
56
|
|
|
|
|
|
|
my ($self) = @_; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
my %methods = %{$self->_mocked_subs}; |
59
|
25
|
|
|
25
|
|
2913
|
my %init_hash; |
60
|
|
|
|
|
|
|
|
61
|
25
|
|
|
|
|
39
|
my $base = $self->has_base |
|
25
|
|
|
|
|
114
|
|
62
|
25
|
|
|
|
|
44
|
? ref $self->base ? $self->base : $self->base->new |
63
|
|
|
|
|
|
|
: undef; |
64
|
25
|
100
|
|
|
|
94
|
|
|
|
100
|
|
|
|
|
|
65
|
|
|
|
|
|
|
return Test::Spy::Object->__new( |
66
|
|
|
|
|
|
|
%{$base // {}}, |
67
|
|
|
|
|
|
|
__base => $base, |
68
|
|
|
|
|
|
|
__spy => $self, |
69
|
25
|
|
100
|
|
|
43
|
); |
|
25
|
|
|
|
|
200
|
|
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
{ |
73
|
|
|
|
|
|
|
my ($self, $method_name, @returns) = @_; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
my $method = $self->_mocked_subs->{$method_name} = Test::Spy::Method->new(method_name => $method_name); |
76
|
|
|
|
|
|
|
|
77
|
20
|
|
|
20
|
1
|
707
|
if (@returns) { |
78
|
|
|
|
|
|
|
$method->should_return(@returns); |
79
|
20
|
|
|
|
|
256
|
} |
80
|
|
|
|
|
|
|
|
81
|
20
|
100
|
|
|
|
6734
|
return $method; |
82
|
5
|
|
|
|
|
25
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
{ |
85
|
20
|
|
|
|
|
67
|
my ($self, $method_name) = @_; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
return $self->_mocked_subs->{$method_name} = Test::Spy::Observer->new(method_name => $method_name); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
1
|
|
|
1
|
1
|
10
|
{ |
91
|
|
|
|
|
|
|
my ($self, $method_name) = @_; |
92
|
1
|
|
|
|
|
7
|
|
93
|
|
|
|
|
|
|
return $self->_mocked_subs->{$method_name} |
94
|
|
|
|
|
|
|
// $self->_no_method($method_name); |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
3
|
|
|
3
|
1
|
17
|
{ |
98
|
|
|
|
|
|
|
my ($self) = @_; |
99
|
3
|
|
66
|
|
|
24
|
|
100
|
|
|
|
|
|
|
$self->clear_context; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
my %methods = %{$self->_mocked_subs}; |
103
|
|
|
|
|
|
|
for my $method_name (keys %methods) { |
104
|
|
|
|
|
|
|
$methods{$method_name}->clear; |
105
|
1
|
|
|
1
|
1
|
9
|
} |
106
|
|
|
|
|
|
|
|
107
|
1
|
|
|
|
|
18
|
return; |
108
|
|
|
|
|
|
|
} |
109
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
5
|
|
110
|
1
|
|
|
|
|
4
|
{ |
111
|
2
|
|
|
|
|
8
|
my ($self) = @_; |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
my $context = $self->context; |
114
|
1
|
|
|
|
|
3
|
croak 'no context was set in ' . ref $self |
115
|
|
|
|
|
|
|
unless $self->has_context && $context; |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
return $self->_mocked_subs->{$context}->call_history |
118
|
|
|
|
|
|
|
// $self->_no_method($context); |
119
|
7
|
|
|
7
|
1
|
22
|
} |
120
|
|
|
|
|
|
|
|
121
|
7
|
|
|
|
|
17
|
{ |
122
|
7
|
100
|
66
|
|
|
187
|
my ($self) = @_; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
return $self->_mocked_subs->{$self->context}->_clear_call_history; |
125
|
6
|
|
33
|
|
|
122
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
1; |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
# ABSTRACT: build mocked interfaces and examine call data easily |
130
|
|
|
|
|
|
|
|