Path::...CodeRef(3pm)

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

πŸ’… Path::Dispatcher::Rule::CodeRef (3pm)

okay bestie, so this is a page from the User Contributed Perl Documentation (the 3pm kind, you know the vibe), and it's about a module called Path::Dispatcher::Rule::CodeRef πŸŽ€


✨ NAME ✨

Path::Dispatcher::Rule::CodeRef β€” the predicate is literally any subroutine. like, any one. your imagination is the limit, no cap πŸ’–


🌸 VERSION 🌸

version 1.08 β€” she's serving exactly this version, don't @ me ✨


πŸ¦‹ SYNOPSIS πŸ¦‹

my $rule = Path::Dispatcher::Rule::CodeRef->new(
    matcher => sub { time % 2 },
    block => sub { warn "Odd time!" },
);

my $undef = $rule->match("foo"); # even time; no match :)

my $match = $rule->match("foo"); # odd time; creates a Path::Dispatcher::Match

$rule->run; # warns "Odd time!"

so yes, that matcher is just vibing on time % 2 and the whole rule is basically a coin flip. iconic behavior honestly 😭


🌈 DESCRIPTION 🌈

Rules in this class can match arbitrarily complex values. the way that they can match literally anything… main character energy fr fr πŸ’…

BUT β€” and this is the important part, listen up β€” you should only reach for this when there is no other recourse, because there's no way we can inspect how things match. like, the module literally cannot see inside your little coderef and figure out what's going on. it's giving mystery box πŸ“¦

You're much better off creating a custom subclass of Path::Dispatcher::Rule if that's at all possible. do that instead, bestie, please πŸ™


πŸ’œ ATTRIBUTES πŸ’œ

πŸ“ matcher

A coderef that returns undef if there's no match β€” otherwise it returns a list of strings (the results). so: no match β†’ undef, match β†’ list of strings. simple as 🫢

The coderef receives the path object as its argument, and the path string as $_. both at once, she's flexible like that ✨


🧚 SUPPORT 🧚

Found a bug? πŸ’€ Same. Bugs may be submitted through the RT bug tracker:

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

(or, if email is more your vibe, hit up bug-Path-Dispatcher@rt.cpan.org πŸ’Œ)


πŸ‘‘ AUTHOR πŸ‘‘

Shawn M Moore, "sartak at bestpractical.com" β€” shoutout to the author, we love a legend 🫑⭐


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. slay, open source queen πŸ’–


okay and for the lil' sign-off: this gorgeous page was rendered by perl v5.30.3 on 2020-07-13, under the Path::...CodeRef(3pm) manual name. that's the whole thing bestie, go write a custom subclass instead of using this rule, mwah πŸ’…βœ¨πŸŽ€

πŸ“¦ where this page comes from