Passing/Filter/Key.pm

filter: Statementstmt 96.6% 29 / 30 Branchbran 87.5% 7 / 8 Conditioncond 81.8% 9 / 11 MC/DCmcdc 66.6% 4 / 6 Subroutinesub 100% 6 / 6 Podpod 100% 1 / 1 totaltotal 90.3% 56 / 62 SCAR 22.0
CC
9
Cov
92%
filter
8.0
__ANON__
2.1
BEGIN
1.0
CRAP 9.0
« Passing/DSL.pm ↑ Summary Passing/Filter/ToLogstash.pm »
1 package Message::Passing::Filter::Key;
2 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use MooX::Types::MooseLike::Base qw/ Str /;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use namespace::clean -except => 'meta';
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 with 'Message::Passing::Role::Filter';
7  
8 1 has key => (
9 isa => Str,
10 is => 'ro',
11 required => 1,
12 );
13  
14 1 has match => (
15 isa => Str,
16 is => 'ro',
17 required => 1,
18 );
19  
20 has match_type => (
21 is => 'ro',
22 # isa => enum(['regex', 'eq']),
23 2 ▶ default => sub { 'eq' },
Subroutine __ANON__: called CC=1 SCAR=0.0
24 1 );
25  
26 has _re => (
27 is => 'ro',
28 lazy => 1,
29 default => sub {
30 2 ▶ my $self = shift;
Subroutine __ANON__: called CC=2 SCAR=7.4
31 2 my $match = $self->match;
32 2 ▶ if ($self->match_type eq 'regex') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->match_type eq 'regex') { } 0 2 2
33 0 return qr/$match/;
34 }
35 else {
36 2 return qr/^\Q$match\E$/;
37 }
38 },
39 1 );
40  
41 sub filter {
42 6 ▶ my ($self, $message) = @_;
Subroutine filter: called CC=8 SCAR=20.8
Pod documented
43 6 my $re = $self->_re;
44 6 my @key_parts = split /\./, $self->key;
45 6 my $m = $message;
46 6 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
$m and scalar @key_parts and do { do { my $part = shift @key_parts; $m = ref $m eq "HASH" && exists $m->{$part} ? $m->{$part} : undef } } 7 6 13
Condition100%2/2
$m and scalar @key_parts
!ll
211
MC/DC100%1/1
$m and scalar @key_parts
$m
Truth table100%2/2
A
A= $m
Aresult
00
11
47 13 my $part = shift(@key_parts);
48 13 ▶ $m = (ref($m) eq 'HASH' && exists($m->{$part})) ? $m->{$part} : undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $m eq 'HASH' && exists $m->{$part} ? : 11 2 13
Condition66%2/3
ref $m eq "HASH" and exists $m->{$part}
!ll&&!rl&&r
2011
MC/DC50%1/2
ref $m eq "HASH" and exists $m->{$part}
ref $m eq "HASH" exists $m->{$part}
Truth table66%2/3
A and B
A= ref $m eq "HASH"B= exists $m->{$part}
ABresult
0X0
100
111
49 } while ($m && scalar(@key_parts));
50 6 ▶ return unless $m && !ref($m) && $m =~ /$re/;
Branch: 1 branch
BranchTrueFalseTotal
unless $m and not ref $m and $m =~ /$re/ 2 2 4
Condition83%5/6
$m and not ref $m and $m =~ /$re/
!ll&&!rl&&r
222
$m and not ref $m
!ll&&!rl&&r
204
MC/DC66%2/3
$m and not ref $m and $m =~ /$re/
$m not ref $m $m =~ /$re/
Truth table75%3/4
A and not(B) and C
A= $mB= not ref $mC= $m =~ /$re/
ABCresult
0XX0
10X0
1100
1111
51 2 return $message;
52 }
53  
54  
55 1 1;
56  
57 =head1 NAME
58  
59 Message::Passing::Filter::Key - Filter a subset of messages out.
60  
61 =head1 DESCRIPTION
62  
63 This filter just removes messages which do not have a key matching a certain value.
64  
65 =head1 ATTRIBUTES
66  
67 =head2 key
68  
69 The name of the key. You may use a C< foo.bar > syntax to indicate variables below the top level
70 of the hash (i.e. the example would look in C<< $msg->{foo}->{bar} >>.).
71  
72 =head2 match
73  
74 The value to match to determine if the message should be passed onto the next stage or filtered out.
75  
76 =head2 match_type
77  
78 The type of match to perform, valid values are 'regex' or 'eq', and the latter is the default.
79  
80 =head1 METHODS
81  
82 =head2 filter
83  
84 Does the actual filtering work.
85  
86 =head1 SPONSORSHIP
87  
88 This module exists due to the wonderful people at Suretec Systems Ltd.
89 <http://www.suretecsystems.com/> who sponsored its development for its
90 VoIP division called SureVoIP <http://www.surevoip.co.uk/> for use with
91 the SureVoIP API -
92 <http://www.surevoip.co.uk/support/wiki/api_documentation>
93  
94 =head1 AUTHOR, COPYRIGHT AND LICENSE
95  
96 See L<Message::Passing>.
97  
98 =cut
« Passing/DSL.pm ↑ Summary Passing/Filter/ToLogstash.pm »