line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Mocha::Method; |
2
|
|
|
|
|
|
|
# ABSTRACT: Objects to represent methods and their arguuments |
3
|
|
|
|
|
|
|
$Test::Mocha::Method::VERSION = '0.61'; |
4
|
21
|
|
|
21
|
|
6638
|
use strict; |
|
21
|
|
|
|
|
30
|
|
|
21
|
|
|
|
|
528
|
|
5
|
21
|
|
|
21
|
|
76
|
use warnings; |
|
21
|
|
|
|
|
19
|
|
|
21
|
|
|
|
|
440
|
|
6
|
|
|
|
|
|
|
|
7
|
21
|
|
|
21
|
|
78
|
use Carp qw( croak ); |
|
21
|
|
|
|
|
17
|
|
|
21
|
|
|
|
|
713
|
|
8
|
21
|
|
|
21
|
|
6475
|
use Test::Mocha::PartialDump; |
|
21
|
|
|
|
|
42
|
|
|
21
|
|
|
|
|
652
|
|
9
|
21
|
|
|
21
|
|
6467
|
use Test::Mocha::Types qw( Matcher Slurpy ); |
|
21
|
|
|
|
|
67
|
|
|
21
|
|
|
|
|
219
|
|
10
|
21
|
|
|
21
|
|
9114
|
use Test::Mocha::Util qw( match ); |
|
21
|
|
|
|
|
31
|
|
|
21
|
|
|
|
|
1045
|
|
11
|
21
|
|
|
21
|
|
80
|
use Types::Standard qw( ArrayRef HashRef Str ); |
|
21
|
|
|
|
|
29
|
|
|
21
|
|
|
|
|
103
|
|
12
|
|
|
|
|
|
|
|
13
|
21
|
|
|
21
|
|
12526
|
use overload '""' => \&stringify, fallback => 1; |
|
21
|
|
|
|
|
32
|
|
|
21
|
|
|
|
|
140
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# cause string overloaded objects (Matchers) to be stringified |
16
|
|
|
|
|
|
|
my $Dumper = Test::Mocha::PartialDump->new( objects => 0, stringify => 1 ); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub new { |
19
|
|
|
|
|
|
|
# uncoverable pod |
20
|
625
|
|
|
625
|
0
|
1261
|
my ( $class, %args ) = @_; |
21
|
|
|
|
|
|
|
### assert: Str->check( $args{name} ) |
22
|
|
|
|
|
|
|
### assert: ArrayRef->check( $args{args} ) |
23
|
625
|
|
|
|
|
1940
|
return bless \%args, $class; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub name { |
27
|
|
|
|
|
|
|
# uncoverable pod |
28
|
3350
|
|
|
3350
|
0
|
9139
|
return $_[0]->{name}; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub args { |
32
|
|
|
|
|
|
|
# uncoverable pod |
33
|
1531
|
|
|
1531
|
0
|
1040
|
return @{ $_[0]->{args} }; |
|
1531
|
|
|
|
|
2817
|
|
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub stringify { |
37
|
|
|
|
|
|
|
# """ |
38
|
|
|
|
|
|
|
# Stringifies this method call to something that roughly resembles what |
39
|
|
|
|
|
|
|
# you'd type in Perl. |
40
|
|
|
|
|
|
|
# """ |
41
|
|
|
|
|
|
|
# uncoverable pod |
42
|
281
|
|
|
281
|
0
|
6924
|
my ($self) = @_; |
43
|
281
|
|
|
|
|
421
|
return $self->name . '(' . $Dumper->dump( $self->args ) . ')'; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
my $Slurp = sub { |
47
|
|
|
|
|
|
|
# """check slurpy arguments""" |
48
|
|
|
|
|
|
|
my ( $slurpy_matcher, @to_match ) = @_; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
### assert: Slurpy->check($slurpy_matcher) |
51
|
|
|
|
|
|
|
my $matcher = $slurpy_matcher->{slurpy}; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
my $value; |
54
|
|
|
|
|
|
|
if ( $matcher->is_a_type_of(ArrayRef) ) { |
55
|
|
|
|
|
|
|
$value = [@to_match]; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
elsif ( $matcher->is_a_type_of(HashRef) ) { |
58
|
|
|
|
|
|
|
return unless scalar(@to_match) % 2 == 0; |
59
|
|
|
|
|
|
|
$value = {@to_match}; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
else { |
62
|
|
|
|
|
|
|
croak 'Slurpy argument must be a type of ArrayRef or HashRef'; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
return $matcher->check($value); |
66
|
|
|
|
|
|
|
}; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub satisfied_by { |
69
|
|
|
|
|
|
|
# """ |
70
|
|
|
|
|
|
|
# Returns true if the given C<$invocation> satisfies this method call. |
71
|
|
|
|
|
|
|
# """ |
72
|
|
|
|
|
|
|
# uncoverable pod |
73
|
1167
|
|
|
1167
|
0
|
1021
|
my ( $self, $invocation ) = @_; |
74
|
|
|
|
|
|
|
|
75
|
1167
|
100
|
|
|
|
1364
|
return unless $invocation->name eq $self->name; |
76
|
|
|
|
|
|
|
|
77
|
625
|
|
|
|
|
998
|
my @expected = $self->args; |
78
|
625
|
|
|
|
|
773
|
my @input = $invocation->args; |
79
|
|
|
|
|
|
|
# invocation arguments can't be argument matchers |
80
|
|
|
|
|
|
|
### assert: ! grep { Matcher->check($_) } @input |
81
|
|
|
|
|
|
|
|
82
|
625
|
|
100
|
|
|
1973
|
while ( @input && @expected ) { |
83
|
528
|
|
|
|
|
606
|
my $matcher = shift @expected; |
84
|
|
|
|
|
|
|
|
85
|
528
|
100
|
|
|
|
953
|
if ( Slurpy->check($matcher) ) { |
|
|
100
|
|
|
|
|
|
86
|
123
|
100
|
|
|
|
2892
|
croak 'No arguments allowed after a slurpy type constraint' |
87
|
|
|
|
|
|
|
unless @expected == 0; |
88
|
|
|
|
|
|
|
|
89
|
122
|
100
|
|
|
|
198
|
return unless $Slurp->( $matcher, @input ); |
90
|
|
|
|
|
|
|
|
91
|
70
|
|
|
|
|
687
|
@input = (); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
elsif ( Matcher->check($matcher) ) { |
94
|
117
|
100
|
|
|
|
3219
|
return unless $matcher->check( shift @input ); |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
else { |
97
|
288
|
100
|
|
|
|
4159
|
return unless match( shift(@input), $matcher ); |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
# slurpy matcher should handle empty argument lists |
102
|
395
|
100
|
100
|
|
|
2823
|
if ( @expected > 0 && Slurpy->check( $expected[0] ) ) { |
103
|
17
|
|
|
|
|
442
|
my $matcher = shift @expected; |
104
|
|
|
|
|
|
|
|
105
|
17
|
100
|
|
|
|
158
|
croak 'No arguments allowed after a slurpy type constraint' |
106
|
|
|
|
|
|
|
unless @expected == 0; |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
# uncoverable branch true |
109
|
16
|
50
|
|
|
|
29
|
return unless $Slurp->( $matcher, @input ); |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
394
|
|
100
|
|
|
2187
|
return @input == 0 && @expected == 0; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
1; |