++ed by:
AKRON FILIN VOEGELAS MARKSTOS GHANDI

119 PAUSE users
152 non-PAUSE users.

Sebastian Riedel

NAME

Mojolicious::Routes::Route - Route container

SYNOPSIS

  use Mojolicious::Routes::Route;

  my $r = Mojolicious::Routes::Route->new;

DESCRIPTION

Mojolicious::Routes::Route is the route container used by Mojolicious::Routes.

ATTRIBUTES

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

block

  my $block = $r->block;
  $r        = $r->block(1);

Allow this route to match even if it's not an endpoint, used for waypoints.

children

  my $children = $r->children;
  $r           = $r->children([Mojolicious::Routes::Route->new]);

The children of this routes object, used for nesting routes.

inline

  my $inline = $r->inline;
  $r         = $r->inline(1);

Allow bridge semantics for this route.

parent

  my $parent = $r->parent;
  $r         = $r->parent(Mojolicious::Routes::Route->new);

The parent of this route, used for nesting routes.

partial

  my $partial = $r->partial;
  $r          = $r->partial(1);

Route has no specific end, remaining characters will be captured in path.

pattern

  my $pattern = $r->pattern;
  $r          = $r->pattern(Mojolicious::Routes::Pattern->new);

Pattern for this route, defaults to a Mojolicious::Routes::Pattern object.

METHODS

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

new

  my $r = Mojolicious::Routes::Route->new;
  my $r = Mojolicious::Routes::Route->new('/:controller/:action');

Construct a new Mojolicious::Routes::Route object.

add_child

  $r = $r->add_child(Mojolicious::Route->new);

Add a new child to this route.

any

  my $route = $r->any('/:foo' => sub {...});
  my $route = $r->any(['GET', 'POST'] => '/:foo' => sub {...});

Generate route matching any of the listed HTTP request methods or all. See also the Mojolicious::Lite tutorial for more argument variations.

bridge

  my $bridge = $r->bridge;
  my $bridge = $r->bridge('/:controller/:action');

Add a new bridge to this route as a nested child.

delete

  my $route = $r->delete('/:foo' => sub {...});

Generate route matching only DELETE requests. See also the Mojolicious::Lite tutorial for more argument variations.

detour

  $r = $r->detour(action => 'foo');
  $r = $r->detour({action => 'foo'});
  $r = $r->detour('controller#action');
  $r = $r->detour('controller#action', foo => 'bar');
  $r = $r->detour('controller#action', {foo => 'bar'});
  $r = $r->detour($app);
  $r = $r->detour($app, foo => 'bar');
  $r = $r->detour($app, {foo => 'bar'});
  $r = $r->detour('MyApp');
  $r = $r->detour('MyApp', foo => 'bar');
  $r = $r->detour('MyApp', {foo => 'bar'});

Set default parameters for this route and allow partial matching to simplify application embedding.

find

  my $route = $r->find('foo');

Find child route by name, custom names have precedence over automatically generated ones.

get

  my $route = $r->get('/:foo' => sub {...});

Generate route matching only GET requests. See also the Mojolicious::Lite tutorial for more argument variations.

has_conditions

  my $success = $r->has_conditions;

Check if this route has active conditions.

has_custom_name

  my $success = $r->has_custom_name;

Check if this route has a custom name.

has_websocket

  my $success = $r->has_websocket;

Check if this route has a WebSocket ancestor.

is_endpoint

  my $success = $r->is_endpoint;

Check if this route qualifies as an endpoint.

is_websocket

  my $success = $r->is_websocket;

Check if this route is a WebSocket.

name

  my $name = $r->name;
  $r       = $r->name('foo');

The name of this route, defaults to an automatically generated name based on the route pattern. Note that the name current is reserved for refering to the current route.

options

  my $route = $r->options('/:foo' => sub {...});

Generate route matching only OPTIONS requests. See also the Mojolicious::Lite tutorial for more argument variations.

over

  my $over = $r->over;
  $r       = $r->over(foo => qr/\w+/);

Activate conditions for this route and disable routing cache.

parse

  $r = $r->parse('/:controller/:action');

Parse a pattern.

patch

  my $route = $r->patch('/:foo' => sub {...});

Generate route matching only PATCH requests. See also the Mojolicious::Lite tutorial for more argument variations.

post

  my $route = $r->post('/:foo' => sub {...});

Generate route matching only POST requests. See also the Mojolicious::Lite tutorial for more argument variations.

put

  my $route = $r->put('/:foo' => sub {...});

Generate route matching only PUT requests. See also the Mojolicious::Lite tutorial for more argument variations.

render

  my $path = $r->render($suffix);
  my $path = $r->render($suffix, {foo => 'bar'});

Render route with parameters into a path.

root

  my $root = $r->root;

The Mojolicious::Routes object this route is an ancestor of.

route

  my $route = $r->route('/:c/:a', a => qr/\w+/);

Add a new nested child to this route.

to

  my $to  = $r->to;
  $r = $r->to(action => 'foo');
  $r = $r->to({action => 'foo'});
  $r = $r->to('controller#action');
  $r = $r->to('controller#action', foo => 'bar');
  $r = $r->to('controller#action', {foo => 'bar'});
  $r = $r->to($app);
  $r = $r->to($app, foo => 'bar');
  $r = $r->to($app, {foo => 'bar'});
  $r = $r->to('MyApp');
  $r = $r->to('MyApp', foo => 'bar');
  $r = $r->to('MyApp', {foo => 'bar'});

Set default parameters for this route.

to_string

  my $string = $r->to_string;

Stringify the whole route.

under

  my $route = $r->under(sub {...});
  my $route = $r->under('/:foo');

Generate bridges. See also the Mojolicious::Lite tutorial for more argument variations.

via

  my $methods = $r->via;
  $r          = $r->via('GET');
  $r          = $r->via(qw/GET POST/);
  $r          = $r->via([qw/GET POST/]);

Restrict HTTP methods this route is allowed to handle, defaults to no restrictions.

waypoint

  my $r = $r->waypoint('/:c/:a', a => qr/\w+/);

Add a waypoint to this route as nested child.

websocket

  my $websocket = $r->websocket('/:foo' => sub {...});

Generate route matching only WebSocket handshakes. See also the Mojolicious::Lite tutorial for more argument variations.

SHORTCUTS

In addition to the attributes and methods above you can also call shortcuts on Mojolicious::Routes::Route objects.

  $r->add_shortcut(firefox => sub {
    my ($r, $path) = @_;
    $r->get($path, agent => qr/Firefox/);
  });

  $r->firefox('/welcome')->to('firefox#welcome');
  $r->firefox('/bye')->to('firefox#bye);

SEE ALSO

Mojolicious, Mojolicious::Guides, http://mojolicio.us.