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