NAME
Gears::Router::Location::SigilMatch - Location with sigil-based pattern matching
SYNOPSIS
use Gears::Router::Location::SigilMatch;
my $location = Gears::Router::Location::SigilMatch->new(
pattern => '/user/:id/post/?slug',
router => $router,
checks => { id => '\d+' },
defaults => { slug => 'index' },
);
# Match with all parameters
my $match = $location->compare('/user/123/post/my-post');
# Match with optional parameter omitted
my $match2 = $location->compare('/user/123/post');
# Build URL with parameters
my $url = $location->build(id => 456, slug => 'another-post');
DESCRIPTION
Gears::Router::Location::SigilMatch is a location implementation that supports pattern matching with placeholders using sigils. It extends the basic location with support for parameter validation and default values. It is pretty much feature-equal to Kelp::Routes (in terms of pattern matching).
It supports following sigils:
:name- Required placeholderMatches any characters except slash.
?name- Optional placeholderMatches any characters except slash. If it follows a slash (with no curly braces), the slash is made optional as well.
*name- Wildcard placeholderMatches any characters including slashes.
>name- Slurpy placeholderOptional wildcard that matches everything including slashes. If it follows a slash (with no curly braces), the slash is made optional as well.
Each placeholder is required to be given a name. Placeholders can be enclosed in curly braces (like {:name}) to separate them from surrounding text.
INTERFACE
Inherits interface from Gears::Router::Location. Uses Gears::Router::Pattern::SigilMatch for pattern matching.
Attributes
checks
A hash reference mapping placeholder names to regular expressions (as strings or compiled regexes) that validate the matched values. If a value doesn't match its check, the pattern won't match during comparison or will throw an exception during building.
Each check should be a partial regular expression, since it will be included in a larger one. It should not use beginning / end of string anchors.
Available in constructor
defaults
A hash reference mapping optional placeholder names to default values. These defaults are used when optional placeholders are not provided during matching or building.
Available in constructor