NAME
Path::Router::Route::Slurpy - Adds slurpy matching to Path::Router
VERSION
version 0.141330
SYNOPSIS
use Path::Router;
use Path::Router::Route::Slurpy;
use Moose::Util::TypeConstraints;
use List::MoreUtils qw( all );
my $router = Path::Router->new(
route_class => 'Path::Router::Route::Slurpy',
inline => 0, # IMPORTANT! See CAVEATS
);
$router->add_route('page/*:page' => (
validations => subtype('ArrayRef[Str]' => where {
all { /^[_a-z0-9\-.]+(?:\.[_a-z0-9\-]+)*$/i } @$_
}),
target => 'MyApp::Controller::Page',
);
$router->add_route('attachment/+:file' => (
validations => subtype('ArrayRef[Str]' => where {
all { /^[_a-z0-9\-.]+(?:\.[_a-z0-9\-]+)*$/i } @$_
}),
target => 'MyApp::Controller::Attachment',
);
DESCRIPTION
This adds the ability to perform "slurpy" matching in Path::Router. This code originated out of my desire to use Path::Router, but to allow for arbitrary length paths in a hierarchical wiki. For example, I wanted to build a route with a path match defined like this:
page/*:page
Here the final :page
variable should match any number of path parts. The built-in Path::Router match has no way to do this.
In addition to the ?
variable modifier that Path::Router::Route provides, this adds a +
which matches 1 or more path parts and *
which matches 0 or more path parts. These additional matches will be returned in the match mapping as arrays (possibly empty in the case of *
). Similarly, validations of these matches must also be based upon an ArrayRef
Moose type.
CAVEATS
Path::Router provides a very nice inline code generation tool that speeds matching up a little bit. This works by generating the Perl code needed to perform the matches and compiling that directly. This means there's a slight startup cost, but that all matching operations are faster, which is a good thing.
Unfortunately, I have not yet implemented this code generation yet. So you MUST pass the inline
setting to the constructor, like so:
my $router = Path::Router->new(
route_class => 'Path::Router::Route::Slurpy',
inline => 0,
);
Without that, the module does not work as of this writing.
EXTENDS
METHODS
is_component_slurpy
If the path component is like "*:var" or "+:var", it is slurpy.
is_component_optional
If the path component is like "?:var" or "*:var", it is optional.
is_component_variable
If the path component is like "?:var" or "+:var" or "*:var" or ":var", it is a variable.
get_component_name
Grabs the name out of a variable.
has_slurpy_match
Returns true if any component is slurpy.
create_default_mapping
If a default value is an array reference, copies that array.
match
Adds support for slurpy matching.
generate_match_code
As of this writing, this will always die with a warning that the inline => 0
setting must be set on the Path::Router constructor.
See "CAVEATS" for details.
AUTHOR
Andrew Sterling Hanenkamp <hanenkamp@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2014 by Qubling Software LLC.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.