Path::...::Under(3pm)

πŸ“¦
version 1.08 Β· 3 versions
, in debian bookworm, debian trixie, ubuntu jammy, ubuntu noble, ubuntu resolute, ubuntu stonking

✨ 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:

  1. first the predicate gets matched,
  2. 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. πŸ‘‘


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