Path::Router::Route::Slurpy - Adds slurpy matching to Path::Router
version 0.141330
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', );
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.
:page
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.
?
+
*
ArrayRef
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:
inline
my $router = Path::Router->new( route_class => 'Path::Router::Route::Slurpy', inline => 0, );
Without that, the module does not work as of this writing.
Path::Router::Route
If the path component is like "*:var" or "+:var", it is slurpy.
If the path component is like "?:var" or "*:var", it is optional.
If the path component is like "?:var" or "+:var" or "*:var" or ":var", it is a variable.
Grabs the name out of a variable.
Returns true if any component is slurpy.
If a default value is an array reference, copies that array.
Adds support for slurpy matching.
As of this writing, this will always die with a warning that the inline => 0 setting must be set on the Path::Router constructor.
inline => 0
See "CAVEATS" for details.
Andrew Sterling Hanenkamp <hanenkamp@cpan.org>
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.
To install Path::Router::Route::Slurpy, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Path::Router::Route::Slurpy
CPAN shell
perl -MCPAN -e shell install Path::Router::Route::Slurpy
For more information on module installation, please visit the detailed CPAN module installation guide.