Path::...::Rule(3pm)
π Path::...::Rule π
okay bestie so this is the manual page for Path::...::Rule from the User Contributed Perl Documentation, section 3pm. it's the lil rule class behind Path::Dispatcher and honestly? it's giving predicate and codeblock. periodt. β¨
β¨ VERSION β¨
this is version 1.08, no cap.
πΈ SYNOPSIS πΈ
okay so here's the whole vibe in code:
my $rule = Path::Dispatcher::Rule::Regex->new(
regex => qr/^quit/,
block => sub { die "Program terminated by user.\n" },
);
$rule->match("die"); # undef, because "die" !~ /^quit/
my $match = $rule->match("quit"); # creates a Path::Dispatcher::Match
$match->run; # exits the program
see how "die" gets absolutely nothing back? that's because "die" !~ /^quit/ β the vibe check failed π. but "quit"? it matches, makes you a Path::Dispatcher::Match, and then run literally exits the program. iconic behaviour fr fr.
π¦ DESCRIPTION π¦
so a rule has two things: a predicate and an optional codeblock. that's the whole personality. π«Ά
- rules can be matched β that's when you check the predicate against the path
- rules can be ran β that's when you invoke the codeblock
β οΈ important bestie: this class is not meant to be instantiated directly, because there's literally no predicate matching function in it. you'd just be holding a rule that can't rule. instead, use one of the subclasses, like Path::Dispatcher::Rule::Tokens. iykyk π
π ATTRIBUTES π
block
an optional block of code that's gonna get run. but listen β please use the run method instead of poking this attribute directly. don't do it. i'm begging π
prefix
a boolean, and it answers the question: "can this rule match just a prefix of a path?" π
- if it's false, then the predicate has to match the entire path. no shortcuts.
- one use-case? say you want a catch-all rule that matches anything beginning with the token
ticket. super valid. and the unmatched, latter part of the path will be available in the match object. slay.
β METHODS β
match path -> match
takes a path, and if it matched the predicate you get back a Path::Dispatcher::Match object. if it didn't? you get undef. that's it, that's the deal. π
the match object is carrying all the info about the match, like:
- the results (for regex, that's a list of the captured variables, bestie)
- the
"leftover"path, if"prefix"matching was used - etc.
run
runs the rule's codeblock. simple. but if there's no codeblock present, it throws an exception. so like... don't run an empty rule and act surprised π
π§ SUPPORT π§
got bugs? yeah, same. they may be submitted through the RT bug tracker <https://rt.cpan.org/Public/Dist/Display.html?Name=Path-Dispatcher> (or bug-Path-Dispatcher@rt.cpan.org <mailto:bug-Path-Dispatcher@rt.cpan.org>). go off π
π AUTHOR π
Shawn M Moore, "<sartak at bestpractical.com>" β the main character who wrote this. we stan.
π COPYRIGHT AND LICENSE π
This software is copyright (c) 2020 by Shawn M Moore.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
and that's the whole page, bestie π this was perl v5.30.3, dated 2020-07-13, and you've officially reached the end of Path::...::Rule(3pm). go write some rules, they're gonna eat π₯πΈ
π¦ where this page comes from
- debian bookworm: libpath-dispatcher-perl 1.08-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libpath-dispatcher-perl 1.08-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu jammy: libpath-dispatcher-perl 1.08-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libpath-dispatcher-perl 1.08-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libpath-dispatcher-perl 1.08-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libpath-dispatcher-perl 1.08-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms