| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%2/2
$m and scalar @key_parts
MC/DC100%1/1
$m and scalar @key_parts
$m
Truth table100%2/2
A
A= $m
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 13 | my $part = shift(@key_parts); | |||||||||||||||||||||||||||||||||||||||||
| 48 | 13 | ▶ | $m = (ref($m) eq 'HASH' && exists($m->{$part})) ? $m->{$part} : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $m eq "HASH" and exists $m->{$part}
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}
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | } while ($m && scalar(@key_parts)); | ||||||||||||||||||||||||||||||||||||||||||
| 50 | 6 | ▶ | return unless $m && !ref($m) && $m =~ /$re/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$m and not ref $m and $m =~ /$re/
$m and not ref $m
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/
| |||||||||||||||||||||||||||||||||||||||||||
| 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 | ||||||||||||||||||||||||||||||||||||||||||