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