
Path::Dispatcher - flexible and extensible dispatch

use Path::Dispatcher;
my $dispatcher = Path::Dispatcher->new;
$dispatcher->add_rule(
Path::Dispatcher::Rule::Regex->new(
regex => qr{^/(foo)/},
block => sub { warn $1; }, # foo
)
);
$dispatcher->add_rule(
Path::Dispatcher::Rule::Tokens->new(
tokens => ['ticket', 'delete', qr/^\d+$/],
delimiter => '/',
block => sub { delete_ticket($3) },
)
);
my $dispatch = $dispatcher->dispatch("/foo/bar");
die "404" unless $dispatch->has_matches;
$dispatch->run;

We really like Jifty::Dispatcher and wanted to use it for the command line.
The basic operation is that of dispatch. Dispatch takes a path and a list of rules, and it returns a list of matches. From there you can "run" the rules that matched. These phases are distinct so that, if you need to, you can inspect which rules were matched without ever running their codeblocks.
Most consumers would want to use Path::Dispatcher::Declarative which gives you some sugar, inspired by Jifty::Dispatcher.

A list of Path::Dispatcher::Rule objects.
A human-readable name; this will be used in the debugging hooks. In Path::Dispatcher::Declarative, this is the package name of the dispatcher.

Adds a Path::Dispatcher::Rule to the end of this dispatcher's rule set.
Takes a string (the path) and returns a Path::Dispatcher::Dispatch object representing a list of matches (Path::Dispatcher::Match objects).
Dispatches on the path and then invokes the run method on the Path::Dispatcher::Dispatch object, for when you don't need to inspect the dispatch.
The args are passed down directly into each rule codeblock. No other args are given to the codeblock.

Shawn M Moore, <sartak at bestpractical.com>

Please report any bugs or feature requests to bug-path-dispatcher at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Path-Dispatcher.


Copyright 2008-2009 Best Practical Solutions.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.