| 1 | package VS::RuleEngine::InputHandler; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 33 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 33 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 33 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 33 | ▶ | use Scalar::Util qw(refaddr blessed); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 33 | my %Global; | |||||||||||||||||||||||||||
| 10 | my %Local; | ||||||||||||||||||||||||||||
| 11 | 33 | my %InputCache; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 35 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 14 | 35 | my ($pkg, %inputs) = @_; | |||||||||||||||||||||||||||
| 15 | 35 | my $self = bless \%inputs, $pkg; | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 35 | $InputCache{refaddr $self} = {}; | |||||||||||||||||||||||||||
| 18 | 35 | $Global{refaddr $self} = undef; | |||||||||||||||||||||||||||
| 19 | 35 | $Local{refaddr $self} = undef; | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 35 | return $self; | |||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 36 | ▶ | sub _clear { | ||||||||||||||||||||||||||
|
Subroutine
_clear: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 25 | 36 | my $self = shift; | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 36 | my $caller = caller; | |||||||||||||||||||||||||||
| 28 | 36 | ▶ | croak "You are not allowed to clear the input" if $caller ne "VS::RuleEngine::Runloop"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 35 | $InputCache{refaddr $self} = {}; | |||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 36 | ▶ | sub set_global { | ||||||||||||||||||||||||||
|
Subroutine
set_global: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 34 | 36 | my ($self, $global) = @_; | |||||||||||||||||||||||||||
| 35 | 36 | ▶ | croak "Not a VS::RuleEngine::Data instance" unless blessed $global && $global->isa("VS::RuleEngine::Data"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
builtin::blessed($global) and $global->isa("VS::RuleEngine::Data")
MC/DC50%1/2
builtin::blessed($global) and $global->isa("VS::RuleEngine::Data")
builtin::blessed($global)
$global->isa("VS::RuleEngine::Data")
Truth table66%2/3
A and B
A= builtin::blessed($global)B= $global->isa("VS::RuleEngine::Data")
| |||||||||||||||||||||||||||||
| 36 | 35 | $Global{refaddr $self} = $global; | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 36 | ▶ | sub set_local { | ||||||||||||||||||||||||||
|
Subroutine
set_local: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 40 | 36 | my ($self, $local) = @_; | |||||||||||||||||||||||||||
| 41 | 36 | ▶ | croak "Not a VS::RuleEngine::Data instance" unless blessed $local && $local->isa("VS::RuleEngine::Data"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
builtin::blessed($local) and $local->isa("VS::RuleEngine::Data")
MC/DC50%1/2
builtin::blessed($local) and $local->isa("VS::RuleEngine::Data")
builtin::blessed($local)
$local->isa("VS::RuleEngine::Data")
Truth table66%2/3
A and B
A= builtin::blessed($local)B= $local->isa("VS::RuleEngine::Data")
| |||||||||||||||||||||||||||||
| 42 | 35 | $Local{refaddr $self} = $local; | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 35 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 46 | 35 | my $self = shift; | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 35 | delete $InputCache{refaddr $self}; | |||||||||||||||||||||||||||
| 49 | 35 | delete $Global{refaddr $self}; | |||||||||||||||||||||||||||
| 50 | 35 | delete $Local{refaddr $self}; | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 38 | ▶ | sub get { | ||||||||||||||||||||||||||
|
Subroutine
get: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 54 | 38 | my $self = shift; | |||||||||||||||||||||||||||
| 55 | 38 | my $input = shift; | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 38 | my $addr = refaddr $self; | |||||||||||||||||||||||||||
| 58 | 38 | my $cache = $InputCache{$addr}; | |||||||||||||||||||||||||||
| 59 | 38 | ▶ | if (exists $cache->{$input}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 2 | return $cache->{$input}; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 36 | ▶ | croak "I don't know anything about '${input}'" if !exists $self->{$input}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 36 | my $input_obj = $self->{$input}; | |||||||||||||||||||||||||||
| 66 | 36 | my $value = $input_obj->value($self, $Global{$addr}, $Local{$addr}); | |||||||||||||||||||||||||||
| 67 | 36 | $cache->{$input} = $value; | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 36 | return $value; | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 33 | 1; | |||||||||||||||||||||||||||
| 73 | __END__ | ||||||||||||||||||||||||||||