NAME
Router::Dumb - yet another dumb path router for URLs
VERSION
version 0.001
SYNOPSIS
my $r = Router::Dumb->new;
$r->add_route(
Router::Dumb::Route->new({
parts => [ qw(group :group uid :uid) ],
target => 'pants',
constraints => {
group => find_type_constraint('Int'),
},
}),
);
my $match = $r->route( '/group/123/uid/321' );
# $match->target returns 'pants'
# $match->matches returns (group => 123, uid => 321)
DESCRIPTION
Router::Dumb provides a pretty dumb router. You can add routes and then ask how to route a given path string.
Routes have a path. A path is an arrayref of names. Names that start with a colon are placeholders. Everything else is a literal. Literals pieces must appear, literally, in the string being routed. A placeholder can be satisfied by any value, as long as it satisfies the placeholder's constraint. If there's no constraint, any value works.
The special part *
can be used to mean "...then capture everything else into the placeholder named REST
."
Most of the time, you won't be calling add_route
, but using some other helper to figure out routes to add for you. Router::Dumb ships with Router::Dumb::Helper::FileMapper and Router::Dumb::Helper::RouteFile.
METHODS
add_route
$router->add_route({
parts => [ qw( the :path parts ) ],
target => 'target-string',
constraints => {
path => $moose_tc,
},
});
This method adds a new route to the router.
route
my $match_or_undef = $router->route( $str );
If the given string can be routed to a match, the match is returned. If not, the method returns false.
The string must begin with a /
.
ordered_routes
my @routes = $router->ordered_routes;
This method returns the router's routes, in the order that they will be checked. You probably do not want to use this method unless you really know what you're doing.
AUTHOR
Ricardo Signes <rjbs@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2011 by Ricardo Signes.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.