line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Message::Match; |
2
|
|
|
|
|
|
|
{ |
3
|
|
|
|
|
|
|
$Message::Match::VERSION = '1.132270'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
33298
|
use strict;use warnings; |
|
2
|
|
|
2
|
|
7
|
|
|
2
|
|
|
|
|
87
|
|
|
2
|
|
|
|
|
12
|
|
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
85
|
|
7
|
|
|
|
|
|
|
require Exporter; |
8
|
2
|
|
|
2
|
|
12
|
use vars qw(@ISA @EXPORT_OK); |
|
2
|
|
|
|
|
21
|
|
|
2
|
|
|
|
|
1331
|
|
9
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
10
|
|
|
|
|
|
|
@EXPORT_OK = qw(mmatch); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub mmatch { |
13
|
30
|
|
|
30
|
1
|
9253
|
my ($message, $match) = @_; |
14
|
30
|
100
|
100
|
|
|
451
|
die 'Message::Match::mmatch: two HASH references required' |
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
100
|
|
|
|
|
15
|
|
|
|
|
|
|
if scalar @_ < 2 or |
16
|
|
|
|
|
|
|
scalar @_ > 2 or |
17
|
|
|
|
|
|
|
not ref $message or |
18
|
|
|
|
|
|
|
not ref $match or |
19
|
|
|
|
|
|
|
ref $message ne 'HASH' or |
20
|
|
|
|
|
|
|
ref $match ne 'HASH'; |
21
|
|
|
|
|
|
|
|
22
|
24
|
|
|
|
|
45
|
return _match($message, $match); |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub _special { |
26
|
5
|
|
|
5
|
|
18
|
my ($message, $match) = @_; |
27
|
5
|
|
|
|
|
11
|
substr($match, 0, 8, ''); |
28
|
5
|
100
|
|
|
|
23
|
if($match =~ m{^/}) { #regex type |
29
|
4
|
|
|
|
|
30
|
my $re; |
30
|
4
|
|
|
|
|
389
|
eval "\$re = qr$match;"; #this is hideously inefficient |
31
|
|
|
|
|
|
|
#but it is highly cacheable, later on |
32
|
4
|
100
|
|
|
|
203
|
if($message =~ $re) { |
33
|
2
|
|
|
|
|
16
|
return 1 |
34
|
|
|
|
|
|
|
} else { |
35
|
2
|
|
|
|
|
22
|
return 0; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
} |
38
|
1
|
|
|
|
|
149
|
die "Message::Match::mmatch: special of unknown type passed: $match"; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub _match { |
42
|
55
|
|
|
55
|
|
84
|
my ($message, $match) = @_; |
43
|
55
|
|
|
|
|
72
|
my $ref_message = ref $message; my $ref_match = ref $match; |
|
55
|
|
|
|
|
142
|
|
44
|
55
|
50
|
66
|
|
|
2243
|
if(not $ref_message and not $ref_match) { #scalar on both sides |
45
|
21
|
100
|
|
|
|
59
|
if(substr($match, 0, 8) eq ' special') { #special handling |
46
|
5
|
|
|
|
|
12
|
return _special($message, $match); |
47
|
|
|
|
|
|
|
} |
48
|
16
|
|
|
|
|
80
|
return $message eq $match; #otherwise, brain-dead comparison |
49
|
|
|
|
|
|
|
} |
50
|
34
|
100
|
66
|
|
|
139
|
if($ref_message eq 'HASH' and $ref_match eq 'HASH') { |
51
|
30
|
|
|
|
|
81
|
foreach my $key (keys %$match) { |
52
|
27
|
|
|
|
|
41
|
my $message = $message->{$key}; |
53
|
27
|
|
|
|
|
39
|
my $match = $match->{$key}; |
54
|
27
|
100
|
|
|
|
59
|
return 0 if not defined $message; |
55
|
25
|
50
|
|
|
|
46
|
return 0 if not defined $match; |
56
|
25
|
100
|
|
|
|
47
|
return 0 unless _match($message, $match); |
57
|
|
|
|
|
|
|
} |
58
|
23
|
|
|
|
|
149
|
return 1; |
59
|
|
|
|
|
|
|
} |
60
|
4
|
100
|
66
|
|
|
21
|
if($ref_message eq 'ARRAY' and not $ref_match) { #check for scalar inside the array |
61
|
2
|
|
|
|
|
4
|
foreach my $item (@$message) { |
62
|
5
|
100
|
|
|
|
17
|
return 1 if $item eq $match; |
63
|
|
|
|
|
|
|
} |
64
|
1
|
|
|
|
|
8
|
return 0; |
65
|
|
|
|
|
|
|
} |
66
|
2
|
50
|
33
|
|
|
26
|
if($ref_message eq 'ARRAY' and $ref_match eq 'ARRAY') { #check the entire array |
67
|
2
|
|
|
|
|
5
|
foreach my $item (@$match) { |
68
|
6
|
|
|
|
|
7
|
my $match = $item; |
69
|
6
|
|
|
|
|
7
|
my $message = shift @{$message}; |
|
6
|
|
|
|
|
9
|
|
70
|
6
|
50
|
|
|
|
12
|
return 0 unless _match($message, $match); |
71
|
|
|
|
|
|
|
} |
72
|
2
|
|
|
|
|
7
|
return 1; |
73
|
|
|
|
|
|
|
} |
74
|
0
|
|
|
|
|
|
return 0; #anything we don't know about fails |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
1; |
77
|
|
|
|
|
|
|
__END__ |