line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mock::Quick::Util; |
2
|
8
|
|
|
8
|
|
46
|
use strict; |
|
8
|
|
|
|
|
20
|
|
|
8
|
|
|
|
|
268
|
|
3
|
8
|
|
|
8
|
|
43
|
use warnings; |
|
8
|
|
|
|
|
18
|
|
|
8
|
|
|
|
|
209
|
|
4
|
|
|
|
|
|
|
|
5
|
8
|
|
|
8
|
|
45
|
use base 'Exporter'; |
|
8
|
|
|
|
|
49
|
|
|
8
|
|
|
|
|
815
|
|
6
|
8
|
|
|
8
|
|
46
|
use Scalar::Util qw/blessed/; |
|
8
|
|
|
|
|
50
|
|
|
8
|
|
|
|
|
992
|
|
7
|
8
|
|
|
8
|
|
2487
|
use Mock::Quick::Method; |
|
8
|
|
|
|
|
16
|
|
|
8
|
|
|
|
|
225
|
|
8
|
8
|
|
|
8
|
|
41
|
use Carp qw/croak/; |
|
8
|
|
|
|
|
15
|
|
|
8
|
|
|
|
|
853
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $CLEAR = 'clear'; |
11
|
|
|
|
|
|
|
our @EXPORT = qw/ |
12
|
|
|
|
|
|
|
class_meth |
13
|
|
|
|
|
|
|
obj_meth |
14
|
|
|
|
|
|
|
alt_meth |
15
|
|
|
|
|
|
|
call |
16
|
|
|
|
|
|
|
param |
17
|
|
|
|
|
|
|
inject |
18
|
|
|
|
|
|
|
purge_util |
19
|
|
|
|
|
|
|
super |
20
|
|
|
|
|
|
|
/; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub inject { |
23
|
103
|
|
|
103
|
0
|
266
|
my ( $package, $name, $code ) = @_; |
24
|
8
|
|
|
8
|
|
39
|
no warnings 'redefine'; |
|
8
|
|
|
|
|
27
|
|
|
8
|
|
|
|
|
532
|
|
25
|
8
|
|
|
8
|
|
40
|
no strict 'refs'; |
|
8
|
|
|
|
|
14
|
|
|
8
|
|
|
|
|
6701
|
|
26
|
103
|
|
|
|
|
121
|
*{"$package\::$name"} = $code; |
|
103
|
|
|
|
|
750
|
|
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub call { |
30
|
65
|
|
|
65
|
0
|
937
|
my $self = shift; |
31
|
65
|
|
|
|
|
367
|
require Mock::Quick::Object::Control; |
32
|
65
|
|
|
|
|
236
|
my $control = Mock::Quick::Object::Control->new( $self ); |
33
|
65
|
|
|
|
|
114
|
my $name = shift; |
34
|
|
|
|
|
|
|
|
35
|
65
|
|
|
|
|
195
|
my $class = blessed( $self ); |
36
|
65
|
50
|
|
|
|
166
|
croak "Can't call method on an unblessed reference" |
37
|
|
|
|
|
|
|
unless $class; |
38
|
|
|
|
|
|
|
|
39
|
65
|
100
|
|
|
|
206
|
if ( $control->strict ) { |
40
|
8
|
100
|
|
|
|
35
|
croak "Can't locate object method \"$name\" in this instance" |
41
|
|
|
|
|
|
|
unless exists $self->{$name}; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
64
|
100
|
100
|
|
|
267
|
if ( @_ && ref $_[0] && $_[0] == \$CLEAR ) { |
|
|
|
100
|
|
|
|
|
45
|
7
|
|
|
|
|
70
|
delete $self->{ $name }; |
46
|
7
|
|
|
|
|
26
|
delete $control->metrics->{$name}; |
47
|
7
|
|
|
|
|
39
|
return; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
57
|
|
|
|
|
164
|
$control->metrics->{$name}++; |
51
|
|
|
|
|
|
|
|
52
|
57
|
100
|
100
|
|
|
653
|
return $self->{ $name }->( $self, @_ ) |
|
|
|
66
|
|
|
|
|
53
|
|
|
|
|
|
|
if exists( $self->{ $name }) |
54
|
|
|
|
|
|
|
&& blessed( $self->{ $name }) |
55
|
|
|
|
|
|
|
&& blessed( $self->{ $name })->isa( 'Mock::Quick::Method' ); |
56
|
|
|
|
|
|
|
|
57
|
39
|
100
|
66
|
|
|
216
|
return $self->{$name} = shift(@_) |
58
|
|
|
|
|
|
|
if blessed( $_[0] ) && blessed( $_[0] )->isa( 'Mock::Quick::Method' ); |
59
|
|
|
|
|
|
|
|
60
|
38
|
|
|
|
|
109
|
param( $self, $name, @_ ); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub param { |
64
|
38
|
|
|
38
|
0
|
53
|
my $self = shift; |
65
|
38
|
|
|
|
|
57
|
my $name = shift; |
66
|
|
|
|
|
|
|
|
67
|
38
|
100
|
|
|
|
96
|
$self->{$name} = shift(@_) if @_; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# Prevent autovivication |
70
|
38
|
100
|
|
|
|
332
|
return unless exists( $self->{ $name }); |
71
|
18
|
|
|
|
|
119
|
return $self->{ $name }; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub class_meth { |
75
|
8
|
|
|
8
|
0
|
1118
|
my ( $name, $block ) = @_; |
76
|
8
|
|
|
|
|
29
|
my $caller = caller; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
my $sub = sub { |
79
|
13
|
50
|
|
13
|
|
316
|
goto &$block unless blessed( $_[0] ); |
80
|
0
|
|
|
|
|
0
|
unshift @_ => ( shift(@_), $name ); |
81
|
0
|
|
|
|
|
0
|
goto &call; |
82
|
8
|
|
|
|
|
136
|
}; |
83
|
|
|
|
|
|
|
|
84
|
8
|
|
|
|
|
31
|
inject( $caller, $name, $sub ); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub obj_meth { |
88
|
8
|
|
|
8
|
0
|
52
|
my ( $name, $block ) = @_; |
89
|
8
|
|
|
|
|
26
|
my $caller = caller; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
my $sub = sub { |
92
|
15
|
100
|
|
15
|
|
4846
|
goto &$block if blessed( $_[0] ); |
93
|
1
|
|
|
|
|
30
|
Carp::croak( "Can't locate object method \"$name\" via package \"$caller\"" ); |
94
|
8
|
|
|
|
|
122
|
}; |
95
|
|
|
|
|
|
|
|
96
|
8
|
|
|
|
|
23
|
inject( $caller, $name, $sub ); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub alt_meth { |
100
|
12
|
|
|
12
|
0
|
1347
|
my ( $name, %alts ) = @_; |
101
|
12
|
|
|
|
|
53
|
my $caller = caller; |
102
|
|
|
|
|
|
|
|
103
|
12
|
50
|
33
|
|
|
287
|
croak "You must provide an action for both 'class' and 'obj'" |
104
|
|
|
|
|
|
|
unless $alts{class} && $alts{obj}; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
my $sub = sub { |
107
|
32
|
100
|
|
32
|
|
3512
|
goto &{ $alts{obj }} if blessed( $_[0] ); |
|
20
|
|
|
|
|
96
|
|
108
|
12
|
|
|
|
|
19
|
goto &{ $alts{ class }}; |
|
12
|
|
|
|
|
61
|
|
109
|
12
|
|
|
|
|
55
|
}; |
110
|
|
|
|
|
|
|
|
111
|
12
|
|
|
|
|
38
|
inject( $caller, $name, $sub ); |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub purge_util { |
115
|
22
|
|
|
22
|
0
|
922
|
my $caller = caller; |
116
|
22
|
|
|
|
|
331
|
for my $sub ( @EXPORT ) { |
117
|
8
|
|
|
8
|
|
47
|
no strict 'refs'; |
|
8
|
|
|
|
|
11
|
|
|
8
|
|
|
|
|
720
|
|
118
|
176
|
|
|
|
|
190
|
my $ref = \%{"$caller\::"}; |
|
176
|
|
|
|
|
626
|
|
119
|
176
|
|
|
|
|
480
|
delete $ref->{ $sub }; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
1; |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
__END__ |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head1 NAME |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
Mock::Quick::Util - Uitls for L<Mock::Quick>. |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head1 AUTHORS |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
Chad Granum L<exodist7@gmail.com> |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head1 COPYRIGHT |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
Copyright (C) 2011 Chad Granum |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
Mock-Quick is free software; Standard perl licence. |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
Mock-Quick is distributed in the hope that it will be useful, but WITHOUT ANY |
142
|
|
|
|
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
143
|
|
|
|
|
|
|
PARTICULAR PURPOSE. See the license for more details. |