1Path::Dispatcher::Rule(U3spemr)Contributed Perl DocumentPaattiho:n:Dispatcher::Rule(3pm)
2
3
4

NAME

6       Path::Dispatcher::Rule - predicate and codeblock
7

VERSION

9       version 1.08
10

SYNOPSIS

12           my $rule = Path::Dispatcher::Rule::Regex->new(
13               regex => qr/^quit/,
14               block => sub { die "Program terminated by user.\n" },
15           );
16
17           $rule->match("die"); # undef, because "die" !~ /^quit/
18
19           my $match = $rule->match("quit"); # creates a Path::Dispatcher::Match
20
21           $match->run; # exits the program
22

DESCRIPTION

24       A rule has a predicate and an optional codeblock. Rules can be matched
25       (which checks the predicate against the path) and they can be ran
26       (which invokes the codeblock).
27
28       This class is not meant to be instantiated directly, because there is
29       no predicate matching function. Instead use one of the subclasses such
30       as Path::Dispatcher::Rule::Tokens.
31

ATTRIBUTES

33   block
34       An optional block of code to be run. Please use the "run" method
35       instead of invoking this attribute directly.
36
37   prefix
38       A boolean indicating whether this rule can match a prefix of a path. If
39       false, then the predicate must match the entire path. One use-case is
40       that you may want a catch-all rule that matches anything beginning with
41       the token "ticket".  The unmatched, latter part of the path will be
42       available in the match object.
43

METHODS

45   match path -> match
46       Takes a path and returns a Path::Dispatcher::Match object if it matched
47       the predicate, otherwise "undef". The match object contains information
48       about the match, such as the results (e.g. for regex, a list of the
49       captured variables), the "leftover" path if "prefix" matching was used,
50       etc.
51
52   run
53       Runs the rule's codeblock. If none is present, it throws an exception.
54

SUPPORT

56       Bugs may be submitted through the RT bug tracker
57       <https://rt.cpan.org/Public/Dist/Display.html?Name=Path-Dispatcher> (or
58       bug-Path-Dispatcher@rt.cpan.org <mailto:bug-Path-
59       Dispatcher@rt.cpan.org>).
60

AUTHOR

62       Shawn M Moore, "<sartak at bestpractical.com>"
63
65       This software is copyright (c) 2020 by Shawn M Moore.
66
67       This is free software; you can redistribute it and/or modify it under
68       the same terms as the Perl 5 programming language system itself.
69
70
71
72perl v5.38.0                      2023-07-21       Path::Dispatcher::Rule(3pm)
Impressum