line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
$Test::Spy::VERSION = '0.003'; |
2
|
|
|
|
|
|
|
use v5.10; |
3
|
6
|
|
|
6
|
|
413315
|
use strict; |
|
6
|
|
|
|
|
67
|
|
4
|
6
|
|
|
6
|
|
51
|
use warnings; |
|
6
|
|
|
|
|
9
|
|
|
6
|
|
|
|
|
217
|
|
5
|
6
|
|
|
6
|
|
34
|
|
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
173
|
|
6
|
|
|
|
|
|
|
use Moo; |
7
|
6
|
|
|
6
|
|
3419
|
use Mooish::AttributeBuilder; |
|
6
|
|
|
|
|
44666
|
|
|
6
|
|
|
|
|
28
|
|
8
|
6
|
|
|
6
|
|
11453
|
use Carp qw(croak); |
|
6
|
|
|
|
|
7762
|
|
|
6
|
|
|
|
|
384
|
|
9
|
6
|
|
|
6
|
|
79
|
|
|
6
|
|
|
|
|
14
|
|
|
6
|
|
|
|
|
254
|
|
10
|
|
|
|
|
|
|
use Test::Spy::Method; |
11
|
6
|
|
|
6
|
|
2492
|
use Test::Spy::Observer; |
|
6
|
|
|
|
|
20
|
|
|
6
|
|
|
|
|
201
|
|
12
|
6
|
|
|
6
|
|
40
|
use Test::Spy::Object; |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
134
|
|
13
|
6
|
|
|
6
|
|
2584
|
|
|
6
|
|
|
|
|
16
|
|
|
6
|
|
|
|
|
4476
|
|
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
|
|
2
|
croak "method $method_name was not mocked!"; |
48
|
|
|
|
|
|
|
} |
49
|
1
|
|
|
|
|
153
|
|
50
|
|
|
|
|
|
|
{ |
51
|
|
|
|
|
|
|
my ($self) = @_; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
my %methods = %{$self->_mocked_subs}; |
54
|
23
|
|
|
23
|
|
3544
|
my %init_hash; |
55
|
|
|
|
|
|
|
|
56
|
23
|
|
|
|
|
37
|
my $base = $self->has_base |
|
23
|
|
|
|
|
102
|
|
57
|
23
|
|
|
|
|
42
|
? ref $self->base ? $self->base : $self->base->new |
58
|
|
|
|
|
|
|
: undef; |
59
|
23
|
100
|
|
|
|
116
|
|
|
|
100
|
|
|
|
|
|
60
|
|
|
|
|
|
|
return Test::Spy::Object->_new( |
61
|
|
|
|
|
|
|
%{$base // {}}, |
62
|
|
|
|
|
|
|
__base => $base, |
63
|
|
|
|
|
|
|
__spy => $self, |
64
|
23
|
|
100
|
|
|
40
|
); |
|
23
|
|
|
|
|
178
|
|
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
|
917
|
if (@returns) { |
73
|
|
|
|
|
|
|
$method->should_return(@returns); |
74
|
20
|
|
|
|
|
283
|
} |
75
|
|
|
|
|
|
|
|
76
|
20
|
100
|
|
|
|
7645
|
return $method; |
77
|
5
|
|
|
|
|
18
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
{ |
80
|
20
|
|
|
|
|
72
|
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
|
17
|
{ |
86
|
|
|
|
|
|
|
my ($self, $method_name) = @_; |
87
|
1
|
|
|
|
|
6
|
|
88
|
|
|
|
|
|
|
return $self->_mocked_subs->{$method_name} |
89
|
|
|
|
|
|
|
// $self->_no_method($method_name); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
3
|
|
|
3
|
1
|
20
|
{ |
93
|
|
|
|
|
|
|
my ($self) = @_; |
94
|
3
|
|
66
|
|
|
36
|
|
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
|
14
|
} |
101
|
|
|
|
|
|
|
|
102
|
1
|
|
|
|
|
18
|
return; |
103
|
|
|
|
|
|
|
} |
104
|
1
|
|
|
|
|
12
|
|
|
1
|
|
|
|
|
6
|
|
105
|
1
|
|
|
|
|
5
|
{ |
106
|
2
|
|
|
|
|
8
|
my ($self) = @_; |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
my $context = $self->context; |
109
|
1
|
|
|
|
|
4
|
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
|
|
|
|
|
16
|
{ |
117
|
7
|
100
|
66
|
|
|
208
|
my ($self) = @_; |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
return $self->_mocked_subs->{$self->context}->_clear_call_history; |
120
|
6
|
|
33
|
|
|
141
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
1; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
# ABSTRACT: build mocked interfaces and examine call data easily |
125
|
|
|
|
|
|
|
|