NAME
Path::Dispatcher::Declarative - sugary dispatcher
SYNOPSIS
package MyApp::Dispatcher;
use Path::Dispatcher::Declarative;
on score => sub { show_score() };
on ['wield', qr/^\w+$/] => sub { wield_weapon($2) };
under display => sub {
on inventory => sub { show_inventory() };
on score => sub { show_score() };
};
package Interpreter;
MyApp::Dispatcher->run($input);
DESCRIPTION
KEYWORDS
dispatcher -> Dispatcher
Returns the Path::Dispatcher object for this class; the object that the sugar is modifying. This is useful for adding custom rules through the regular API, and inspection.
dispatch path -> Dispatch
Invokes the dispatcher on the given path and returns a Path::Dispatcher::Dispatch object. Acts as a keyword within the same package; otherwise as a method (since these declarative dispatchers are supposed to be used by other packages).
run path, args
Performs a dispatch then invokes the "run" in Path::Dispatcher::Dispatch method on it.
on path => sub {}
Adds a rule to the dispatcher for the given path. The path may be:
- a string
-
This is taken to mean a single token; creates an Path::Dispatcher::Rule::Token rule.
- an array reference
-
This is creates a Path::Dispatcher::Rule::Token rule.
- a regular expression
-
This is creates a Path::Dispatcher::Rule::Regex rule.
- a code reference
-
This is creates a Path::Dispatcher::Rule::CodeRef rule.
under path => sub {}
Creates a Path::Dispatcher::Rule::Under rule. The contents of the coderef should be other "on" and under
calls.