.\" Automatically generated by Pod::Man 2.25 (Pod::Simple 3.16) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .ie \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . nr % 0 . rr F .\} .el \{\ . de IX .. .\} .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Mojolicious::Routes::Route 3pm" .TH Mojolicious::Routes::Route 3pm "2012-09-05" "perl v5.14.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Mojolicious::Routes::Route \- Route container .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Mojolicious::Routes::Route; \& \& my $r = Mojolicious::Routes::Route\->new; .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Mojolicious::Routes::Route is the route container used by Mojolicious::Routes. .SH "ATTRIBUTES" .IX Header "ATTRIBUTES" Mojolicious::Routes::Route implements the following attributes. .ie n .SS """children""" .el .SS "\f(CWchildren\fP" .IX Subsection "children" .Vb 2 \& my $children = $r\->children; \& $r = $r\->children([Mojolicious::Routes::Route\->new]); .Ve .PP The children of this route, used for nesting routes. .ie n .SS """inline""" .el .SS "\f(CWinline\fP" .IX Subsection "inline" .Vb 2 \& my $inline = $r\->inline; \& $r = $r\->inline(1); .Ve .PP Allow \f(CW\*(C`bridge\*(C'\fR semantics for this route. .ie n .SS """parent""" .el .SS "\f(CWparent\fP" .IX Subsection "parent" .Vb 2 \& my $parent = $r\->parent; \& $r = $r\->parent(Mojolicious::Routes::Route\->new); .Ve .PP The parent of this route, used for nesting routes. .ie n .SS """partial""" .el .SS "\f(CWpartial\fP" .IX Subsection "partial" .Vb 2 \& my $partial = $r\->partial; \& $r = $r\->partial(1); .Ve .PP Route has no specific end, remaining characters will be captured in \f(CW\*(C`path\*(C'\fR. .ie n .SS """pattern""" .el .SS "\f(CWpattern\fP" .IX Subsection "pattern" .Vb 2 \& my $pattern = $r\->pattern; \& $r = $r\->pattern(Mojolicious::Routes::Pattern\->new); .Ve .PP Pattern for this route, defaults to a Mojolicious::Routes::Pattern object. .SH "METHODS" .IX Header "METHODS" Mojolicious::Routes::Route inherits all methods from Mojo::Base and implements the following ones. .ie n .SS """new""" .el .SS "\f(CWnew\fP" .IX Subsection "new" .Vb 2 \& my $r = Mojolicious::Routes::Route\->new; \& my $r = Mojolicious::Routes::Route\->new(\*(Aq/:controller/:action\*(Aq); .Ve .PP Construct a new Mojolicious::Routes::Route object. .ie n .SS """add_child""" .el .SS "\f(CWadd_child\fP" .IX Subsection "add_child" .Vb 1 \& $r = $r\->add_child(Mojolicious::Route\->new); .Ve .PP Add a new child to this route, it will be automatically removed from its current parent if necessary. .PP .Vb 2 \& # Reattach route \& $r\->add_child($r\->find(\*(Aqfoo\*(Aq)); .Ve .ie n .SS """any""" .el .SS "\f(CWany\fP" .IX Subsection "any" .Vb 2 \& my $route = $r\->any(\*(Aq/:foo\*(Aq => sub {...}); \& my $route = $r\->any([qw(GET POST)] => \*(Aq/:foo\*(Aq => sub {...}); .Ve .PP Generate route matching any of the listed \s-1HTTP\s0 request methods or all. See also the Mojolicious::Lite tutorial for more argument variations. .PP .Vb 1 \& $r\->any(\*(Aq/user\*(Aq)\->to(\*(Aquser#whatever\*(Aq); .Ve .ie n .SS """bridge""" .el .SS "\f(CWbridge\fP" .IX Subsection "bridge" .Vb 4 \& my $bridge = $r\->bridge; \& my $bridge = $r\->bridge(\*(Aq/:action\*(Aq); \& my $bridge = $r\->bridge(\*(Aq/:action\*(Aq, action => qr/\ew+/); \& my $bridge = $r\->bridge(format => 0); .Ve .PP Generate bridge. .PP .Vb 3 \& my $auth = $r\->bridge(\*(Aq/user\*(Aq)\->to(\*(Aquser#auth\*(Aq); \& $auth\->get(\*(Aq/show\*(Aq)\->to(\*(Aq#show\*(Aq); \& $auth\->post(\*(Aq/create\*(Aq)\->to(\*(Aq#create\*(Aq); .Ve .ie n .SS """delete""" .el .SS "\f(CWdelete\fP" .IX Subsection "delete" .Vb 1 \& my $route = $r\->delete(\*(Aq/:foo\*(Aq => sub {...}); .Ve .PP Generate route matching only \f(CW\*(C`DELETE\*(C'\fR requests. See also the Mojolicious::Lite tutorial for more argument variations. .PP .Vb 1 \& $r\->delete(\*(Aq/user\*(Aq)\->to(\*(Aquser#remove\*(Aq); .Ve .ie n .SS """detour""" .el .SS "\f(CWdetour\fP" .IX Subsection "detour" .Vb 11 \& $r = $r\->detour(action => \*(Aqfoo\*(Aq); \& $r = $r\->detour({action => \*(Aqfoo\*(Aq}); \& $r = $r\->detour(\*(Aqcontroller#action\*(Aq); \& $r = $r\->detour(\*(Aqcontroller#action\*(Aq, foo => \*(Aqbar\*(Aq); \& $r = $r\->detour(\*(Aqcontroller#action\*(Aq, {foo => \*(Aqbar\*(Aq}); \& $r = $r\->detour($app); \& $r = $r\->detour($app, foo => \*(Aqbar\*(Aq); \& $r = $r\->detour($app, {foo => \*(Aqbar\*(Aq}); \& $r = $r\->detour(\*(AqMyApp\*(Aq); \& $r = $r\->detour(\*(AqMyApp\*(Aq, foo => \*(Aqbar\*(Aq); \& $r = $r\->detour(\*(AqMyApp\*(Aq, {foo => \*(Aqbar\*(Aq}); .Ve .PP Set default parameters for this route and allow partial matching to simplify application embedding. .ie n .SS """find""" .el .SS "\f(CWfind\fP" .IX Subsection "find" .Vb 1 \& my $route = $r\->find(\*(Aqfoo\*(Aq); .Ve .PP Find child route by name, custom names have precedence over automatically generated ones. .PP .Vb 1 \& $r\->find(\*(Aqshow_user\*(Aq)\->to(foo => \*(Aqbar\*(Aq); .Ve .ie n .SS """get""" .el .SS "\f(CWget\fP" .IX Subsection "get" .Vb 1 \& my $route = $r\->get(\*(Aq/:foo\*(Aq => sub {...}); .Ve .PP Generate route matching only \f(CW\*(C`GET\*(C'\fR requests. See also the Mojolicious::Lite tutorial for more argument variations. .PP .Vb 1 \& $r\->get(\*(Aq/user\*(Aq)\->to(\*(Aquser#show\*(Aq); .Ve .ie n .SS """has_conditions""" .el .SS "\f(CWhas_conditions\fP" .IX Subsection "has_conditions" .Vb 1 \& my $success = $r\->has_conditions; .Ve .PP Check if this route has active conditions. .ie n .SS """has_custom_name""" .el .SS "\f(CWhas_custom_name\fP" .IX Subsection "has_custom_name" .Vb 1 \& my $success = $r\->has_custom_name; .Ve .PP Check if this route has a custom name. .ie n .SS """has_websocket""" .el .SS "\f(CWhas_websocket\fP" .IX Subsection "has_websocket" .Vb 1 \& my $success = $r\->has_websocket; .Ve .PP Check if this route has a WebSocket ancestor. .ie n .SS """is_endpoint""" .el .SS "\f(CWis_endpoint\fP" .IX Subsection "is_endpoint" .Vb 1 \& my $success = $r\->is_endpoint; .Ve .PP Check if this route qualifies as an endpoint. .ie n .SS """is_websocket""" .el .SS "\f(CWis_websocket\fP" .IX Subsection "is_websocket" .Vb 1 \& my $success = $r\->is_websocket; .Ve .PP Check if this route is a WebSocket. .ie n .SS """name""" .el .SS "\f(CWname\fP" .IX Subsection "name" .Vb 2 \& my $name = $r\->name; \& $r = $r\->name(\*(Aqfoo\*(Aq); .Ve .PP The name of this route, defaults to an automatically generated name based on the route pattern. Note that the name \f(CW\*(C`current\*(C'\fR is reserved for refering to the current route. .PP .Vb 1 \& $r\->get(\*(Aq/user\*(Aq)\->to(\*(Aquser#show\*(Aq)\->name(\*(Aqshow_user\*(Aq); .Ve .ie n .SS """options""" .el .SS "\f(CWoptions\fP" .IX Subsection "options" .Vb 1 \& my $route = $r\->options(\*(Aq/:foo\*(Aq => sub {...}); .Ve .PP Generate route matching only \f(CW\*(C`OPTIONS\*(C'\fR requests. See also the Mojolicious::Lite tutorial for more argument variations. .PP .Vb 1 \& $r\->options(\*(Aq/user\*(Aq)\->to(\*(Aquser#overview\*(Aq); .Ve .ie n .SS """over""" .el .SS "\f(CWover\fP" .IX Subsection "over" .Vb 2 \& my $over = $r\->over; \& $r = $r\->over(foo => qr/\ew+/); .Ve .PP Activate conditions for this route. Note that this automatically disables the routing cache, since conditions are too complex for caching. .PP .Vb 1 \& $r\->get(\*(Aq/foo\*(Aq)\->over(host => qr/mojolicio\e.us/)\->to(\*(Aqfoo#bar\*(Aq); .Ve .ie n .SS """parse""" .el .SS "\f(CWparse\fP" .IX Subsection "parse" .Vb 3 \& $r = $r\->parse(\*(Aq/:action\*(Aq); \& $r = $r\->parse(\*(Aq/:action\*(Aq, action => qr/\ew+/); \& $r = $r\->parse(format => 0); .Ve .PP Parse a pattern. .ie n .SS """patch""" .el .SS "\f(CWpatch\fP" .IX Subsection "patch" .Vb 1 \& my $route = $r\->patch(\*(Aq/:foo\*(Aq => sub {...}); .Ve .PP Generate route matching only \f(CW\*(C`PATCH\*(C'\fR requests. See also the Mojolicious::Lite tutorial for more argument variations. .PP .Vb 1 \& $r\->patch(\*(Aq/user\*(Aq)\->to(\*(Aquser#update\*(Aq); .Ve .ie n .SS """post""" .el .SS "\f(CWpost\fP" .IX Subsection "post" .Vb 1 \& my $route = $r\->post(\*(Aq/:foo\*(Aq => sub {...}); .Ve .PP Generate route matching only \f(CW\*(C`POST\*(C'\fR requests. See also the Mojolicious::Lite tutorial for more argument variations. .PP .Vb 1 \& $r\->post(\*(Aq/user\*(Aq)\->to(\*(Aquser#create\*(Aq); .Ve .ie n .SS """put""" .el .SS "\f(CWput\fP" .IX Subsection "put" .Vb 1 \& my $route = $r\->put(\*(Aq/:foo\*(Aq => sub {...}); .Ve .PP Generate route matching only \f(CW\*(C`PUT\*(C'\fR requests. See also the Mojolicious::Lite tutorial for more argument variations. .PP .Vb 1 \& $r\->put(\*(Aq/user\*(Aq)\->to(\*(Aquser#replace\*(Aq); .Ve .ie n .SS """remove""" .el .SS "\f(CWremove\fP" .IX Subsection "remove" .Vb 1 \& $r = $r\->remove; .Ve .PP Remove route from parent. .PP .Vb 2 \& # Remove route completely \& $r\->find(\*(Aqfoo\*(Aq)\->remove; \& \& # Reattach route to new parent \& $r\->route(\*(Aq/foo\*(Aq)\->add_child($r\->find(\*(Aqbar\*(Aq)\->remove); .Ve .ie n .SS """render""" .el .SS "\f(CWrender\fP" .IX Subsection "render" .Vb 2 \& my $path = $r\->render($suffix); \& my $path = $r\->render($suffix, {foo => \*(Aqbar\*(Aq}); .Ve .PP Render route with parameters into a path. .ie n .SS """root""" .el .SS "\f(CWroot\fP" .IX Subsection "root" .Vb 1 \& my $root = $r\->root; .Ve .PP The Mojolicious::Routes object this route is an ancestor of. .PP .Vb 1 \& $r\->root\->cache(0); .Ve .ie n .SS """route""" .el .SS "\f(CWroute\fP" .IX Subsection "route" .Vb 4 \& my $route = $r\->route; \& my $route = $r\->route(\*(Aq/:action\*(Aq); \& my $route = $r\->route(\*(Aq/:action\*(Aq, action => qr/\ew+/); \& my $route = $r\->route(format => 0); .Ve .PP Generate route matching all \s-1HTTP\s0 request methods. .ie n .SS """to""" .el .SS "\f(CWto\fP" .IX Subsection "to" .Vb 11 \& $r = $r\->to(action => \*(Aqfoo\*(Aq); \& $r = $r\->to({action => \*(Aqfoo\*(Aq}); \& $r = $r\->to(\*(Aqcontroller#action\*(Aq); \& $r = $r\->to(\*(Aqcontroller#action\*(Aq, foo => \*(Aqbar\*(Aq); \& $r = $r\->to(\*(Aqcontroller#action\*(Aq, {foo => \*(Aqbar\*(Aq}); \& $r = $r\->to($app); \& $r = $r\->to($app, foo => \*(Aqbar\*(Aq); \& $r = $r\->to($app, {foo => \*(Aqbar\*(Aq}); \& $r = $r\->to(\*(AqMyApp\*(Aq); \& $r = $r\->to(\*(AqMyApp\*(Aq, foo => \*(Aqbar\*(Aq); \& $r = $r\->to(\*(AqMyApp\*(Aq, {foo => \*(Aqbar\*(Aq}); .Ve .PP Set default parameters for this route. .ie n .SS """to_string""" .el .SS "\f(CWto_string\fP" .IX Subsection "to_string" .Vb 1 \& my $string = $r\->to_string; .Ve .PP Stringify the whole route. .ie n .SS """under""" .el .SS "\f(CWunder\fP" .IX Subsection "under" .Vb 2 \& my $route = $r\->under(sub {...}); \& my $route = $r\->under(\*(Aq/:foo\*(Aq); .Ve .PP Generate bridge. See also the Mojolicious::Lite tutorial for more argument variations. .PP .Vb 3 \& my $auth = $r\->under(\*(Aq/user\*(Aq)\->to(\*(Aquser#auth\*(Aq); \& $auth\->get(\*(Aq/show\*(Aq)\->to(\*(Aq#show\*(Aq); \& $auth\->post(\*(Aq/create\*(Aq)\->to(\*(Aq#create\*(Aq); .Ve .ie n .SS """via""" .el .SS "\f(CWvia\fP" .IX Subsection "via" .Vb 4 \& my $methods = $r\->via; \& $r = $r\->via(\*(AqGET\*(Aq); \& $r = $r\->via(qw(GET POST)); \& $r = $r\->via([qw(GET POST)]); .Ve .PP Restrict \s-1HTTP\s0 methods this route is allowed to handle, defaults to no restrictions. .PP .Vb 1 \& $r\->route(\*(Aq/foo\*(Aq)\->via(qw(GET POST))\->to(\*(Aqfoo#bar\*(Aq); .Ve .ie n .SS """websocket""" .el .SS "\f(CWwebsocket\fP" .IX Subsection "websocket" .Vb 1 \& my $websocket = $r\->websocket(\*(Aq/:foo\*(Aq => sub {...}); .Ve .PP Generate route matching only \f(CW\*(C`WebSocket\*(C'\fR handshakes. See also the Mojolicious::Lite tutorial for more argument variations. .PP .Vb 1 \& $r\->websocket(\*(Aq/echo\*(Aq)\->to(\*(Aqexample#echo\*(Aq); .Ve .SH "SHORTCUTS" .IX Header "SHORTCUTS" In addition to the attributes and methods above you can also call shortcuts on Mojolicious::Routes::Route objects. .PP .Vb 4 \& $r\->root\->add_shortcut(firefox => sub { \& my ($r, $path) = @_; \& $r\->get($path, agent => qr/Firefox/); \& }); \& \& $r\->firefox(\*(Aq/welcome\*(Aq)\->to(\*(Aqfirefox#welcome\*(Aq); \& $r\->firefox(\*(Aq/bye\*(Aq)\->to(\*(Aqfirefox#bye); .Ve .SH "SEE ALSO" .IX Header "SEE ALSO" Mojolicious, Mojolicious::Guides, .