SYNOPSIS

    my $rule = Path::Dispatcher::Rule::Tokens->new(
        tokens    => [ "comment", "show", qr/^\d+$/ ],
        delimiter => '/',
        block     => sub { display_comment(shift->pos(3)) },
    );

    $rule->match("/comment/show/25");

DESCRIPTION

Rules of this class use a list of tokens to match the path.

ATTRIBUTES

tokens

Each token can be a literal string, a regular expression, or a list of either (which are taken to mean alternations). For example, the tokens:

[ 'ticket', [ 'show', 'display' ], [ qr/^\d+$/, qr/^#\w{3}/ ] ]

first matches \*(L"ticket\*(R". Then, the next token must be \*(L"show\*(R" or \*(L"display\*(R". The final token must be a number or a pound sign followed by three word characters.

The results are the tokens in the original string, as they were matched. If you have three tokens, then \*(C`match->pos(1)\*(C' will be the string's first token (\*(L"ticket\*(R"), \*(C`match->pos(2)\*(C' its second (\*(L"display\*(R"), and \*(C`match->pos(3)\*(C' its third (\*(L"#AAA\*(R").

Capture groups inside a regex token are completely ignored.

delimiter

A string that is used to tokenize the path. The delimiter must be a string because prefix matches use \*(C`join\*(C' on unmatched tokens to return the leftover path. In the future this may be extended to support having a regex delimiter.

The default is a space, but if you're matching URLs you probably want to change this to a slash.

case_sensitive

Decide whether the rule matching is case sensitive. Default is 1, case sensitive matching.