NAME
Mojolicious::Routes::Pattern - Routes pattern engine
SYNOPSIS
# Create pattern
my
$pattern
= Mojolicious::Routes::Pattern->new(
'/test/:name'
);
# Match routes
my
$result
=
$pattern
->match(
'/test/sebastian'
);
say
$result
->{name};
DESCRIPTION
Mojolicious::Routes::Pattern is the core of Mojolicious::Routes.
ATTRIBUTES
Mojolicious::Routes::Pattern implements the following attributes.
constraints
my
$constraints
=
$pattern
->constraints;
$pattern
=
$pattern
->constraints({
foo
=>
qr/\w+/
});
Regular expression constraints.
defaults
my
$defaults
=
$pattern
->defaults;
$pattern
=
$pattern
->defaults({
foo
=>
'bar'
});
Default parameters.
format_regex
my
$regex
=
$pattern
->format_regex;
$pattern
=
$pattern
->format_regex(
$regex
);
Compiled regular expression for format matching.
pattern
my
$pattern
=
$pattern
->pattern;
$pattern
=
$pattern
->pattern(
'/(foo)/(bar)'
);
Raw unparsed pattern.
placeholder_start
my
$start
=
$pattern
->placeholder_start;
$pattern
=
$pattern
->placeholder_start(
':'
);
Character indicating a placeholder, defaults to :
.
placeholders
my
$placeholders
=
$pattern
->placeholders;
$pattern
=
$pattern
->placeholders([
'foo'
,
'bar'
]);
Placeholder names.
quote_end
my
$end
=
$pattern
->quote_end;
$pattern
=
$pattern
->quote_end(
']'
);
Character indicating the end of a quoted placeholder, defaults to )
.
quote_start
my
$start
=
$pattern
->quote_start;
$pattern
=
$pattern
->quote_start(
'['
);
Character indicating the start of a quoted placeholder, defaults to (
.
regex
my
$regex
=
$pattern
->regex;
$pattern
=
$pattern
->regex(
$regex
);
Pattern in compiled regular expression form.
relaxed_start
my
$start
=
$pattern
->relaxed_start;
$pattern
=
$pattern
->relaxed_start(
'*'
);
Character indicating a relaxed placeholder, defaults to #
.
tree
my
$tree
=
$pattern
->tree;
$pattern
=
$pattern
->tree([ ... ]);
Pattern in parsed form.
wildcard_start
my
$start
=
$pattern
->wildcard_start;
$pattern
=
$pattern
->wildcard_start(
'*'
);
Character indicating the start of a wildcard placeholder, defaults to *
.
METHODS
Mojolicious::Routes::Pattern inherits all methods from Mojo::Base and implements the following new ones.
new
my
$pattern
= Mojolicious::Routes::Pattern->new(
'/:action'
);
my
$pattern
= Mojolicious::Routes::Pattern->new(
'/:action'
,
action
=>
qr/\w+/
);
my
$pattern
= Mojolicious::Routes::Pattern->new(
format
=> 0);
Construct a new Mojolicious::Routes::Pattern object.
match
my
$result
=
$pattern
->match(
'/foo/bar'
);
my
$result
=
$pattern
->match(
'/foo/bar'
, 1);
Match pattern against entire path, format detection is disabled by default.
parse
$pattern
=
$pattern
->parse(
'/:action'
);
$pattern
=
$pattern
->parse(
'/:action'
,
action
=>
qr/\w+/
);
$pattern
=
$pattern
->parse(
format
=> 0);
Parse a raw pattern.
render
my
$path
=
$pattern
->render({
action
=>
'foo'
});
my
$path
=
$pattern
->render({
action
=>
'foo'
}, 1);
Render pattern into a path with parameters, format rendering is disabled by default.
shape_match
my
$result
=
$pattern
->shape_match(\
$path
);
my
$result
=
$pattern
->shape_match(\
$path
, 1);
Match pattern against path and remove matching parts, format detection is disabled by default.