Mojolicious::Routes::Route - Route
use Mojolicious::Routes::Route; my $r = Mojolicious::Routes::Route->new;
Mojolicious::Routes::Route is the route container used by Mojolicious::Routes.
Mojolicious::Routes::Route implements the following attributes.
my $children = $r->children; $r = $r->children([Mojolicious::Routes::Route->new]);
The children of this route, used for nesting routes.
my $bool = $r->inline; $r = $r->inline($bool);
Allow "bridge" semantics for this route.
my $parent = $r->parent; $r = $r->parent(Mojolicious::Routes::Route->new);
The parent of this route, used for nesting routes.
my $bool = $r->partial; $r = $r->partial($bool);
Route has no specific end, remaining characters will be captured in path.
path
my $pattern = $r->pattern; $r = $r->pattern(Mojolicious::Routes::Pattern->new);
Pattern for this route, defaults to a Mojolicious::Routes::Pattern object.
Mojolicious::Routes::Route inherits all methods from Mojo::Base and implements the following new ones.
my $r = Mojolicious::Routes::Route->new; my $r = Mojolicious::Routes::Route->new('/:controller/:action');
Construct a new Mojolicious::Routes::Route object and <parse> pattern if necessary.
$r = $r->add_child(Mojolicious::Routes::Route->new);
Add a new child to this route, it will be automatically removed from its current parent if necessary.
# Reattach route $r->add_child($r->find('foo'));
my $route = $r->any('/:foo' => sub {...}); my $route = $r->any([qw(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.
$r->any('/user')->to('user#whatever');
my $bridge = $r->bridge; my $bridge = $r->bridge('/:action'); my $bridge = $r->bridge('/:action', action => qr/\w+/); my $bridge = $r->bridge(format => 0);
Generate bridge route with optional pattern and restrictive placeholders.
my $auth = $r->bridge('/user')->to('user#auth'); $auth->get('/show')->to('#show'); $auth->post('/create')->to('#create');
my $route = $r->delete('/:foo' => sub {...});
Generate route matching only DELETE requests. See also the Mojolicious::Lite tutorial for more argument variations.
$r->delete('/user')->to('user#remove');
$r = $r->detour(action => 'foo'); $r = $r->detour('controller#action'); $r = $r->detour(Mojolicious->new, foo => 'bar'); $r = $r->detour('MyApp', {foo => 'bar'});
Set default parameters for this route and allow partial matching to simplify application embedding, takes the same arguments as "to".
my $route = $r->find('foo');
Find child route by name, custom names have precedence over automatically generated ones.
$r->find('show_user')->to(foo => 'bar');
my $route = $r->get('/:foo' => sub {...});
Generate route matching only GET requests. See also the Mojolicious::Lite tutorial for more argument variations.
$r->get('/user')->to('user#show');
my $bool = $r->has_conditions;
Check if this route has active conditions.
my $bool = $r->has_custom_name;
Check if this route has a custom name.
my $bool = $r->has_websocket;
Check if this route has a WebSocket ancestor.
my $bool = $r->is_endpoint;
Check if this route qualifies as an endpoint.
my $bool = $r->is_websocket;
Check if this route is a WebSocket.
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 referring to the current route.
current
$r->get('/user')->to('user#show')->name('show_user');
my $route = $r->options('/:foo' => sub {...});
Generate route matching only OPTIONS requests. See also the Mojolicious::Lite tutorial for more argument variations.
$r->options('/user')->to('user#overview');
my $over = $r->over; $r = $r->over(foo => 1); $r = $r->over(foo => 1, bar => {baz => 'yada'}); $r = $r->over([foo => 1, bar => {baz => 'yada'}]);
Activate conditions for this route. Note that this automatically disables the routing cache, since conditions are too complex for caching.
$r->get('/foo')->over(host => qr/mojolicio\.us/)->to('foo#bar');
$r = $r->parse('/:action'); $r = $r->parse('/:action', action => qr/\w+/); $r = $r->parse(format => 0);
Parse pattern.
my $route = $r->patch('/:foo' => sub {...});
Generate route matching only PATCH requests. See also the Mojolicious::Lite tutorial for more argument variations.
$r->patch('/user')->to('user#update');
my $route = $r->post('/:foo' => sub {...});
Generate route matching only POST requests. See also the Mojolicious::Lite tutorial for more argument variations.
$r->post('/user')->to('user#create');
my $route = $r->put('/:foo' => sub {...});
Generate route matching only PUT requests. See also the Mojolicious::Lite tutorial for more argument variations.
$r->put('/user')->to('user#replace');
$r = $r->remove;
Remove route from parent.
# Remove route completely $r->find('foo')->remove; # Reattach route to new parent $r->route('/foo')->add_child($r->find('bar')->remove);
my $path = $r->render($suffix); my $path = $r->render($suffix, {foo => 'bar'});
Render route with parameters into a path.
my $root = $r->root;
The Mojolicious::Routes object this route is an descendent of.
$r->root->cache(0);
my $route = $r->route; my $route = $r->route('/:action'); my $route = $r->route('/:action', action => qr/\w+/); my $route = $r->route(format => 0);
Generate route matching all HTTP request methods with optional pattern and restrictive placeholders.
my $defaults = $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(Mojolicious->new); $r = $r->to(Mojolicious->new, foo => 'bar'); $r = $r->to(Mojolicious->new, {foo => 'bar'}); $r = $r->to('MyApp'); $r = $r->to('MyApp', foo => 'bar'); $r = $r->to('MyApp', {foo => 'bar'});
Set default parameters for this route.
my $str = $r->to_string;
Stringify the whole route.
my $bridge = $r->under(sub {...}); my $bridge = $r->under('/:foo');
Generate bridge route. See also the Mojolicious::Lite tutorial for more argument variations.
my $auth = $r->under('/user')->to('user#auth'); $auth->get('/show')->to('#show'); $auth->post('/create')->to('#create');
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.
$r->route('/foo')->via(qw(GET POST))->to('foo#bar');
my $ws = $r->websocket('/:foo' => sub {...});
Generate route matching only WebSocket handshakes. See also the Mojolicious::Lite tutorial for more argument variations.
$r->websocket('/echo')->to('example#echo');
In addition to the attributes and methods above you can also call shortcuts on Mojolicious::Routes::Route objects.
$r->root->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);
Mojolicious, Mojolicious::Guides, http://mojolicio.us.
To install Mojolicious, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mojolicious
CPAN shell
perl -MCPAN -e shell install Mojolicious
For more information on module installation, please visit the detailed CPAN module installation guide.