VS::RuleEngine::Declare - Declarative interface for VS::RuleEngine engines
use VS::RuleEngine::Constants; use VS::RuleEngine::Declare; my $input = MyApp::MyOtherInput->new(); my $rule = MyApp::ComplexRule->new(); my $engine = engine { defaults "d1" => { some_arg => 1, }; input "input1" => instanceof "MyApp::Input" => with_defaults "d1"; input "input2" => $input; rule "rule1" => instanceof "MyApp::Rule" => with_args { input => "input1" }; rule "rule2" => $rule; rule "rule3" => does { my ($input, $global, $local) = @_[KV_INPUT, KV_GLOBAL_DATA, KV_LOCAL_DATA]; if ($input->get("input1") < 5 && $input->get("input1") > 10) { return KV_MATCH; } return KV_NO_MATCH; }; action "action1" => does { my $result = complex_calculation(); $_[KV_LOCAL]->set("result" => $result); }; prehook "check_date" => does { return KV_CONTINUE; }; run "action1" => when qw(rule1 rule2 rule3); }; $engine->run();
Creates a new engine.
Creates a new action and registers it in the engine as NAME. If an object is passed it must conform to VS::RuleEngine::Action.
VS::RuleEngine::Action
Creates a new input and registers it in the engine as NAME. If an object is passed it must conform to VS::RuleEngine::Input.
VS::RuleEngine::Input
Creates a new output and registers it in the engine as NAME. If an object is passed it must conform to VS::RuleEngine::Output.
VS::RuleEngine::Output
Creates a new prehook and registers it in the engine as NAME. If an object is passed it must conform to VS::RuleEngine::Hook.
VS::RuleEngine::Hook
Prehooks are evaulated in the order they are declared.
Creates a new posthook and registers it in the engine as NAME. If an object is passed it must conform to VS::RuleEngine::Hook.
Posthooks are evaulated in the order they are declared.
Creates a new rule and registers it in the engine as NAME. If an object is passed it must conform to VS::RuleEngine::Rule.
VS::RuleEngine::Rule
Rules are evaulated in the order they are declared unless an order has explicitly been defined using rule_order. d
rule_order
Runs the list of ACTION when the given RULES matches.
Creates a argument set for the entity.
Use the defaults defined by DEFAULT or multiple defaults defined by the ARRAY referene DEFAULTS.
Checks that NAME is a valid name and returns it if so. Otherwise throws an exception.
Marks the declared entity to be an instance of the given CLASS.
Creates a new arguent set with the given NAME and arguments. ARGUMENTS must be a hash reference.
Marks the declared entity to be implemented via a Perl subroutine.
Load the module MODULE.
To install VS::RuleEngine, copy and paste the appropriate command in to your terminal.
cpanm
cpanm VS::RuleEngine
CPAN shell
perl -MCPAN -e shell install VS::RuleEngine
For more information on module installation, please visit the detailed CPAN module installation guide.