1Path::Dispatcher::Rule:U:sCeordeCRoenft(r3ipbmu)ted PerlPaDtohc:u:mDeinstpaatticohner::Rule::CodeRef(3pm)
2
3
4
6 Path::Dispatcher::Rule::CodeRef - predicate is any subroutine
7
9 version 1.08
10
12 my $rule = Path::Dispatcher::Rule::CodeRef->new(
13 matcher => sub { time % 2 },
14 block => sub { warn "Odd time!" },
15 );
16
17 my $undef = $rule->match("foo"); # even time; no match :)
18
19 my $match = $rule->match("foo"); # odd time; creates a Path::Dispatcher::Match
20
21 $rule->run; # warns "Odd time!"
22
24 Rules of this class can match arbitrarily complex values. This should
25 be used only when there is no other recourse, because there's no way we
26 can inspect how things match.
27
28 You're much better off creating a custom subclass of
29 Path::Dispatcher::Rule if at all possible.
30
32 matcher
33 A coderef that returns "undef" if there's no match, otherwise a list of
34 strings (the results).
35
36 The coderef receives the path object as its argument, and the path
37 string as $_.
38
40 Bugs may be submitted through the RT bug tracker
41 <https://rt.cpan.org/Public/Dist/Display.html?Name=Path-Dispatcher> (or
42 bug-Path-Dispatcher@rt.cpan.org <mailto:bug-Path-
43 Dispatcher@rt.cpan.org>).
44
46 Shawn M Moore, "<sartak at bestpractical.com>"
47
49 This software is copyright (c) 2020 by Shawn M Moore.
50
51 This is free software; you can redistribute it and/or modify it under
52 the same terms as the Perl 5 programming language system itself.
53
54
55
56perl v5.34.0 2022-01-2P1ath::Dispatcher::Rule::CodeRef(3pm)