line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Mock::Signature; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
58516
|
use strict; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
117
|
|
4
|
4
|
|
|
4
|
|
14
|
use warnings; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
94
|
|
5
|
|
|
|
|
|
|
|
6
|
4
|
|
|
4
|
|
18
|
use Scalar::Util qw(weaken); |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
340
|
|
7
|
4
|
|
|
4
|
|
1807
|
use Class::Load qw(load_class); |
|
4
|
|
|
|
|
93789
|
|
|
4
|
|
|
|
|
333
|
|
8
|
|
|
|
|
|
|
|
9
|
4
|
|
|
4
|
|
1646
|
use Test::Mock::Signature::Meta; |
|
4
|
|
|
|
|
12
|
|
|
4
|
|
|
|
|
456
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
12
|
|
|
|
|
|
|
our @EXPORT_OK = qw(any); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my $singleton = { |
15
|
|
|
|
|
|
|
}; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub any() { |
18
|
1
|
|
|
1
|
1
|
11
|
return $Data::PatternCompare::any; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
2
|
|
|
2
|
1
|
2
|
sub init { } |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub new { |
24
|
11
|
|
|
11
|
1
|
422
|
my $class = shift; |
25
|
11
|
|
|
|
|
13
|
my $mock_class = do { |
26
|
4
|
|
|
4
|
|
24
|
no strict 'refs'; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
1246
|
|
27
|
11
|
|
|
|
|
12
|
${$class . '::CLASS'}; |
|
11
|
|
|
|
|
51
|
|
28
|
|
|
|
|
|
|
}; |
29
|
11
|
|
66
|
|
|
61
|
$mock_class ||= shift; |
30
|
|
|
|
|
|
|
|
31
|
11
|
50
|
|
|
|
24
|
die "No class for mocking defined. Look documentation for constructor new()." unless $mock_class; |
32
|
|
|
|
|
|
|
|
33
|
11
|
|
|
|
|
37
|
my $param = { |
34
|
|
|
|
|
|
|
_method_dispatcher => {}, |
35
|
|
|
|
|
|
|
_real_class => $mock_class, |
36
|
|
|
|
|
|
|
@_ |
37
|
|
|
|
|
|
|
}; |
38
|
|
|
|
|
|
|
|
39
|
11
|
100
|
|
|
|
45
|
return $singleton->{$mock_class} if exists $singleton->{$mock_class}; |
40
|
|
|
|
|
|
|
|
41
|
4
|
|
|
|
|
22
|
load_class($mock_class); |
42
|
|
|
|
|
|
|
|
43
|
4
|
|
|
|
|
412
|
$singleton->{$mock_class} = bless($param, $class); |
44
|
4
|
|
|
|
|
21
|
weaken($singleton->{$mock_class}); |
45
|
4
|
|
|
|
|
16
|
$singleton->{$mock_class}->init; |
46
|
|
|
|
|
|
|
|
47
|
4
|
|
|
|
|
19
|
return $singleton->{$mock_class}; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub method { |
51
|
7
|
|
|
7
|
1
|
6548
|
my $self = shift; |
52
|
7
|
|
|
|
|
8
|
my $method = shift; |
53
|
7
|
|
|
|
|
15
|
my $params = [ @_ ]; |
54
|
|
|
|
|
|
|
|
55
|
7
|
|
|
|
|
48
|
return Test::Mock::Signature::Meta->new( |
56
|
|
|
|
|
|
|
class => $self->{'_real_class'}, |
57
|
|
|
|
|
|
|
method => $method, |
58
|
|
|
|
|
|
|
params => $params |
59
|
|
|
|
|
|
|
); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub clear { |
63
|
4
|
|
|
4
|
1
|
1250
|
my $self = shift; |
64
|
4
|
|
|
|
|
7
|
my $method = shift; |
65
|
4
|
|
|
|
|
8
|
my $params = [ @_ ]; |
66
|
4
|
|
|
|
|
6
|
my $md = $self->{'_method_dispatcher'}; |
67
|
|
|
|
|
|
|
|
68
|
4
|
100
|
|
|
|
12
|
unless (scalar @$params) { |
69
|
2
|
|
|
|
|
12
|
delete $self->{'_method_dispatcher'}->{$method}; |
70
|
|
|
|
|
|
|
# do not return dispatcher object for GC |
71
|
2
|
|
|
|
|
5
|
return; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
2
|
|
|
|
|
11
|
my $meta = Test::Mock::Signature::Meta->new( |
75
|
|
|
|
|
|
|
class => $self->{'_real_class'}, |
76
|
|
|
|
|
|
|
method => $method, |
77
|
|
|
|
|
|
|
params => $params |
78
|
|
|
|
|
|
|
); |
79
|
|
|
|
|
|
|
|
80
|
2
|
|
|
|
|
11
|
$md->{$method}->delete($meta); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub dispatcher { |
84
|
7
|
|
|
7
|
1
|
8
|
my $self = shift; |
85
|
7
|
|
|
|
|
11
|
my $method = shift; |
86
|
7
|
|
|
|
|
7
|
my $md = $self->{'_method_dispatcher'}; |
87
|
|
|
|
|
|
|
|
88
|
7
|
100
|
|
|
|
18
|
return $md->{$method} if exists $md->{$method}; |
89
|
|
|
|
|
|
|
|
90
|
5
|
|
|
|
|
33
|
$md->{$method} = Test::Mock::Signature::Dispatcher->new($self->{'_real_class'} .'::'. $method); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub import { |
94
|
3
|
|
|
3
|
|
60
|
my $class = shift; |
95
|
|
|
|
|
|
|
|
96
|
3
|
|
|
|
|
6
|
my $caller = caller; |
97
|
3
|
|
|
|
|
5
|
my %export = map { $_ => 1 } @EXPORT_OK; |
|
3
|
|
|
|
|
11
|
|
98
|
|
|
|
|
|
|
|
99
|
4
|
|
|
4
|
|
21
|
no strict 'refs'; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
110
|
|
100
|
4
|
|
|
4
|
|
17
|
no warnings 'redefine'; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
574
|
|
101
|
|
|
|
|
|
|
|
102
|
3
|
|
|
|
|
1633
|
for my $i ( @_ ) { |
103
|
2
|
50
|
|
|
|
8
|
next unless exists $export{$i}; |
104
|
|
|
|
|
|
|
|
105
|
2
|
|
|
|
|
3
|
my $src_glob = __PACKAGE__ .'::'. $i; |
106
|
2
|
|
|
|
|
3
|
my $dst_glob = $caller .'::'. $i; |
107
|
|
|
|
|
|
|
|
108
|
2
|
|
|
|
|
3297
|
*$dst_glob = *$src_glob; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub DESTROY { |
113
|
4
|
|
|
4
|
|
3225
|
my $self = shift; |
114
|
4
|
50
|
|
|
|
15
|
return unless ref($self); |
115
|
|
|
|
|
|
|
|
116
|
4
|
|
|
|
|
43
|
delete $singleton->{$self->{'_real_class'}}; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
42; |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
__END__ |