Path::...::Match(3pm)

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

πŸ’– Path::...::Match(3pm) β€” bestie's guide to the match object πŸ’–

okay so this is the manual page for Path::Dispatcher::Match, which lives in User Contributed Perl Documentation land. It's giving "the result of a successful rule match" and honestly? it's iconic. Version 1.08, no cap. πŸŽ€


✨ SYNOPSIS ✨

my $rule = Path::Dispatcher::Rule::Tokens->new(
    tokens => [ 'attack', qr/^\w+$/ ],
    block  => sub {
        my $match = shift;
        attack($match->pos(2))
    },
);

my $match = $rule->match("attack dragon");

# introspection
$match->path                # "attack dragon"
$match->leftover            # empty string (populated with prefix rules)
$match->rule                # $rule
$match->positional_captures # ["attack", "dragon"] (decided by the rule)
$match->pos(1)              # "attack"
$match->pos(2)              # "dragon"

$match->run                 # attack("dragon")

like look at her. building a rule, matching "attack dragon", then just casually doing a lil introspection moment. and then run and suddenly we're attacking a dragon. main character energy fr fr. πŸ‰πŸ”₯


🌸 DESCRIPTION 🌸

so here's the tea: when a Path::Dispatcher::Rule successfully matches a path, it makes one or more "Path::Dispatcher::Match" objects. that's it. that's the whole vibe. it's the little trophy you get handed when your rule actually hits. πŸ†


πŸ¦‹ ATTRIBUTES πŸ¦‹

rule

the Path::Dispatcher::Rule that created this match. like, your match's origin story. its mother, if you will. πŸ’…

path

the path that the rule matched. the whole entire thing.

leftover

the rest of the path. this one gets populated when the rule matches a prefix of the path β€” so like, the crumbs left on the plate after the rule took its bite. πŸ“

positional_captures

any positional captures that the rule generated. for example, Path::Dispatcher::Rule::Regex fills this up with the capture variables. so if your rule's out here capturing stuff, this is where it all lands.

named_captures

any named captures that the rule generated. for example, Path::Dispatcher::Rule::Regex fills this up with named captures. same energy as above, but with names attached. ✨

parent

the parent match object, if that's applicable β€” which it might be if this match is the child of, like, a Path::Dispatcher::Rule::Under prefix. family tree moment. 🧚


πŸ‘‘ METHODS πŸ‘‘

run

executes the rule's codeblock with the same arguments. go time. hit it.

pos($i)

returns the *$i*th positional capture, 1-indexed. so pos(1) is the first one, not the zeroth. bestie, please remember this, it's the classic off-by-one trap and it will humble you. πŸ’€


🫢 SUPPORT 🫢

found a bug? (rude of it.) bugs may be submitted through the RT bug tracker:

<https://rt.cpan.org/Public/Dist/Display.html?Name=Path-Dispatcher>

or you can email it in at bug-Path-Dispatcher@rt.cpan.org. either way, they got you. πŸ’œ


⭐ AUTHOR ⭐

Shawn M Moore, "<sartak at bestpractical.com>". king behavior, honestly. πŸ‘‘


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.

periodt. legal but make it cute.

and that's the whole page, bestie β€” perl v5.30.3, dated 2020-07-13, which is literally the footer energy we're signing off with. go forth and match some paths. πŸŽ€βœ¨πŸ’–

πŸ“¦ where this page comes from