line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Mock::Simple; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
203551
|
use 5.008008; |
|
3
|
|
|
|
|
31
|
|
4
|
3
|
|
|
3
|
|
17
|
use strict; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
59
|
|
5
|
3
|
|
|
3
|
|
13
|
use warnings; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
1075
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.10'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
my $allow_new_methods = 0; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new { |
12
|
6
|
|
|
6
|
1
|
2868
|
my $package = shift; |
13
|
6
|
|
66
|
|
|
36
|
my $class = ref($package) || $package; |
14
|
|
|
|
|
|
|
|
15
|
6
|
|
|
|
|
22
|
my $self = {@_}; |
16
|
6
|
|
|
|
|
14
|
bless($self, $class); |
17
|
|
|
|
|
|
|
|
18
|
6
|
100
|
|
|
|
27
|
if (!$self->{module}) { |
19
|
1
|
|
|
|
|
6
|
require Carp; |
20
|
1
|
|
|
|
|
188
|
Carp::croak("No module name provided to mock"); |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
5
|
|
|
|
|
9
|
my $module_location; |
24
|
5
|
100
|
|
|
|
15
|
if ($self->{module_location}) { |
25
|
1
|
|
|
|
|
2
|
$module_location = $self->{module_location}; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
else { |
28
|
4
|
|
|
|
|
10
|
$module_location = $self->{module} . '.pm'; |
29
|
4
|
|
|
|
|
10
|
$module_location =~ s/::/\//g; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
5
|
50
|
|
|
|
12
|
if ($self->{no_load}) { |
33
|
0
|
|
|
|
|
0
|
$INC{$module_location} = 1; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
else { |
36
|
5
|
|
|
|
|
1148
|
require $module_location; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
5
|
100
|
66
|
|
|
840
|
$allow_new_methods = 1 if $self->{allow_new_methods} || $self->{no_load}; |
40
|
|
|
|
|
|
|
|
41
|
5
|
|
|
|
|
17
|
return $self; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub add { |
45
|
8
|
|
|
8
|
1
|
1215
|
my $self = shift; |
46
|
8
|
|
|
|
|
14
|
my $name = shift; |
47
|
8
|
|
|
|
|
11
|
my $sub = shift; |
48
|
|
|
|
|
|
|
|
49
|
8
|
50
|
|
|
|
23
|
return if $ENV{TEST_MOCK_SIMPLE_DISABLE}; |
50
|
|
|
|
|
|
|
|
51
|
8
|
100
|
|
|
|
17
|
if (!$name) { |
52
|
1
|
|
|
|
|
4
|
require Carp; |
53
|
1
|
|
|
|
|
98
|
Carp::croak("No method name provided to mock"); |
54
|
|
|
|
|
|
|
} |
55
|
7
|
100
|
|
|
|
20
|
if (!$sub) { |
56
|
1
|
|
|
|
|
5
|
require Carp; |
57
|
1
|
|
|
|
|
72
|
Carp::croak("No sub ref provided to mock"); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
6
|
100
|
|
|
|
13
|
if (!$allow_new_methods) { |
61
|
|
|
|
|
|
|
die("Module (" . $self->{module} . ") does not have a method named '$name'\n") |
62
|
2
|
100
|
|
|
|
38
|
unless $self->{module}->can($name); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
{ |
66
|
3
|
|
|
3
|
|
71
|
no strict; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
96
|
|
|
5
|
|
|
|
|
32
|
|
67
|
3
|
|
|
3
|
|
16
|
no warnings; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
282
|
|
68
|
|
|
|
|
|
|
|
69
|
5
|
|
|
|
|
18
|
*{$self->{module} . '::' . $name} = $sub; |
|
5
|
|
|
|
|
38
|
|
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
1; |
74
|
|
|
|
|
|
|
__END__ |