NAME
Kvasir::Declare - Declarative interface for Kvasir engines
SYNOPSIS
use Kvasir::Constants;
use Kvasir::Declare;
my $engine = engine {
input "input1" => instanceof "MyApp::Input";
input "input2" => instanceof "MyApp::OtherInput";
rule "rule1" => instanceof "MyApp::Rule" => with_args { input => "input1" };
rule "rule2" => instanceof "MyApp::Rule" => with_args { input => "input2" };
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();
INTERFACE
FUNCTIONS
- engine BLOCK
-
Creates a new engine.
- action NAME [=> instanceof CLASS [ => with_args ARGS]]
- action NAME => does BLOCK
-
Creates a new action and registers it in the engine as NAME.
- input NAME [=> instanceof CLASS [ => with_args ARGS]]
- input NAME => does BLOCK
-
Creates a new input and registers it in the engine as NAME.
- output NAME [=> instanceof CLASS [ => with_args ARGS]]
- output NAME => does BLOCK
-
Creates a new output and registers it in the engine as NAME.
- prehook NAME [=> instanceof CLASS [ => with_args ARGS]]
- prehook NAME => does BLOCK
-
Creates a new prehook and registers it in the engine as NAME.
Prehooks are evaulated in the order they are declared.
- posthook NAME [=> instanceof CLASS [ => with_args ARGS]]
- posthook NAME => does BLOCK
-
Creates a new posthook and registers it in the engine as NAME.
Posthooks are evaulated in the order they are declared.
- rule NAME [=> instanceof CLASS [ => with_args ARGS]]
- rule NAME => does BLOCK
-
Creates a new rule and registers it in the engine as NAME.
Rules are evaulated in the order they are declared unless an order has explicitly been defined using
rule_order
. d - run ACTIONS => when RULES
-
Runs the list of ACTION when the given RULES matches.
- as NAME
-
Checks that NAME is a valid name and returns it if so. Otherwise throws an exception.
- instanceof CLASS
-
Marks the declared entity to be an instance of the given CLASS.
- does BLOCK
-
Marks the declared entity to be implemented via a Perl subroutine.
- load_module MODULE
-
Load the module MODULE.