Path::...::Under(3pm)
β¨ NAME β¨
Path::Dispatcher::Rule::Under β rules under a predicate π«Ά
Like, it's a rule that wraps a whole lil squad of other rules and makes them all share one predicate. So cute, so efficient.
π VERSION π
version 1.08 β¨
πΈ SYNOPSIS πΈ
my $ticket = Path::Dispatcher::Rule::Tokens->new(
tokens => [ 'ticket' ],
prefix => 1,
);
my $create = Path::Dispatcher::Rule::Tokens->new(
tokens => [ 'create' ],
block => sub { create_ticket() },
);
my $delete = Path::Dispatcher::Rule::Tokens->new(
tokens => [ 'delete', qr/^\d+$/ ],
block => sub { delete_ticket(shift->pos(2)) },
);
my $rule = Path::Dispatcher::Rule::Under->new(
predicate => $ticket,
rules => [ $create, $delete ],
);
$rule->match("ticket create");
$rule->match("ticket delete 3");
π DESCRIPTION π
Okay so rules of this class do two-phase matching, and it's giving genius:
- first the
predicategets matched, - and only if that hits, then the contained rules get matched.
Why do we care? Because it means you're not out here copy-pasting the same predicate over and over β less repetition in your code, and less work in the matching too. Efficiency queen behavior, honestly. π
π ATTRIBUTES π
predicate
A rule (and it must match prefixes, bestie, that part is non-negotiable) whose match decides whether the contained rules even get considered at all.
The leftover path from the predicate? That becomes the path for the contained rules. Snatched and reused, no cap. π¦
rules
A list of rules that will try to be matched β but only if the predicate matched first. No predicate match, no rules getting checked. That's the vibe check and they did not pass. π
π¦ SUPPORT π¦
Found a bug? π Don't suffer in silence, submit it through the RT bug tracker:
<https://rt.cpan.org/Public/Dist/Display.html?Name=Path-Dispatcher>
(or email bug-Path-Dispatcher@rt.cpan.org <mailto:bug-Path-Dispatcher@rt.cpan.org>)
Fr fr, the RT tracker is the move β slide in there with your bug report. π«Ά
π AUTHOR π
Shawn M Moore, "<sartak at bestpractical.com>" β king behavior, 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 one's running on perl v5.30.3 and it's dated 2020-07-13 β iconic from day one. Go forth and nest your rules, you absolute legend. πβ¨π¦
π¦ 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