line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package VS::RuleEngine::Rule::InputOverThreshold; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
2272
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
5
|
use VS::RuleEngine::Constants; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
68
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
5
|
use base qw(VS::RuleEngine::Rule); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
318
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
11
|
7
|
|
|
7
|
1
|
18
|
my ($pkg, %args) = @_; |
12
|
7
|
|
|
|
|
27
|
my $self = bless { %args }, $pkg; |
13
|
7
|
|
|
|
|
26
|
return $self; |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub evaluate { |
17
|
7
|
|
|
7
|
1
|
7
|
my ($self, $input) = @_; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# If we have nothing to match aginst it's a no match |
20
|
7
|
50
|
|
|
|
6
|
return KV_NO_MATCH unless %{$self}; |
|
7
|
|
|
|
|
21
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# The order we evaulate each change in is not relevant |
23
|
7
|
|
|
|
|
9
|
for my $key (keys %{$self}) { |
|
7
|
|
|
|
|
19
|
|
24
|
16
|
|
50
|
|
|
40
|
my $v1 = $input->get($key) || 0; |
25
|
|
|
|
|
|
|
|
26
|
16
|
50
|
|
|
|
24
|
if (!$v1) { |
27
|
0
|
|
|
|
|
0
|
return KV_NO_MATCH; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
16
|
|
|
|
|
19
|
my $change = $self->{$key}; |
31
|
|
|
|
|
|
|
|
32
|
16
|
100
|
66
|
|
|
75
|
if ($change && ($v1 / $change) < 1) { |
33
|
3
|
|
|
|
|
9
|
return KV_NO_MATCH; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# All thresholds passed therefore we have a match |
38
|
4
|
|
|
|
|
11
|
return KV_MATCH; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
1; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 NAME |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
VS::RuleEngine::Rule::InputOverThreshold - Generic rule for checking input thresholds |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head1 SYNOPSIS |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
use VS::RuleEngine::Declare; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
my $engine = engine { |
52
|
|
|
|
|
|
|
rule 'valid_name' => instanceof "VS::RuleEngine::Rule::InputOverThreshold" => with_args { |
53
|
|
|
|
|
|
|
'input_1' => 5, |
54
|
|
|
|
|
|
|
'input_2' => -5, |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head1 DESCRIPTION |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
This is a generic rule that checks if the value from an input is equal or passes a |
61
|
|
|
|
|
|
|
threshold relative to 0. This can be used to model change matrices where a row |
62
|
|
|
|
|
|
|
represets a rule. |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
The following table shows the conditions when it matches |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
Input | Threshold | Result |
67
|
|
|
|
|
|
|
------+-----------+------- |
68
|
|
|
|
|
|
|
x | 0 | match |
69
|
|
|
|
|
|
|
>= y | y > 0 | match |
70
|
|
|
|
|
|
|
>= y | y < 0 | no match |
71
|
|
|
|
|
|
|
<= y | y < 0 | match |
72
|
|
|
|
|
|
|
<= y | y > 0 | no match |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head1 USAGE |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head2 Rule arguments |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
This rule expects a hash reference as its argument, which is what C<< with_args >> provides, |
79
|
|
|
|
|
|
|
where the key is the name of an input and the value is the expected threshold value. |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=begin PRIVATE |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=over 4 |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=item new |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
L |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=item evaluate |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
L |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=back |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=end PRIVATE |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=cut |