line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
$Test::Spy::VERSION = '0.004'; |
2
|
|
|
|
|
|
|
use v5.10; |
3
|
6
|
|
|
6
|
|
404755
|
use strict; |
|
6
|
|
|
|
|
72
|
|
4
|
6
|
|
|
6
|
|
46
|
use warnings; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
179
|
|
5
|
6
|
|
|
6
|
|
30
|
|
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
165
|
|
6
|
|
|
|
|
|
|
use Moo; |
7
|
6
|
|
|
6
|
|
3211
|
use Mooish::AttributeBuilder -standard; |
|
6
|
|
|
|
|
42765
|
|
|
6
|
|
|
|
|
29
|
|
8
|
6
|
|
|
6
|
|
11436
|
use Carp qw(croak); |
|
6
|
|
|
|
|
9893
|
|
|
6
|
|
|
|
|
54
|
|
9
|
6
|
|
|
6
|
|
555
|
|
|
6
|
|
|
|
|
19
|
|
|
6
|
|
|
|
|
256
|
|
10
|
|
|
|
|
|
|
use Test::Spy::Method; |
11
|
6
|
|
|
6
|
|
2723
|
use Test::Spy::Observer; |
|
6
|
|
|
|
|
21
|
|
|
6
|
|
|
|
|
227
|
|
12
|
6
|
|
|
6
|
|
38
|
use Test::Spy::Object; |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
136
|
|
13
|
6
|
|
|
6
|
|
2567
|
|
|
6
|
|
|
|
|
15
|
|
|
6
|
|
|
|
|
4676
|
|
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
|
|
|
|
|
|
|
with qw(Test::Spy::Interface); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
{ |
45
|
|
|
|
|
|
|
my ($self, $method_name) = @_; |
46
|
|
|
|
|
|
|
|
47
|
1
|
|
|
1
|
|
4
|
croak "method $method_name was not mocked!"; |
48
|
|
|
|
|
|
|
} |
49
|
1
|
|
|
|
|
196
|
|
50
|
|
|
|
|
|
|
{ |
51
|
|
|
|
|
|
|
my ($self) = @_; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
my %methods = %{$self->_mocked_subs}; |
54
|
23
|
|
|
23
|
|
3526
|
my %init_hash; |
55
|
|
|
|
|
|
|
|
56
|
23
|
|
|
|
|
35
|
my $base = $self->has_base |
|
23
|
|
|
|
|
106
|
|
57
|
23
|
|
|
|
|
52
|
? ref $self->base ? $self->base : $self->base->new |
58
|
|
|
|
|
|
|
: undef; |
59
|
23
|
100
|
|
|
|
110
|
|
|
|
100
|
|
|
|
|
|
60
|
|
|
|
|
|
|
return Test::Spy::Object->_new( |
61
|
|
|
|
|
|
|
%{$base // {}}, |
62
|
|
|
|
|
|
|
__base => $base, |
63
|
|
|
|
|
|
|
__spy => $self, |
64
|
23
|
|
100
|
|
|
42
|
); |
|
23
|
|
|
|
|
201
|
|
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
{ |
68
|
|
|
|
|
|
|
my ($self, $method_name, @returns) = @_; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
my $method = $self->_mocked_subs->{$method_name} = Test::Spy::Method->new(method_name => $method_name); |
71
|
|
|
|
|
|
|
|
72
|
20
|
|
|
20
|
1
|
847
|
if (@returns) { |
73
|
|
|
|
|
|
|
$method->should_return(@returns); |
74
|
20
|
|
|
|
|
270
|
} |
75
|
|
|
|
|
|
|
|
76
|
20
|
100
|
|
|
|
8884
|
return $method; |
77
|
5
|
|
|
|
|
22
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
{ |
80
|
20
|
|
|
|
|
88
|
my ($self, $method_name) = @_; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
return $self->_mocked_subs->{$method_name} = Test::Spy::Observer->new(method_name => $method_name); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
1
|
|
|
1
|
1
|
14
|
{ |
86
|
|
|
|
|
|
|
my ($self, $method_name) = @_; |
87
|
1
|
|
|
|
|
8
|
|
88
|
|
|
|
|
|
|
return $self->_mocked_subs->{$method_name} |
89
|
|
|
|
|
|
|
// $self->_no_method($method_name); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
3
|
|
|
3
|
1
|
19
|
{ |
93
|
|
|
|
|
|
|
my ($self) = @_; |
94
|
3
|
|
66
|
|
|
29
|
|
95
|
|
|
|
|
|
|
$self->clear_context; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
my %methods = %{$self->_mocked_subs}; |
98
|
|
|
|
|
|
|
for my $method_name (keys %methods) { |
99
|
|
|
|
|
|
|
$methods{$method_name}->clear; |
100
|
1
|
|
|
1
|
1
|
10
|
} |
101
|
|
|
|
|
|
|
|
102
|
1
|
|
|
|
|
19
|
return; |
103
|
|
|
|
|
|
|
} |
104
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
5
|
|
105
|
1
|
|
|
|
|
4
|
{ |
106
|
2
|
|
|
|
|
10
|
my ($self) = @_; |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
my $context = $self->context; |
109
|
1
|
|
|
|
|
5
|
croak 'no context was set in ' . ref $self |
110
|
|
|
|
|
|
|
unless $self->has_context && $context; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
return $self->_mocked_subs->{$context}->call_history |
113
|
|
|
|
|
|
|
// $self->_no_method($context); |
114
|
7
|
|
|
7
|
1
|
26
|
} |
115
|
|
|
|
|
|
|
|
116
|
7
|
|
|
|
|
19
|
{ |
117
|
7
|
100
|
66
|
|
|
204
|
my ($self) = @_; |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
return $self->_mocked_subs->{$self->context}->_clear_call_history; |
120
|
6
|
|
33
|
|
|
132
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
1; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
# ABSTRACT: build mocked interfaces and examine call data easily |
125
|
|
|
|
|
|
|
|