line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Double::Mock; |
2
|
|
|
|
|
|
|
|
3
|
9
|
|
|
9
|
|
45
|
use strict; |
|
9
|
|
|
|
|
16
|
|
|
9
|
|
|
|
|
262
|
|
4
|
9
|
|
|
9
|
|
112
|
use warnings; |
|
9
|
|
|
|
|
15
|
|
|
9
|
|
|
|
|
275
|
|
5
|
9
|
|
|
9
|
|
43
|
use Class::Monadic qw(monadic); |
|
9
|
|
|
|
|
14
|
|
|
9
|
|
|
|
|
515
|
|
6
|
9
|
|
|
9
|
|
43
|
use Scalar::Util qw(weaken); |
|
9
|
|
|
|
|
17
|
|
|
9
|
|
|
|
|
933
|
|
7
|
9
|
|
|
9
|
|
4943
|
use Test::Double::Mock::Expectation; |
|
9
|
|
|
|
|
31
|
|
|
9
|
|
|
|
|
3473
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
{ |
10
|
|
|
|
|
|
|
my %MOCKS = (); |
11
|
|
|
|
|
|
|
sub wrap { |
12
|
32
|
|
|
32
|
0
|
69
|
my ($class, $instance) = @_; |
13
|
32
|
|
66
|
|
|
300
|
$MOCKS{$instance} ||= $class->new( |
14
|
|
|
|
|
|
|
package => ref($instance), |
15
|
|
|
|
|
|
|
instance => $instance, |
16
|
|
|
|
|
|
|
); |
17
|
32
|
|
|
|
|
112
|
weaken($instance); |
18
|
32
|
|
|
|
|
159
|
return $MOCKS{$instance}; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub reset_all { |
22
|
15
|
|
|
15
|
0
|
251
|
%MOCKS = (); |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub verify_result_all { |
26
|
8
|
|
|
8
|
0
|
19
|
my $all_result; |
27
|
8
|
|
|
|
|
21
|
for my $instance (values %MOCKS) { |
28
|
9
|
|
|
|
|
15
|
for (@{$instance->{expectations}}) { |
|
9
|
|
|
|
|
23
|
|
29
|
10
|
|
|
|
|
39
|
my $result = $_->verify_result; |
30
|
10
|
|
|
|
|
41
|
$all_result->{$_->{method}} = $result; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
} |
33
|
8
|
|
|
|
|
25
|
return $all_result; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub verify_all { |
37
|
15
|
|
|
15
|
0
|
40
|
for my $instance (values %MOCKS) { |
38
|
21
|
|
|
|
|
2115
|
$_->verify for @{$instance->{expectations}}; |
|
21
|
|
|
|
|
109
|
|
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub new { |
44
|
31
|
|
|
31
|
0
|
102
|
my ($class, %args) = @_; |
45
|
31
|
|
|
|
|
256
|
bless { %args, expectations => [] }, $class; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub expects { |
49
|
32
|
|
|
32
|
1
|
52
|
my ($self, $method) = @_; |
50
|
|
|
|
|
|
|
|
51
|
32
|
|
|
|
|
180
|
my $expectation = Test::Double::Mock::Expectation->new( |
52
|
|
|
|
|
|
|
package => $self->{package}, |
53
|
|
|
|
|
|
|
method => $method, |
54
|
|
|
|
|
|
|
); |
55
|
|
|
|
|
|
|
|
56
|
32
|
|
|
|
|
136
|
monadic($self->{instance})->add_methods($method => $expectation->behavior); |
57
|
32
|
|
|
|
|
522
|
push @{ $self->{expectations} }, $expectation; |
|
32
|
|
|
|
|
78
|
|
58
|
|
|
|
|
|
|
|
59
|
32
|
|
|
|
|
173
|
return $expectation; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
1; |
63
|
|
|
|
|
|
|
__END__ |