line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::MockPackages::Package; |
2
|
5
|
|
|
5
|
|
20645
|
use strict; |
|
5
|
|
|
|
|
5
|
|
|
5
|
|
|
|
|
116
|
|
3
|
5
|
|
|
5
|
|
17
|
use warnings; |
|
5
|
|
|
|
|
6
|
|
|
5
|
|
|
|
|
97
|
|
4
|
5
|
|
|
5
|
|
15
|
use utf8; |
|
5
|
|
|
|
|
6
|
|
|
5
|
|
|
|
|
53
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.9'; |
7
|
|
|
|
|
|
|
|
8
|
5
|
|
|
5
|
|
188
|
use Carp qw(croak); |
|
5
|
|
|
|
|
5
|
|
|
5
|
|
|
|
|
281
|
|
9
|
5
|
|
|
5
|
|
413
|
use English qw(-no_match_vars); |
|
5
|
|
|
|
|
3260
|
|
|
5
|
|
|
|
|
26
|
|
10
|
5
|
|
|
5
|
|
2000
|
use Test::MockPackages::Mock(); |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
892
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
10
|
|
|
10
|
1
|
1263
|
my ( $pkg, $package_name ) = @ARG; |
14
|
|
|
|
|
|
|
|
15
|
10
|
100
|
100
|
|
|
42
|
if ( !$package_name || ref( $package_name ) ) { |
16
|
2
|
|
|
|
|
28
|
croak( '$package_name is required and must be a SCALAR' ); |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
8
|
|
|
|
|
47
|
return bless { |
20
|
|
|
|
|
|
|
_package_name => $package_name, |
21
|
|
|
|
|
|
|
_mocks => {}, |
22
|
|
|
|
|
|
|
}, $pkg; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub mock { |
26
|
12
|
|
|
12
|
1
|
568
|
my ( $self, $name ) = @ARG; |
27
|
|
|
|
|
|
|
|
28
|
12
|
100
|
100
|
|
|
49
|
if ( !$name || ref( $name ) ) { |
29
|
2
|
|
|
|
|
15
|
croak( '$name is required and must be a SCALAR' ); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
10
|
100
|
|
|
|
26
|
if ( my $mock = $self->{_mocks}{$name} ) { |
33
|
1
|
|
|
|
|
5
|
return $mock; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
9
|
|
|
|
|
33
|
return $self->{_mocks}{$name} = Test::MockPackages::Mock->new( $self->{_package_name}, $name ); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub DESTROY { |
40
|
8
|
|
|
8
|
|
89
|
my ( $self ) = @ARG; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# ensures that objects are destroyed in a consistent order. |
43
|
8
|
|
|
|
|
9
|
for my $key ( sort keys %{ $self->{_mocks} } ) { |
|
8
|
|
|
|
|
37
|
|
44
|
9
|
|
|
|
|
31
|
delete $self->{_mocks}{$key}; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
1; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
__END__ |