| 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'
defined $options->{"outputfield"} and $options->{"outputfield"}[0]
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]
| |||||||||||||||||||||||||
| 22 | 0 | for my $o (keys %$options) { | |||||||||||||||||||||||
| 23 | 0 | ▶ | next if $o eq 'args'; # Skip original arguments line | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 24 | 0 | ▶ | next if $o eq 'outputfield'; # Skip that too | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 25 | 0 | my $values = $self->value($input, $o); | |||||||||||||||||||||||
| 26 | 0 | ▶ | next unless $values; # Skip input when no field found | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||
| 31 | 0 | my $capture = $1; | |||||||||||||||||||||||
| 32 | 0 | ▶ | $input->{$outputfield} = $capture if defined $capture; | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 33 | 0 | $self->output->add($input); | |||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||
| 38 | 0 | return 1; | |||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||
| 41 | 1 | 1; | |||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||
| 43 | __END__ | ||||||||||||||||||||||||