1Mojolicious::Routes::PaUtsteerrnC(o3n)tributed Perl DocuMmoejnotlaitciioonus::Routes::Pattern(3)
2
3
4
6 Mojolicious::Routes::Pattern - Route pattern
7
9 use Mojolicious::Routes::Pattern;
10
11 # Create pattern
12 my $pattern = Mojolicious::Routes::Pattern->new('/test/:name');
13
14 # Match routes
15 my $captures = $pattern->match('/test/sebastian');
16 say $captures->{name};
17
19 Mojolicious::Routes::Pattern is the core of Mojolicious::Routes.
20
22 Mojolicious::Routes::Pattern implements the following attributes.
23
24 constraints
25 my $constraints = $pattern->constraints;
26 $pattern = $pattern->constraints({foo => qr/\w+/});
27
28 Regular expression constraints.
29
30 defaults
31 my $defaults = $pattern->defaults;
32 $pattern = $pattern->defaults({foo => 'bar'});
33
34 Default parameters.
35
36 placeholder_start
37 my $start = $pattern->placeholder_start;
38 $pattern = $pattern->placeholder_start(':');
39
40 Character indicating a placeholder, defaults to ":".
41
42 placeholders
43 my $placeholders = $pattern->placeholders;
44 $pattern = $pattern->placeholders(['foo', 'bar']);
45
46 Placeholder names.
47
48 quote_end
49 my $end = $pattern->quote_end;
50 $pattern = $pattern->quote_end('}');
51
52 Character indicating the end of a quoted placeholder, defaults to ">".
53
54 quote_start
55 my $start = $pattern->quote_start;
56 $pattern = $pattern->quote_start('{');
57
58 Character indicating the start of a quoted placeholder, defaults to
59 "<".
60
61 regex
62 my $regex = $pattern->regex;
63 $pattern = $pattern->regex($regex);
64
65 Pattern in compiled regular expression form.
66
67 relaxed_start
68 my $start = $pattern->relaxed_start;
69 $pattern = $pattern->relaxed_start('*');
70
71 Character indicating a relaxed placeholder, defaults to "#".
72
73 tree
74 my $tree = $pattern->tree;
75 $pattern = $pattern->tree([['text', '/foo']]);
76
77 Pattern in parsed form. Note that this structure should only be used
78 very carefully since it is very dynamic.
79
80 type_start
81 my $start = $pattern->type_start;
82 $pattern = $pattern->type_start('|');
83
84 Character indicating the start of a placeholder type, defaults to ":".
85
86 types
87 my $types = $pattern->types;
88 $pattern = $pattern->types({int => qr/[0-9]+/});
89
90 Placeholder types.
91
92 unparsed
93 my $unparsed = $pattern->unparsed;
94 $pattern = $pattern->unparsed('/:foo/:bar');
95
96 Raw unparsed pattern.
97
98 wildcard_start
99 my $start = $pattern->wildcard_start;
100 $pattern = $pattern->wildcard_start('*');
101
102 Character indicating the start of a wildcard placeholder, defaults to
103 "*".
104
106 Mojolicious::Routes::Pattern inherits all methods from Mojo::Base and
107 implements the following new ones.
108
109 match
110 my $captures = $pattern->match('/foo/bar');
111 my $captures = $pattern->match('/foo/bar', 1);
112
113 Match pattern against entire path, format detection is disabled by
114 default.
115
116 match_partial
117 my $captures = $pattern->match_partial(\$path);
118 my $captures = $pattern->match_partial(\$path, 1);
119
120 Match pattern against path and remove matching parts, format detection
121 is disabled by default.
122
123 new
124 my $pattern = Mojolicious::Routes::Pattern->new;
125 my $pattern = Mojolicious::Routes::Pattern->new('/:action');
126 my $pattern
127 = Mojolicious::Routes::Pattern->new('/:action', action => qr/\w+/);
128 my $pattern = Mojolicious::Routes::Pattern->new(format => 0);
129
130 Construct a new Mojolicious::Routes::Pattern object and "parse" pattern
131 if necessary.
132
133 parse
134 $pattern = $pattern->parse('/:action');
135 $pattern = $pattern->parse('/:action', action => qr/\w+/);
136 $pattern = $pattern->parse(format => 0);
137
138 Parse pattern.
139
140 render
141 my $path = $pattern->render({action => 'foo'});
142 my $path = $pattern->render({action => 'foo'}, 1);
143
144 Render pattern into a path with parameters, format rendering is
145 disabled by default.
146
148 Mojolicious, Mojolicious::Guides, <https://mojolicious.org>.
149
150
151
152perl v5.28.1 2018-11-22 Mojolicious::Routes::Pattern(3)