line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Mock::Signature; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
58292
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
129
|
|
4
|
3
|
|
|
3
|
|
15
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
84
|
|
5
|
|
|
|
|
|
|
|
6
|
3
|
|
|
3
|
|
2478
|
use Class::Load qw(load_class); |
|
3
|
|
|
|
|
113664
|
|
|
3
|
|
|
|
|
177
|
|
7
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
|
1599
|
use Test::Mock::Signature::Meta; |
|
3
|
|
|
|
|
11
|
|
|
3
|
|
|
|
|
330
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
11
|
|
|
|
|
|
|
our @EXPORT_OK = qw(any); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub any() { |
14
|
1
|
|
|
1
|
1
|
14
|
return $Data::PatternCompare::any; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
1
|
|
|
1
|
1
|
1
|
sub init { } |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub new { |
20
|
7
|
|
|
7
|
1
|
5067
|
my $class = shift; |
21
|
7
|
|
|
|
|
11
|
my $singleton = do { |
22
|
3
|
|
|
3
|
|
17
|
no strict 'refs'; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
262
|
|
23
|
7
|
|
|
|
|
44
|
${$class .'::singleton'} |
|
7
|
|
|
|
|
37
|
|
24
|
|
|
|
|
|
|
}; |
25
|
7
|
100
|
|
|
|
84
|
return $singleton if $singleton; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my $params = { |
28
|
3
|
|
|
|
|
8
|
_real_class => do { |
29
|
3
|
|
|
3
|
|
16
|
no strict 'refs'; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
186
|
|
30
|
3
|
|
|
|
|
5
|
${$class .'::CLASS'} |
|
3
|
|
|
|
|
36
|
|
31
|
|
|
|
|
|
|
}, |
32
|
|
|
|
|
|
|
_method_dispatcher => {}, |
33
|
|
|
|
|
|
|
@_ |
34
|
|
|
|
|
|
|
}; |
35
|
|
|
|
|
|
|
|
36
|
3
|
|
|
|
|
13
|
$singleton = bless($params, $class); |
37
|
|
|
|
|
|
|
{ |
38
|
3
|
|
|
3
|
|
15
|
no strict 'refs'; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
995
|
|
|
3
|
|
|
|
|
6
|
|
39
|
3
|
|
|
|
|
6
|
${$class .'::singleton'} = $singleton; |
|
3
|
|
|
|
|
13
|
|
40
|
|
|
|
|
|
|
} |
41
|
3
|
|
|
|
|
18
|
$singleton->init; |
42
|
|
|
|
|
|
|
|
43
|
3
|
|
|
|
|
18
|
return $singleton; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub method { |
47
|
4
|
|
|
4
|
1
|
5015
|
my $self = shift; |
48
|
4
|
|
|
|
|
9
|
my $method = shift; |
49
|
4
|
|
|
|
|
21
|
my $params = [ @_ ]; |
50
|
|
|
|
|
|
|
|
51
|
4
|
|
|
|
|
32
|
return Test::Mock::Signature::Meta->new( |
52
|
|
|
|
|
|
|
class => $self->{'_real_class'}, |
53
|
|
|
|
|
|
|
method => $method, |
54
|
|
|
|
|
|
|
params => $params |
55
|
|
|
|
|
|
|
); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub clear { |
59
|
2
|
|
|
2
|
1
|
679
|
my $self = shift; |
60
|
2
|
|
|
|
|
5
|
my $method = shift; |
61
|
2
|
|
|
|
|
4
|
my $params = [ @_ ]; |
62
|
2
|
|
|
|
|
4
|
my $md = $self->{'_method_dispatcher'}; |
63
|
|
|
|
|
|
|
|
64
|
2
|
100
|
|
|
|
6
|
unless (scalar @$params) { |
65
|
1
|
|
|
|
|
7
|
delete $self->{'_method_dispatcher'}->{$method}; |
66
|
|
|
|
|
|
|
# do not return dispatcher object for GC |
67
|
1
|
|
|
|
|
3
|
return; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
1
|
|
|
|
|
7
|
my $meta = Test::Mock::Signature::Meta->new( |
71
|
|
|
|
|
|
|
class => $self->{'_real_class'}, |
72
|
|
|
|
|
|
|
method => $method, |
73
|
|
|
|
|
|
|
params => $params |
74
|
|
|
|
|
|
|
); |
75
|
|
|
|
|
|
|
|
76
|
1
|
|
|
|
|
7
|
$md->{$method}->delete($meta); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub dispatcher { |
80
|
4
|
|
|
4
|
1
|
8
|
my $self = shift; |
81
|
4
|
|
|
|
|
9
|
my $method = shift; |
82
|
4
|
|
|
|
|
8
|
my $md = $self->{'_method_dispatcher'}; |
83
|
|
|
|
|
|
|
|
84
|
4
|
100
|
|
|
|
13
|
return $md->{$method} if exists $md->{$method}; |
85
|
|
|
|
|
|
|
|
86
|
3
|
|
|
|
|
33
|
$md->{$method} = Test::Mock::Signature::Dispatcher->new($self->{'_real_class'} .'::'. $method); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub import { |
90
|
2
|
|
|
2
|
|
72
|
my $class = shift; |
91
|
2
|
|
|
|
|
3
|
my $mock = do { |
92
|
3
|
|
|
3
|
|
18
|
no strict 'refs'; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
263
|
|
93
|
2
|
|
|
|
|
2
|
${$class . '::CLASS'}; |
|
2
|
|
|
|
|
7
|
|
94
|
|
|
|
|
|
|
}; |
95
|
|
|
|
|
|
|
|
96
|
2
|
|
|
|
|
11
|
load_class($mock); |
97
|
|
|
|
|
|
|
|
98
|
2
|
|
|
|
|
201
|
my $caller = caller; |
99
|
2
|
|
|
|
|
5
|
my %export = map { $_ => 1 } @EXPORT_OK; |
|
2
|
|
|
|
|
7
|
|
100
|
|
|
|
|
|
|
|
101
|
3
|
|
|
3
|
|
16
|
no strict 'refs'; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
84
|
|
102
|
3
|
|
|
3
|
|
14
|
no warnings 'redefine'; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
528
|
|
103
|
|
|
|
|
|
|
|
104
|
2
|
|
|
|
|
14
|
*{$mock .'::_tms_mock_instance'} = sub { |
105
|
4
|
|
|
4
|
|
22
|
return $class->new; |
106
|
2
|
|
|
|
|
9
|
}; |
107
|
|
|
|
|
|
|
|
108
|
2
|
|
|
|
|
6
|
for my $i ( @_ ) { |
109
|
2
|
50
|
|
|
|
10
|
next unless exists $export{$i}; |
110
|
|
|
|
|
|
|
|
111
|
2
|
|
|
|
|
5
|
my $src_glob = __PACKAGE__ .'::'. $i; |
112
|
2
|
|
|
|
|
3
|
my $dst_glob = $caller .'::'. $i; |
113
|
|
|
|
|
|
|
|
114
|
2
|
|
|
|
|
4042
|
*$dst_glob = *$src_glob; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
42; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
__END__ |