| 1 | package VS::RuleEngine::Action::SetGlobal; | ||||||||||
| 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 Carp qw(croak); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 2 | ▶ | use VS::RuleEngine::Constants; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 2 | ▶ | use base qw(VS::RuleEngine::Action); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 1 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 13 | 1 | my ($pkg, %args) = @_; | |||||||||
| 14 | 1 | my $self = bless \%args, $pkg; | |||||||||
| 15 | 1 | return $self; | |||||||||
| 16 | } | ||||||||||
| 17 | |||||||||||
| 18 | 1 | ▶ | sub perform { | ||||||||
|
Subroutine
perform: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 19 | 1 | my ($self, $global) = @_[KV_SELF, KV_GLOBAL]; | |||||||||
| 20 | |||||||||||
| 21 | 1 | ▶ | while (my ($k, $v) = each %$self) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 22 | 2 | $global->set($k => $v); | |||||||||
| 23 | } | ||||||||||
| 24 | } | ||||||||||
| 25 | |||||||||||
| 26 | 2 | 1; | |||||||||
| 27 | |||||||||||
| 28 | |||||||||||
| 29 | =head1 NAME | ||||||||||
| 30 | |||||||||||
| 31 | VS::RuleEngine::Action::SetGlobal - Generic action to set key/value pairs in the global object | ||||||||||
| 32 | |||||||||||
| 33 | =head1 SYNOPSIS | ||||||||||
| 34 | |||||||||||
| 35 | use VS::RuleEngine::Declare; | ||||||||||
| 36 | |||||||||||
| 37 | my $engine = engine { | ||||||||||
| 38 | # input_1 and input_2 will be set to the global object (KV_GLOBAL) | ||||||||||
| 39 | # every time this action is invoked | ||||||||||
| 40 | action 'set_properties' => instanceof "VS::RuleEngine::Action::SetGlobal" => with_args { | ||||||||||
| 41 | 'input_1' => 5, | ||||||||||
| 42 | 'input_2' => -5, | ||||||||||
| 43 | } | ||||||||||
| 44 | } | ||||||||||
| 45 | |||||||||||
| 46 | =head1 DESCRIPTION | ||||||||||
| 47 | |||||||||||
| 48 | This is a generic action that sets key/value pairs to the global object. Any | ||||||||||
| 49 | existing value for a given key will be overwritten. | ||||||||||
| 50 | |||||||||||
| 51 | =head1 USAGE | ||||||||||
| 52 | |||||||||||
| 53 | =head2 Rule arguments | ||||||||||
| 54 | |||||||||||
| 55 | This rule expects a hash as its argument, which is what C<< with_args >> provides, | ||||||||||
| 56 | where the key is the name of the key to set and the value is its value. | ||||||||||
| 57 | |||||||||||
| 58 | =begin PRIVATE | ||||||||||
| 59 | |||||||||||
| 60 | =over 4 | ||||||||||
| 61 | |||||||||||
| 62 | =item new | ||||||||||
| 63 | |||||||||||
| 64 | L<VS::RuleEngine::Action/new> | ||||||||||
| 65 | |||||||||||
| 66 | =item perform | ||||||||||
| 67 | |||||||||||
| 68 | L<VS::RuleEngine::Action/perform> | ||||||||||
| 69 | |||||||||||
| 70 | =back | ||||||||||
| 71 | |||||||||||
| 72 | =end PRIVATE | ||||||||||
| 73 | |||||||||||
| 74 | =head1 SEE ALSO | ||||||||||
| 75 | |||||||||||
| 76 | L<VS::RuleEngine::Action::SetLocal> | ||||||||||
| 77 | |||||||||||
| 78 | =cut | ||||||||||