TopicStore.pm

filter: Statementstmt 94.7% 36 / 38 Branchbran 80.0% 8 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 85.7% 6 / 7 Podpod 100% 4 / 4 totaltotal 91.5% 54 / 59 CC 8 SCAR 9.7
CC
8
Cov
92%
values
4.0
_topic_to_regexp
3.0
add
2.0
CRAP 2.6
« Message.pm ↑ Summary Message/Connect.pm »
1 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package Net::MQTT::TopicStore;
4 1 $Net::MQTT::TopicStore::VERSION = '1.143250';
5 # ABSTRACT: Perl module to represent MQTT topic store
6  
7  
8 sub new {
9 9 ▶ my $pkg = shift;
Subroutine new: called CC=2 SCAR=6.9
Pod documented
10 9 my $self = bless { topics => { } }, $pkg;
11 9 $self->add($_) foreach (@_);
12 9 $self
13 }
14  
15  
16 sub add {
17 10 ▶ my ($self, $topic_pattern) = @_;
Subroutine add: called CC=2 SCAR=7.0
Pod documented
18 10 ▶ unless (exists $self->{topics}->{$topic_pattern}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"topics"}{$topic_pattern}) 10 0 10
19 10 $self->{topics}->{$topic_pattern} = _topic_to_regexp($topic_pattern);
20 }
21 $topic_pattern
22 10 }
23  
24  
25 sub delete {
26 0 ▶ my ($self, $topic) = @_;
Subroutine delete: not called CC=1 SCAR=6.9
Pod documented
27 0 delete $self->{topics}->{$topic};
28 }
29  
30  
31 sub values {
32 19 ▶ my ($self, $topic) = @_;
Subroutine values: called CC=4 SCAR=13.9
Pod documented
33 19 my @res = ();
34 19 foreach my $t (keys %{$self->{topics}}) {
35 20 my $re = $self->{topics}->{$t};
36 20 ▶ next unless (defined $re ? $topic =~ $re : $topic eq $t);
Branch: 2 branches
BranchTrueFalseTotal
unless defined $re ? $topic =~ /$re/ : $topic eq $t 7 13 20
defined $re ? : 19 1 20
37 13 push @res, $t;
38 }
39 19 return \@res;
40 }
41  
42 sub _topic_to_regexp {
43 10 ▶ my $topic = shift;
Subroutine _topic_to_regexp: called CC=3 SCAR=11.0
44 10 my $c;
45 10 $topic = quotemeta $topic;
46 10 $c += ($topic =~ s!\\/\\\+!\\/[^/]*!g);
47 10 $c += ($topic =~ s!\\/\\#$!(?:\$|/.*)!);
48 10 $c += ($topic =~ s!^\\\+\\/![^/]*\\/!g);
49 10 $c += ($topic =~ s!^\\\+$![^/]*!g);
50 10 $c += ($topic =~ s!^\\#$!.*!);
51 10 ▶ $topic .= '$' unless ($topic =~ m!\$$!);
Branch: 1 branch
BranchTrueFalseTotal
unless $topic =~ /\$$/ 10 0 10
52 10 ▶ unless ($c) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($c) 1 9 10
53 1 return;
54 }
55 qr/^$topic/
56 9 }
57  
58 1 1;
59  
60 __END__
« Message.pm ↑ Summary Message/Connect.pm »