line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
15817
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
31
|
|
2
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
328
|
|
3
|
|
|
|
|
|
|
package Net::MQTT::TopicStore; |
4
|
|
|
|
|
|
|
$Net::MQTT::TopicStore::VERSION = '1.143250'; |
5
|
|
|
|
|
|
|
# ABSTRACT: Perl module to represent MQTT topic store |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub new { |
9
|
9
|
|
|
9
|
1
|
894
|
my $pkg = shift; |
10
|
9
|
|
|
|
|
28
|
my $self = bless { topics => { } }, $pkg; |
11
|
9
|
|
|
|
|
21
|
$self->add($_) foreach (@_); |
12
|
9
|
|
|
|
|
31
|
$self |
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub add { |
17
|
10
|
|
|
10
|
1
|
15
|
my ($self, $topic_pattern) = @_; |
18
|
10
|
50
|
|
|
|
23
|
unless (exists $self->{topics}->{$topic_pattern}) { |
19
|
10
|
|
|
|
|
13
|
$self->{topics}->{$topic_pattern} = _topic_to_regexp($topic_pattern); |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
$topic_pattern |
22
|
10
|
|
|
|
|
26
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub delete { |
26
|
0
|
|
|
0
|
1
|
0
|
my ($self, $topic) = @_; |
27
|
0
|
|
|
|
|
0
|
delete $self->{topics}->{$topic}; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub values { |
32
|
19
|
|
|
19
|
1
|
2329
|
my ($self, $topic) = @_; |
33
|
19
|
|
|
|
|
23
|
my @res = (); |
34
|
19
|
|
|
|
|
17
|
foreach my $t (keys %{$self->{topics}}) { |
|
19
|
|
|
|
|
52
|
|
35
|
20
|
|
|
|
|
22
|
my $re = $self->{topics}->{$t}; |
36
|
20
|
100
|
|
|
|
139
|
next unless (defined $re ? $topic =~ $re : $topic eq $t); |
|
|
100
|
|
|
|
|
|
37
|
13
|
|
|
|
|
30
|
push @res, $t; |
38
|
|
|
|
|
|
|
} |
39
|
19
|
|
|
|
|
44
|
return \@res; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub _topic_to_regexp { |
43
|
10
|
|
|
10
|
|
11
|
my $topic = shift; |
44
|
10
|
|
|
|
|
9
|
my $c; |
45
|
10
|
|
|
|
|
12
|
$topic = quotemeta $topic; |
46
|
10
|
|
|
|
|
21
|
$c += ($topic =~ s!\\/\\\+!\\/[^/]*!g); |
47
|
10
|
|
|
|
|
19
|
$c += ($topic =~ s!\\/\\#$!(?:\$|/.*)!); |
48
|
10
|
|
|
|
|
12
|
$c += ($topic =~ s!^\\\+\\/![^/]*\\/!g); |
49
|
10
|
|
|
|
|
12
|
$c += ($topic =~ s!^\\\+$![^/]*!g); |
50
|
10
|
|
|
|
|
12
|
$c += ($topic =~ s!^\\#$!.*!); |
51
|
10
|
50
|
|
|
|
22
|
$topic .= '$' unless ($topic =~ m!\$$!); |
52
|
10
|
100
|
|
|
|
18
|
unless ($c) { |
53
|
1
|
|
|
|
|
4
|
return; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
qr/^$topic/ |
56
|
9
|
|
|
|
|
174
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
1; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
__END__ |