DOKK / manpages / debian 12 / libmojolicious-perl / Mojolicious::Routes::Pattern.3pm.en
Mojolicious::Routes::Pattern(3pm) User Contributed Perl Documentation Mojolicious::Routes::Pattern(3pm)

Mojolicious::Routes::Pattern - Route pattern

  use Mojolicious::Routes::Pattern;
  # Create pattern
  my $pattern = Mojolicious::Routes::Pattern->new('/test/:name');
  # Match routes
  my $captures = $pattern->match('/test/sebastian');
  say $captures->{name};

Mojolicious::Routes::Pattern is the core of Mojolicious::Routes.

Mojolicious::Routes::Pattern implements the following attributes.

  my $constraints = $pattern->constraints;
  $pattern        = $pattern->constraints({foo => qr/\w+/});

Regular expression constraints.

  my $defaults = $pattern->defaults;
  $pattern     = $pattern->defaults({foo => 'bar'});

Default parameters.

  my $start = $pattern->placeholder_start;
  $pattern  = $pattern->placeholder_start(':');

Character indicating a placeholder, defaults to ":".

  my $placeholders = $pattern->placeholders;
  $pattern         = $pattern->placeholders(['foo', 'bar']);

Placeholder names.

  my $end  = $pattern->quote_end;
  $pattern = $pattern->quote_end('}');

Character indicating the end of a quoted placeholder, defaults to ">".

  my $start = $pattern->quote_start;
  $pattern  = $pattern->quote_start('{');

Character indicating the start of a quoted placeholder, defaults to "<".

  my $regex = $pattern->regex;
  $pattern  = $pattern->regex($regex);

Pattern in compiled regular expression form.

  my $start = $pattern->relaxed_start;
  $pattern  = $pattern->relaxed_start('*');

Character indicating a relaxed placeholder, defaults to "#".

  my $tree = $pattern->tree;
  $pattern = $pattern->tree([['text', '/foo']]);

Pattern in parsed form. Note that this structure should only be used very carefully since it is very dynamic.

  my $start = $pattern->type_start;
  $pattern  = $pattern->type_start('|');

Character indicating the start of a placeholder type, defaults to ":".

  my $types = $pattern->types;
  $pattern  = $pattern->types({int => qr/[0-9]+/});

Placeholder types.

  my $unparsed = $pattern->unparsed;
  $pattern     = $pattern->unparsed('/:foo/:bar');

Raw unparsed pattern.

  my $start = $pattern->wildcard_start;
  $pattern  = $pattern->wildcard_start('*');

Character indicating the start of a wildcard placeholder, defaults to "*".

Mojolicious::Routes::Pattern inherits all methods from Mojo::Base and implements the following new ones.

  my $captures = $pattern->match('/foo/bar');
  my $captures = $pattern->match('/foo/bar', 1);

Match pattern against entire path, format detection is disabled by default.

  my $captures = $pattern->match_partial(\$path);
  my $captures = $pattern->match_partial(\$path, 1);

Match pattern against path and remove matching parts, format detection is disabled by default.

  my $pattern = Mojolicious::Routes::Pattern->new;
  my $pattern = Mojolicious::Routes::Pattern->new('/users/:id');
  my $pattern = Mojolicious::Routes::Pattern->new('/user/:id', id => qr/\d+/);
  my $pattern = Mojolicious::Routes::Pattern->new(format => ['json', 'yaml']);

Construct a new Mojolicious::Routes::Pattern object and "parse" pattern if necessary.

  $pattern = $pattern->parse('/user/:id');
  $pattern = $pattern->parse('/user/:id', id=> qr/\d+/);
  $pattern = $pattern->parse(format => ['json', 'yaml']);

Parse pattern.

  my $path = $pattern->render({id => 24});
  my $path = $pattern->render({id => 24}, 1);

Render pattern into a path with parameters, format rendering is disabled by default.

Mojolicious, Mojolicious::Guides, <https://mojolicious.org>.

2022-12-22 perl v5.36.0