line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Stub; |
2
|
5
|
|
|
5
|
|
630942
|
use strict; |
|
5
|
|
|
|
|
14
|
|
|
5
|
|
|
|
|
193
|
|
3
|
5
|
|
|
5
|
|
27
|
use warnings; |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
249
|
|
4
|
5
|
|
|
5
|
|
120
|
use 5.008001; |
|
5
|
|
|
|
|
18
|
|
|
5
|
|
|
|
|
313
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
6
|
5
|
|
|
5
|
|
4191
|
use parent qw/Exporter/; |
|
5
|
|
|
|
|
1893
|
|
|
5
|
|
|
|
|
24
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our @EXPORT = qw/stub make_stub/; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub stub { |
11
|
8
|
|
|
8
|
1
|
558
|
bless \$_[0], 'Test::Stub::Driver'; |
12
|
|
|
|
|
|
|
} |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my $id = 0; |
15
|
|
|
|
|
|
|
sub make_stub { |
16
|
7
|
|
|
7
|
1
|
12
|
my $object = shift; |
17
|
7
|
|
|
|
|
14
|
my $method = shift; |
18
|
7
|
|
100
|
0
|
|
26
|
my $stub = shift || sub {}; |
|
0
|
|
|
|
|
0
|
|
19
|
|
|
|
|
|
|
|
20
|
7
|
100
|
|
6
|
|
42
|
my $func = ref($stub) eq 'CODE' ? $stub : sub { $stub }; |
|
6
|
|
|
|
|
36
|
|
21
|
|
|
|
|
|
|
|
22
|
7
|
|
|
|
|
22
|
my $pkg = "Test::Stub::Anon" . $id++; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# stubbing. |
25
|
|
|
|
|
|
|
{ |
26
|
5
|
|
|
5
|
|
722
|
no strict 'refs'; |
|
5
|
|
|
|
|
15
|
|
|
5
|
|
|
|
|
578
|
|
|
7
|
|
|
|
|
9
|
|
27
|
7
|
|
|
|
|
11
|
unshift @{"$pkg\::ISA"}, ref $$object; |
|
7
|
|
|
|
|
110
|
|
28
|
7
|
|
|
|
|
15
|
*{"$pkg\::$method"} = $func; |
|
7
|
|
|
|
|
56
|
|
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# rebless |
32
|
7
|
|
|
|
|
18
|
bless $$object, $pkg; |
33
|
|
|
|
|
|
|
|
34
|
7
|
|
|
|
|
16
|
return; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
package Test::Stub::Driver; |
38
|
5
|
|
|
5
|
|
25
|
use strict; |
|
5
|
|
|
|
|
24
|
|
|
5
|
|
|
|
|
149
|
|
39
|
5
|
|
|
5
|
|
22
|
use warnings; |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
165
|
|
40
|
|
|
|
|
|
|
|
41
|
5
|
|
|
5
|
|
24
|
use Carp qw(croak); |
|
5
|
|
|
|
|
15
|
|
|
5
|
|
|
|
|
1517
|
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
our $AUTOLOAD; |
44
|
0
|
|
|
0
|
|
0
|
sub DESTROY { } |
45
|
|
|
|
|
|
|
sub AUTOLOAD { |
46
|
8
|
|
|
8
|
|
1963
|
$AUTOLOAD =~ s/.*:://; |
47
|
8
|
|
|
|
|
15
|
my $method = $AUTOLOAD; |
48
|
|
|
|
|
|
|
|
49
|
8
|
|
|
|
|
13
|
my $self = shift; |
50
|
|
|
|
|
|
|
|
51
|
8
|
100
|
100
|
|
|
77
|
if (UNIVERSAL::can($$self, $method) || UNIVERSAL::can($$self, 'AUTOLOAD')) { |
52
|
7
|
|
|
|
|
22
|
Test::Stub::make_stub($self, $method, @_); |
53
|
7
|
|
|
|
|
14
|
return; |
54
|
|
|
|
|
|
|
} else { |
55
|
|
|
|
|
|
|
# Throw the same kind of error that perl would throw if you attempt to call |
56
|
|
|
|
|
|
|
# some unknown method on an object |
57
|
1
|
|
|
|
|
3
|
my $package = ref($$self); |
58
|
1
|
|
|
|
|
159
|
croak(qq{Can't locate object method "$method" via package "$package"}); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
1; |
63
|
|
|
|
|
|
|
__END__ |