Regexp.pm

filter: Statementstmt 92.6% 63 / 68 Branchbran 75.0% 3 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 78.9% 15 / 19 Podpod 0.0% 0 / 1 totaltotal 88.0% 81 / 92 CC 4 SCAR 5.5
CC
4
Cov
92%
filter
4.0
__ANON__
2.0
__ANON__
2.0
CRAP 1.7
↑ Summary Regexp/Log.pm »
1 package Message::Passing::Filter::Regexp;
2 1 ▶use 5.014002;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use MooX::Types::MooseLike::Base qw/ HashRef ArrayRef Str RegexpRef /;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use namespace::clean -except => 'meta';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use JSON::Types;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Message::Passing::Filter::Regexp::Log;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 with qw/ Message::Passing::Role::Filter /;
13 1 ▶use vars qw( $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 1 $VERSION = 0.05;
16  
17 has format => (
18 is => 'ro',
19 isa => Str,
20 0 ▶ default => sub { ':default' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
21 1 );
22  
23 has regexfile => (
24 is => 'ro',
25 isa => Str,
26 0 ▶ default => sub { '/etc/message-passing/regexfile' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
27 1 );
28  
29 has capture => (
30 is => 'ro',
31 isa => ArrayRef,
32 0 ▶ default => sub { [] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
33 1 );
34  
35 has mutate => (
36 is => 'ro',
37 isa => HashRef,
38 0 ▶ default => sub { {} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
39 1 );
40  
41 has fromto => (
42 is => 'ro',
43 isa => HashRef,
44 1 ▶ default => sub { { '@message' => '@fields' } },
Subroutine __ANON__: called CC=1 SCAR=0.0
45 1 );
46  
47 1 has _regex => (
48 is => 'ro',
49 lazy => 1,
50 builder => '_build_regex',
51 );
52  
53 1 has _re => (
54 is => 'ro',
55 isa => RegexpRef,
56 lazy => 1,
57 builder => '_build_re',
58 );
59  
60 1 has _fields => (
61 is => 'ro',
62 isa => ArrayRef,
63 lazy => 1,
64 builder => '_build_fields',
65 );
66  
67 1 ▶sub _build_regex {
Subroutine _build_regex: called CC=1 SCAR=0.0
68 1 my $self = shift;
69 1 Message::Passing::Filter::Regexp::Log->new(
70 format => $self->format,
71 capture => $self->capture,
72 regexfile => $self->regexfile,
73 );
74 }
75  
76 1 ▶sub _build_re {
Subroutine _build_re: called CC=1 SCAR=0.0
77 1 my $self = shift;
78 1 return $self->_regex->regexp;
79 }
80  
81 1 ▶sub _build_fields {
Subroutine _build_fields: called CC=1 SCAR=0.0
82 1 my $self = shift;
83 1 return [ $self->_regex->capture ];
84 }
85  
86 1 ▶sub filter {
Subroutine filter: called CC=4 SCAR=13.9
Pod undocumented
87 1 my ( $self, $message ) = @_;
88  
89 1 ▶ while ( my ( $from, $to ) = each %{ $self->fromto } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$self->fromto;}) 1 1 2
90 1 my $log_line = $message->{$from};
91 1 my %data;
92 1 my $re = $self->_re;
93 1 @data{ @{ $self->_fields } } = $log_line =~ /$re/;
94 1 for ( keys %{ $self->mutate } ) {
95 1 my $type = $self->mutate->{$_};
96 1 $data{$_} = eval "$type $data{$_}";
97 }
98 1 ▶ if ( defined $to ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $to) { } 1 0 1
99 1 $message->{$to} = {%data};
100 }
101 # put parsed fields directly in message hashref
102 else {
103 0 %$message = ( %$message, %data );
104 }
105 }
106  
107 1 return $message;
108 }
109  
110 1 1;
111  
112 1 1;
113 __END__
↑ Summary Regexp/Log.pm »