line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package match::simple; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
72094
|
use 5.006001; |
|
2
|
|
|
|
|
18
|
|
4
|
2
|
|
|
2
|
|
17
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
38
|
|
5
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
61
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
933
|
use Exporter::Tiny; |
|
2
|
|
|
|
|
6603
|
|
|
2
|
|
|
|
|
12
|
|
8
|
2
|
|
|
2
|
|
280
|
use List::Util 1.33 qw( any ); |
|
2
|
|
|
|
|
39
|
|
|
2
|
|
|
|
|
213
|
|
9
|
2
|
|
|
2
|
|
15
|
use Scalar::Util qw( blessed ); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
113
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
BEGIN { |
12
|
2
|
|
|
2
|
|
6
|
$match::simple::AUTHORITY = 'cpan:TOBYINK'; |
13
|
2
|
|
|
|
|
509
|
$match::simple::VERSION = '0.011'; |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our @ISA = qw( Exporter::Tiny ); |
17
|
|
|
|
|
|
|
our @EXPORT = qw( M ); |
18
|
|
|
|
|
|
|
our @EXPORT_OK = qw( match ); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
my $xs; |
21
|
|
|
|
|
|
|
unless (($ENV{MATCH_SIMPLE_IMPLEMENTATION}||'') =~ /pp/i) { |
22
|
|
|
|
|
|
|
eval { |
23
|
|
|
|
|
|
|
require match::simple::XS; |
24
|
|
|
|
|
|
|
match::simple::XS->VERSION( 0.002 ); # minimum |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# Unless we're a development version... |
27
|
|
|
|
|
|
|
# Avoid using an unstable version of ::XS |
28
|
|
|
|
|
|
|
unless (match::simple->VERSION =~ /_/) { |
29
|
|
|
|
|
|
|
die if match::simple::XS->VERSION =~ /_/; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
$xs = match::simple::XS->can('match'); |
33
|
|
|
|
|
|
|
}; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
eval($xs ? <<'XS' : <<'PP'); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub IMPLEMENTATION () { "XS" } |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
*match = *match::simple::XS::match; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
XS |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub IMPLEMENTATION () { "PP" } |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub match { |
47
|
|
|
|
|
|
|
no warnings qw( uninitialized numeric ); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
my ( $a, $b ) = @_; |
50
|
|
|
|
|
|
|
my $method; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
return !defined $a if !defined($b); |
53
|
|
|
|
|
|
|
return $a eq $b if !ref($b); |
54
|
|
|
|
|
|
|
return $a =~ $b if ref($b) eq q(Regexp); |
55
|
|
|
|
|
|
|
return do { local $_ = $a; !!$b->($a) } if ref($b) eq q(CODE); |
56
|
|
|
|
|
|
|
return any { match( $a, $_ ) } @$b if ref($b) eq q(ARRAY); |
57
|
|
|
|
|
|
|
return !!$b->$method( $a, 1 ) if blessed($b) && ( $method = _overloaded_smartmatch( $b ) ); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
require Carp; |
60
|
|
|
|
|
|
|
Carp::croak( "match::simple cannot match anything against: $b" ); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
unless ( eval 'require re; 1' and exists &re::is_regexp ) { |
64
|
|
|
|
|
|
|
require B; |
65
|
|
|
|
|
|
|
*re::is_regexp = sub { |
66
|
|
|
|
|
|
|
eval { B::svref_2object( $_[0] )->MAGIC->TYPE eq 'r' }; |
67
|
|
|
|
|
|
|
}; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub _overloaded_smartmatch { |
71
|
|
|
|
|
|
|
my ( $obj ) = @_; |
72
|
|
|
|
|
|
|
return if re::is_regexp( $obj ); |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
if ( $obj->isa( 'Type::Tiny' ) ) { |
75
|
|
|
|
|
|
|
return $obj->can( 'check' ); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
if ( my $match = $obj->can( 'MATCH' ) ) { |
79
|
|
|
|
|
|
|
return $match; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
if ( $] lt '5.010' ) { require MRO::Compat; } |
83
|
|
|
|
|
|
|
else { require mro; } |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
my @mro = @{ mro::get_linear_isa( ref $obj ) }; |
86
|
|
|
|
|
|
|
for my $class ( @mro ) { |
87
|
|
|
|
|
|
|
my $name = "$class\::(~~"; |
88
|
|
|
|
|
|
|
my $overload = do { |
89
|
|
|
|
|
|
|
no strict 'refs'; |
90
|
|
|
|
|
|
|
exists( &$name ) ? \&$name : undef; |
91
|
|
|
|
|
|
|
}; |
92
|
|
|
|
|
|
|
return $overload if $overload; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
return; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
PP |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub _generate_M { |
101
|
2
|
|
|
2
|
|
1119
|
require Sub::Infix; |
102
|
2
|
|
|
|
|
4251
|
&Sub::Infix::infix( \&match ); |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
1; |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
__END__ |