| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Message::Match; |
|
2
|
|
|
|
|
|
|
{ |
|
3
|
|
|
|
|
|
|
$Message::Match::VERSION = '1.132270'; |
|
4
|
|
|
|
|
|
|
} |
|
5
|
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
16886
|
use strict;use warnings; |
|
|
2
|
|
|
2
|
|
3
|
|
|
|
2
|
|
|
|
|
64
|
|
|
|
2
|
|
|
|
|
10
|
|
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
90
|
|
|
7
|
|
|
|
|
|
|
require Exporter; |
|
8
|
2
|
|
|
2
|
|
10
|
use vars qw(@ISA @EXPORT_OK); |
|
|
2
|
|
|
|
|
8
|
|
|
|
2
|
|
|
|
|
510
|
|
|
9
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
|
10
|
|
|
|
|
|
|
@EXPORT_OK = qw(mmatch); |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $named_regex = {}; |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub mmatch { |
|
15
|
30
|
|
|
30
|
1
|
2717
|
my ($message, $match) = @_; |
|
16
|
30
|
100
|
100
|
|
|
305
|
die 'Message::Match::mmatch: two HASH references required' |
|
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
17
|
|
|
|
|
|
|
if scalar @_ < 2 or |
|
18
|
|
|
|
|
|
|
scalar @_ > 2 or |
|
19
|
|
|
|
|
|
|
not ref $message or |
|
20
|
|
|
|
|
|
|
not ref $match or |
|
21
|
|
|
|
|
|
|
ref $message ne 'HASH' or |
|
22
|
|
|
|
|
|
|
ref $match ne 'HASH'; |
|
23
|
|
|
|
|
|
|
|
|
24
|
24
|
|
|
|
|
33
|
return _match($message, $match); |
|
25
|
|
|
|
|
|
|
} |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub _special { |
|
28
|
5
|
|
|
5
|
|
5
|
my ($message, $match) = @_; |
|
29
|
5
|
|
|
|
|
8
|
substr($match, 0, 8, ''); |
|
30
|
5
|
100
|
|
|
|
13
|
if($match =~ m{^/}) { #regex type |
|
31
|
4
|
|
|
|
|
3
|
my $re; |
|
32
|
4
|
|
|
|
|
271
|
eval "\$re = qr$match;"; #this is hideously inefficient |
|
33
|
|
|
|
|
|
|
#but it is highly cacheable, later on |
|
34
|
4
|
100
|
|
|
|
20
|
if($message =~ $re) { |
|
35
|
2
|
50
|
|
2
|
|
1104
|
if(%+) { |
|
|
2
|
|
|
|
|
991
|
|
|
|
2
|
|
|
|
|
776
|
|
|
|
2
|
|
|
|
|
11
|
|
|
36
|
0
|
|
|
|
|
0
|
while(my($key, $value) = each %+) { |
|
37
|
0
|
|
|
|
|
0
|
$named_regex->{$key} = $value; |
|
38
|
|
|
|
|
|
|
} |
|
39
|
|
|
|
|
|
|
} |
|
40
|
2
|
|
|
|
|
9
|
return 1 |
|
41
|
|
|
|
|
|
|
} else { |
|
42
|
2
|
|
|
|
|
13
|
return 0; |
|
43
|
|
|
|
|
|
|
} |
|
44
|
|
|
|
|
|
|
} |
|
45
|
1
|
|
|
|
|
11
|
die "Message::Match::mmatch: special of unknown type passed: $match"; |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub _match { |
|
49
|
56
|
|
|
56
|
|
35
|
my ($message, $match) = @_; |
|
50
|
56
|
|
|
|
|
40
|
my $ref_message = ref $message; my $ref_match = ref $match; |
|
|
56
|
|
|
|
|
51
|
|
|
51
|
56
|
50
|
66
|
|
|
80
|
if(not $ref_message and not $ref_match) { #scalar on both sides |
|
52
|
21
|
100
|
|
|
|
33
|
if(substr($match, 0, 8) eq ' special') { #special handling |
|
53
|
5
|
|
|
|
|
7
|
return _special($message, $match); |
|
54
|
|
|
|
|
|
|
} |
|
55
|
16
|
|
|
|
|
50
|
return $message eq $match; #otherwise, brain-dead comparison |
|
56
|
|
|
|
|
|
|
} |
|
57
|
35
|
50
|
33
|
|
|
52
|
if($ref_message eq 'JSON::PP::Boolean' and $ref_match eq 'JSON::PP::Boolean') { |
|
58
|
0
|
|
|
|
|
0
|
return "$message" eq "$match"; |
|
59
|
|
|
|
|
|
|
} |
|
60
|
35
|
100
|
66
|
|
|
86
|
if($ref_message eq 'HASH' and $ref_match eq 'HASH') { |
|
61
|
31
|
|
|
|
|
56
|
foreach my $key (keys %$match) { |
|
62
|
28
|
|
|
|
|
25
|
my $message = $message->{$key}; |
|
63
|
28
|
|
|
|
|
17
|
my $match = $match->{$key}; |
|
64
|
28
|
100
|
|
|
|
44
|
return 0 if not defined $message; |
|
65
|
26
|
50
|
|
|
|
27
|
return 0 if not defined $match; |
|
66
|
26
|
100
|
|
|
|
30
|
return 0 unless _match($message, $match); |
|
67
|
|
|
|
|
|
|
} |
|
68
|
24
|
|
|
|
|
69
|
return 1; |
|
69
|
|
|
|
|
|
|
} |
|
70
|
4
|
100
|
66
|
|
|
14
|
if($ref_message eq 'ARRAY' and not $ref_match) { #check for scalar inside the array |
|
71
|
2
|
|
|
|
|
2
|
foreach my $item (@$message) { |
|
72
|
5
|
100
|
|
|
|
12
|
return 1 if $item eq $match; |
|
73
|
|
|
|
|
|
|
} |
|
74
|
1
|
|
|
|
|
6
|
return 0; |
|
75
|
|
|
|
|
|
|
} |
|
76
|
2
|
50
|
33
|
|
|
9
|
if($ref_message eq 'ARRAY' and $ref_match eq 'ARRAY') { #check the entire array |
|
77
|
2
|
|
|
|
|
2
|
foreach my $item (@$match) { |
|
78
|
6
|
|
|
|
|
6
|
my $match = $item; |
|
79
|
6
|
|
|
|
|
4
|
my $message = shift @{$message}; |
|
|
6
|
|
|
|
|
7
|
|
|
80
|
6
|
50
|
|
|
|
6
|
return 0 unless _match($message, $match); |
|
81
|
|
|
|
|
|
|
} |
|
82
|
2
|
|
|
|
|
4
|
return 1; |
|
83
|
|
|
|
|
|
|
} |
|
84
|
0
|
0
|
0
|
|
|
|
if($ref_message eq 'ARRAY' and $ref_match eq 'HASH') { |
|
85
|
|
|
|
|
|
|
#The idea is that if a message field is an array, and the |
|
86
|
|
|
|
|
|
|
#match field is a hash, every element in the array must have a key in the |
|
87
|
|
|
|
|
|
|
#hash in order to pass |
|
88
|
0
|
|
|
|
|
|
foreach my $item (@$message) { |
|
89
|
0
|
0
|
|
|
|
|
return 0 unless defined $match->{$item}; |
|
90
|
|
|
|
|
|
|
} |
|
91
|
0
|
|
|
|
|
|
return 1; |
|
92
|
|
|
|
|
|
|
} |
|
93
|
0
|
|
|
|
|
|
return 0; #anything we don't know about fails |
|
94
|
|
|
|
|
|
|
} |
|
95
|
|
|
|
|
|
|
1; |
|
96
|
|
|
|
|
|
|
__END__ |