blib/lib/OPP/Proc/Regex.pm

filter: Statementstmt 41.3% 12 / 29 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 75.0% 3 / 4 Podpod 0.0% 0 / 1 totaltotal 29.4% 15 / 51 CC 10 SCAR 44.4
CC
10
Cov
27%
process
110.0
BEGIN
1.0
BEGIN
1.0
CRAP 84.8
« blib/lib/Onyphe.pm ↑ Summary blib/lib/OPP/Proc.pm »
1 #
2 # $Id: Regex.pm,v df49b574c57c 2023/03/24 06:37:31 gomor $
3 #
4 package OPP::Proc::Regex;
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use base qw(OPP::Proc);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 __PACKAGE__->cgBuildIndices;
10  
11 1 our $VERSION = '1.00';
12  
13 #
14 # | regex data='^.+?Server: (apache)' outputfield=server
15 #
16 sub process {
17 0 ▶ my $self = shift;
Subroutine process: not called CC=10 SCAR=47.0
Pod undocumented
18 0 my ($input) = @_;
19  
20 0 my $options = $self->options;
21 0 ▶ my $outputfield = defined($options->{outputfield}) && $options->{outputfield}[0] || 'regex';
Condition0%0/5
defined $options->{'outputfield'} && $options->{'outputfield'}[0] || 'regex'
l!l
00
defined $options->{"outputfield"} and $options->{"outputfield"}[0]
!ll&&!rl&&r
000
MC/DC0%0/2
defined $options->{'outputfield'} && $options->{'outputfield'}[0] || 'regex'
defined $options->{"outputfield"} $options->{"outputfield"}[0]
Truth table0%0/3
A and B
A= defined $options->{"outputfield"}B= $options->{"outputfield"}[0]
ABresult
111
0X0
100
22 0 for my $o (keys %$options) {
23 0 ▶ next if $o eq 'args'; # Skip original arguments line
Branch: 1 branch
BranchTrueFalseTotal
if $o eq "args" 0 0 0
24 0 ▶ next if $o eq 'outputfield'; # Skip that too
Branch: 1 branch
BranchTrueFalseTotal
if $o eq "outputfield" 0 0 0
25 0 my $values = $self->value($input, $o);
26 0 ▶ next unless $values; # Skip input when no field found
Branch: 1 branch
BranchTrueFalseTotal
unless $values 0 0 0
27 0 my $regex = $options->{$o}; # Example: $regex = [ '^.+?Server: apache' ]
28 0 $regex = $regex->[0]; # Example: $regex '^.+?Server: apache'
29 0 for my $this (@$values) { # Example: $this = 'Server: apache'
30 0 ▶ if ($this =~ m{$regex}si) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this =~ /$regex/is) 0 0 0
31 0 my $capture = $1;
32 0 ▶ $input->{$outputfield} = $capture if defined $capture;
Branch: 1 branch
BranchTrueFalseTotal
if defined $capture 0 0 0
33 0 $self->output->add($input);
34 }
35 }
36 }
37  
38 0 return 1;
39 }
40  
41 1 1;
42  
43 __END__
« blib/lib/Onyphe.pm ↑ Summary blib/lib/OPP/Proc.pm »