Path::...::Rule(3pm)

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

πŸ’– 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.


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