NAME

Gears::Router::Pattern::SigilMatch - Pattern matching with placeholder support

SYNOPSIS

use Gears::Router::Pattern::SigilMatch;

my $pattern = Gears::Router::Pattern::SigilMatch->new(
	location => $location,
);

# Match and extract placeholders
my $match_data = $pattern->compare('/user/123/post/my-slug');
# $match_data = ['123', 'my-slug']

# Build URL from placeholders
my $url = $pattern->build(id => 456, slug => 'new-slug');
# $url = '/user/456/post/new-slug'

DESCRIPTION

Gears::Router::Pattern::SigilMatch provides pattern matching with support for placeholders using sigils. It converts patterns with sigils into regular expressions for matching and can build URLs by substituting placeholder values.

See Gears::Router::Location::SigilMatch, which discusses placeholder types and their behavior.

INTERFACE

Inherits interface from Gears::Router::Pattern.

Attributes

tokens

An array reference of token definitions extracted from the pattern. Each token is a hash with sigil and label keys. This is populated automatically when the pattern object is built.

Not available in constructor

checks

A hash reference of validation patterns for placeholders, taken from the location data.

Not available in constructor

defaults

A hash reference of default values for placeholders, taken from the location data.

Not available in constructor

Methods

compare

$match_data = $pattern->compare($request_path)

Matches the request path against the pattern's compiled regular expression. Returns an array reference containing the extracted placeholder values in the order they appear in the pattern. Returns undef if the path doesn't match. Default values are applied for optional placeholders that weren't matched.

build

$url = $pattern->build(%params)

Builds a URL by substituting placeholders in the pattern with provided parameter values. Default values are used for parameters not provided. Throws an exception if required parameters are missing or if parameter values don't pass their checks.