line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Mock::Two; |
2
|
|
|
|
|
|
|
our $VERSION = '0.011'; |
3
|
1
|
|
|
1
|
|
336
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
23
|
|
4
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
16
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# ABSTRACT: Inspection module for Test::Mock::One |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
3
|
use Exporter 'import'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
9
|
1
|
|
|
1
|
|
5
|
use Carp qw(croak carp); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
36
|
|
10
|
1
|
|
|
1
|
|
4
|
use List::Util qw(any); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
133
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our @EXPORT_OK = qw( |
13
|
|
|
|
|
|
|
one_called |
14
|
|
|
|
|
|
|
one_called_ok |
15
|
|
|
|
|
|
|
one_called_times_ok |
16
|
|
|
|
|
|
|
one_called_params_ok |
17
|
|
|
|
|
|
|
); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( |
20
|
|
|
|
|
|
|
all => \@EXPORT_OK, |
21
|
|
|
|
|
|
|
test => [ grep { $_ =~ /_ok$/ } @EXPORT_OK ], |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
|
24
|
1
|
|
|
1
|
|
9
|
use Test::Builder; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
616
|
|
25
|
|
|
|
|
|
|
my $tb = Test::Builder->new(); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub one_called { |
28
|
11
|
|
|
11
|
1
|
2564
|
my ($one, $method, $func) = @_; |
29
|
|
|
|
|
|
|
|
30
|
11
|
100
|
|
|
|
43
|
if (!UNIVERSAL::isa($one, 'Test::Mock::One')) { |
31
|
1
|
|
|
|
|
16
|
croak "We only play well with Test::Mock::One"; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
10
|
50
|
|
|
|
41
|
if (!$one->{'X-Mock-Called'}) { |
35
|
0
|
|
|
|
|
0
|
croak "Test::Mock::One object did not specify call tracing", $/; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
10
|
100
|
|
|
|
22
|
if (!defined $method) { |
39
|
1
|
|
|
|
|
7
|
croak "Failed to provide a method"; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
9
|
100
|
|
|
|
24
|
if (my $cs = $one->{'X-Mock-Called-By'}) { |
43
|
8
|
|
|
|
|
14
|
my $rv = $cs->{$method}; |
44
|
|
|
|
|
|
|
|
45
|
8
|
100
|
|
|
|
19
|
return unless $rv; |
46
|
7
|
50
|
|
|
|
15
|
return $rv if !defined $func; |
47
|
|
|
|
|
|
|
|
48
|
7
|
100
|
|
|
|
25
|
return $rv->{$func} if exists $rv->{$func}; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
2
|
50
|
|
|
|
6
|
return if !defined $func; |
52
|
|
|
|
|
|
|
|
53
|
2
|
|
|
|
|
11
|
$func =~ s#::#/#g; |
54
|
2
|
|
|
|
|
5
|
$func .= '.pm'; |
55
|
2
|
100
|
|
164
|
|
90
|
if (any { $func eq $_ } keys %INC) { |
|
164
|
|
|
|
|
189
|
|
56
|
1
|
|
|
|
|
14
|
carp("Using Pkg::Name instead of Pkg::Name::Function"); |
57
|
|
|
|
|
|
|
} |
58
|
2
|
|
|
|
|
28
|
return; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub one_called_ok { |
62
|
2
|
|
|
2
|
1
|
759
|
my ($one, $method, $func, $msg) = @_; |
63
|
|
|
|
|
|
|
|
64
|
2
|
|
33
|
|
|
17
|
$msg //= "${func} called Test::Mock::One->$method"; |
65
|
2
|
|
|
|
|
5
|
my $rv = one_called($one, $method, $func); |
66
|
2
|
|
|
|
|
9
|
$tb->ok($rv, $msg); |
67
|
2
|
50
|
|
|
|
769
|
return $rv if defined $rv; |
68
|
0
|
|
|
|
|
0
|
return ; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub one_called_times_ok { |
72
|
3
|
|
|
3
|
1
|
3065
|
my ($one, $method, $func, $times, $msg) = @_; |
73
|
|
|
|
|
|
|
|
74
|
3
|
|
33
|
|
|
22
|
$msg //= "${func} called $times on Test::Mock::One->$method"; |
75
|
3
|
100
|
|
|
|
5
|
if (my $rv = one_called($one, $method, $func)) { |
76
|
2
|
|
|
|
|
9
|
$tb->is_eq(scalar @$rv, $times, $msg); |
77
|
2
|
|
|
|
|
1337
|
return $rv; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
else { |
80
|
1
|
|
|
|
|
5
|
$tb->is_eq(0, $times, $msg); |
81
|
1
|
|
|
|
|
470
|
return; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
1; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
__END__ |