| 1 | package VS::RuleEngine::Rule::InputMatchesRegexp; | ||||||||||
| 2 | |||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 2 | ▶ | use VS::RuleEngine::Constants; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 2 | ▶ | use base qw(VS::RuleEngine::Rule); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 4 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 11 | 4 | my ($pkg, %args) = @_; | |||||||||
| 12 | |||||||||||
| 13 | # Compile regexps | ||||||||||
| 14 | 4 | my %re; | |||||||||
| 15 | 4 | ▶ | while (my ($input, $re) = each %args) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 16 | 6 | $re{$input} = $re; | |||||||||
| 17 | } | ||||||||||
| 18 | 4 | my $self = bless { %re }, $pkg; | |||||||||
| 19 | |||||||||||
| 20 | 4 | return $self; | |||||||||
| 21 | } | ||||||||||
| 22 | |||||||||||
| 23 | 4 | ▶ | sub evaluate { | ||||||||
|
Subroutine
evaluate: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||
| 24 | 4 | my ($self, $input) = @_; | |||||||||
| 25 | |||||||||||
| 26 | # If we have nothing to match aginst it's a no match | ||||||||||
| 27 | 4 | ▶ | return KV_NO_MATCH unless %{$self}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 28 | |||||||||||
| 29 | # The order we evaulate each change in is not relevant | ||||||||||
| 30 | 4 | for my $key (keys %{$self}) { | |||||||||
| 31 | 5 | my $v1 = $input->get($key); | |||||||||
| 32 | 5 | my $re = $self->{$key}; | |||||||||
| 33 | |||||||||||
| 34 | 5 | ▶ | if ($v1 !~ $re) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 35 | 2 | return KV_NO_MATCH; | |||||||||
| 36 | } | ||||||||||
| 37 | } | ||||||||||
| 38 | |||||||||||
| 39 | # All thresholds passed therefore we have a match | ||||||||||
| 40 | 2 | return KV_MATCH; | |||||||||
| 41 | } | ||||||||||
| 42 | |||||||||||
| 43 | 2 | 1; | |||||||||
| 44 | __END__ | ||||||||||