VS::RuleEngine::Action::SetGlobal - Generic action to set key/value pairs in the global object


VS-RuleEngine documentation Contained in the VS-RuleEngine distribution.

Index


Code Index:

NAME

Top

VS::RuleEngine::Action::SetGlobal - Generic action to set key/value pairs in the global object

SYNOPSIS

Top

  use VS::RuleEngine::Declare;

  my $engine = engine {
      # input_1 and input_2 will be set to the global object (KV_GLOBAL)
      # every time this action is invoked
      action 'set_properties' => instanceof "VS::RuleEngine::Action::SetGlobal" => with_args {
          'input_1' => 5,
          'input_2' => -5,
      }
  }

DESCRIPTION

Top

This is a generic action that sets key/value pairs to the global object. Any existing value for a given key will be overwritten.

USAGE

Top

Rule arguments

This rule expects a hash as its argument, which is what with_args provides, where the key is the name of the key to set and the value is its value.

SEE ALSO

Top

VS::RuleEngine::Action::SetLocal


VS-RuleEngine documentation Contained in the VS-RuleEngine distribution.

package VS::RuleEngine::Action::SetGlobal;

use strict;
use warnings;

use Carp qw(croak);

use VS::RuleEngine::Constants;

use base qw(VS::RuleEngine::Action);

sub new {
    my ($pkg, %args) = @_;
    my $self = bless \%args, $pkg;
    return $self;
}

sub perform {
    my ($self, $global) = @_[KV_SELF, KV_GLOBAL];
        
    while (my ($k, $v) = each %$self) {
        $global->set($k => $v);
    }
}

1;