line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Mock::One; |
2
|
2
|
|
|
2
|
|
173472
|
use warnings; |
|
2
|
|
|
|
|
21
|
|
|
2
|
|
|
|
|
63
|
|
3
|
2
|
|
|
2
|
|
11
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
102
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
# ABSTRACT: Mock the world with one object |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.011'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $AUTOLOAD; |
10
|
|
|
|
|
|
|
|
11
|
2
|
|
|
2
|
|
11
|
use overload '""' => '__x_mock_str'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
19
|
|
12
|
|
|
|
|
|
|
|
13
|
2
|
|
|
2
|
|
188
|
use List::Util 1.33 qw(any); |
|
2
|
|
|
|
|
41
|
|
|
2
|
|
|
|
|
1748
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new { |
16
|
35
|
|
|
35
|
1
|
15595
|
my $class = shift; |
17
|
35
|
|
66
|
|
|
212
|
return bless({@_}, ref($class) || $class); |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub can { |
21
|
5
|
|
|
5
|
1
|
867
|
my ($self, $can) = @_; |
22
|
5
|
100
|
100
|
|
|
32
|
if (!exists $self->{$can} && $self->{"X-Mock-Strict"}) { |
23
|
1
|
|
|
|
|
17
|
return 0; |
24
|
|
|
|
|
|
|
} |
25
|
4
|
|
|
|
|
23
|
return 1; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub AUTOLOAD { |
29
|
55
|
|
|
55
|
|
3116
|
my $self = shift; |
30
|
|
|
|
|
|
|
|
31
|
55
|
|
|
|
|
280
|
my ($call) = $AUTOLOAD =~ /([^:]+)$/; |
32
|
|
|
|
|
|
|
|
33
|
55
|
100
|
|
|
|
124
|
if ($self->{'X-Mock-Called'}) { |
34
|
7
|
|
|
|
|
20
|
my @caller = caller(1); |
35
|
7
|
|
|
|
|
130
|
push(@{ $self->{'X-Mock-Called-By'}{$call}{$caller[3]}}, [ @_ ]); |
|
7
|
|
|
|
|
32
|
|
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
55
|
100
|
|
|
|
110
|
if (exists $self->{$call}) { |
|
|
100
|
|
|
|
|
|
39
|
41
|
|
|
|
|
62
|
my $ref = ref $self->{$call}; |
40
|
41
|
100
|
|
|
|
100
|
if ($ref eq 'HASH') { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
41
|
15
|
|
|
|
|
23
|
return $self->new( __x_mock_copy_x($self), %{ $self->{$call} }); |
|
15
|
|
|
|
|
37
|
|
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
elsif ($ref eq 'ARRAY') { |
44
|
4
|
|
|
|
|
10
|
return $self->new(__x_mock_copy_x($self), map { $_ => $self } @{ $self->{$call} }); |
|
10
|
|
|
|
|
21
|
|
|
4
|
|
|
|
|
9
|
|
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
elsif ($ref eq 'CODE') { |
47
|
3
|
100
|
|
|
|
9
|
if ($self->{'X-Mock-SelfArg'}) { |
48
|
2
|
|
|
|
|
5
|
return $self->{$call}->($self, @_); |
49
|
|
|
|
|
|
|
} |
50
|
1
|
|
|
|
|
4
|
return $self->{$call}->(@_); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
elsif ($ref eq 'REF') { |
53
|
2
|
|
|
|
|
3
|
return ${ $self->{$call} }; |
|
2
|
|
|
|
|
17
|
|
54
|
|
|
|
|
|
|
} |
55
|
17
|
|
|
|
|
61
|
return $self->{$call}; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
elsif ($self->{"X-Mock-Strict"}) { |
58
|
2
|
|
|
|
|
17
|
die sprintf("Using %s in strict mode, called undefined function '%s'", |
59
|
|
|
|
|
|
|
__PACKAGE__, $call); |
60
|
|
|
|
|
|
|
} |
61
|
12
|
|
|
|
|
69
|
return $self; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub isa { |
65
|
18
|
|
|
18
|
1
|
1748
|
my ($self, $class) = @_; |
66
|
|
|
|
|
|
|
|
67
|
18
|
100
|
|
|
|
57
|
if (my $isas = $self->{"X-Mock-ISA"}) { |
|
|
100
|
|
|
|
|
|
68
|
15
|
|
|
|
|
20
|
my $ref = ref $isas; |
69
|
15
|
100
|
100
|
|
|
54
|
if (!$ref && $isas eq $class) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
70
|
3
|
|
|
|
|
7
|
return 1; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
elsif ($ref eq 'ARRAY') { |
73
|
3
|
100
|
|
5
|
|
14
|
return 1 if any { $_ eq $class } @$isas; |
|
5
|
|
|
|
|
13
|
|
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
elsif ($ref eq 'CODE') { |
76
|
4
|
100
|
|
|
|
6
|
if ($self->{'X-Mock-SelfArg'}) { |
77
|
2
|
|
|
|
|
5
|
return $isas->($self, $class); |
78
|
|
|
|
|
|
|
} |
79
|
2
|
|
|
|
|
4
|
return $isas->($class); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
elsif ($ref eq "Regexp") { |
82
|
2
|
|
|
|
|
11
|
return $class =~ /$isas/; |
83
|
|
|
|
|
|
|
} |
84
|
4
|
|
|
|
|
14
|
return 0; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
elsif (exists $self->{"X-Mock-ISA"}) { |
87
|
1
|
|
|
|
|
4
|
return 0; |
88
|
|
|
|
|
|
|
} |
89
|
2
|
|
|
|
|
6
|
return 1; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
# Just an empty method to prevent weird AUTOLOAD loops |
93
|
|
|
|
0
|
|
|
sub DESTROY { } |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
my @__xattr = qw(Strict ISA Stringify SelfArg); |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub __x_mock_copy_x { |
98
|
19
|
|
|
19
|
|
26
|
my ($orig) = @_; |
99
|
19
|
|
|
|
|
24
|
my %copy; |
100
|
19
|
|
|
|
|
29
|
foreach (@__xattr) { |
101
|
76
|
|
|
|
|
100
|
my $attr = "X-Mock-$_"; |
102
|
76
|
100
|
|
|
|
114
|
if (exists $orig->{$attr}) { |
103
|
56
|
|
|
|
|
75
|
$copy{$attr} = $orig->{$attr}; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
} |
106
|
19
|
|
|
|
|
44
|
return %copy; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub __x_mock_str { |
110
|
8
|
|
|
8
|
|
220
|
my ($self) = @_; |
111
|
8
|
100
|
|
|
|
18
|
if (my $stringify = $self->{'X-Mock-Stringify'}) { |
112
|
5
|
100
|
|
|
|
11
|
if (ref $stringify eq 'CODE') { |
113
|
3
|
100
|
|
|
|
5
|
if ($self->{'X-Mock-SelfArg'}) { |
114
|
2
|
|
|
|
|
5
|
return $stringify->($self); |
115
|
|
|
|
|
|
|
} |
116
|
1
|
|
|
|
|
3
|
return $stringify->(); |
117
|
|
|
|
|
|
|
} |
118
|
2
|
|
|
|
|
8
|
return $stringify; |
119
|
|
|
|
|
|
|
} |
120
|
3
|
|
|
|
|
35
|
return __PACKAGE__ . " stringified"; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
1; |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
__END__ |