1Path::Dispatcher::Rule:U:sUenrdeCro(n3tprmi)buted Perl DPoactuhm:e:nDtiastpiaotncher::Rule::Under(3pm)
2
3
4
6 Path::Dispatcher::Rule::Under - rules under a predicate
7
9 version 1.08
10
12 my $ticket = Path::Dispatcher::Rule::Tokens->new(
13 tokens => [ 'ticket' ],
14 prefix => 1,
15 );
16
17 my $create = Path::Dispatcher::Rule::Tokens->new(
18 tokens => [ 'create' ],
19 block => sub { create_ticket() },
20 );
21
22 my $delete = Path::Dispatcher::Rule::Tokens->new(
23 tokens => [ 'delete', qr/^\d+$/ ],
24 block => sub { delete_ticket(shift->pos(2)) },
25 );
26
27 my $rule = Path::Dispatcher::Rule::Under->new(
28 predicate => $ticket,
29 rules => [ $create, $delete ],
30 );
31
32 $rule->match("ticket create");
33 $rule->match("ticket delete 3");
34
36 Rules of this class have two-phase matching: if the predicate is
37 matched, then the contained rules are matched. The benefit of this is
38 less repetition of the predicate, both in terms of code and in matching
39 it.
40
42 predicate
43 A rule (which must match prefixes) whose match determines whether the
44 contained rules are considered. The leftover path of the predicate is
45 used as the path for the contained rules.
46
47 rules
48 A list of rules that will be try to be matched only if the predicate is
49 matched.
50
52 Bugs may be submitted through the RT bug tracker
53 <https://rt.cpan.org/Public/Dist/Display.html?Name=Path-Dispatcher> (or
54 bug-Path-Dispatcher@rt.cpan.org <mailto:bug-Path-
55 Dispatcher@rt.cpan.org>).
56
58 Shawn M Moore, "<sartak at bestpractical.com>"
59
61 This software is copyright (c) 2020 by Shawn M Moore.
62
63 This is free software; you can redistribute it and/or modify it under
64 the same terms as the Perl 5 programming language system itself.
65
66
67
68perl v5.36.0 2022-07-22Path::Dispatcher::Rule::Under(3pm)