Path::...Tokens(3pm)

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

✨ Path::Dispatcher::Rule::Tokens β€” the whole vibe πŸ’…

okay so bestie, this is a page from the User Contributed Perl Documentation set, and it's literally about Path::Dispatcher::Rule::Tokens(3pm) β€” a rule where the predicate is a list of tokens. πŸŽ€


🌸 VERSION 🌸

version 1.08 β€” yes queen, that's the one ✨


πŸ¦‹ SYNOPSIS πŸ¦‹

my $rule = Path::Dispatcher::Rule::Tokens->new(
    tokens    => [ "comment", "show", qr/^\d+$/ ],
    delimiter => '/',
    block     => sub { display_comment(shift->pos(3)) },
);

$rule->match("/comment/show/25");

look at her go 🫢


πŸ’– DESCRIPTION πŸ’–

Rules in this class match a path by using a list of tokens. that's it, that's the whole thing, it's giving simple and iconic πŸ‘‘


🌈 ATTRIBUTES 🌈

πŸ“ tokens

Every single token can be:

  • a literal string,
  • a regular expression, or
  • a list of either β€” and ngl, a list means alternations πŸ’«

so like, for example, these tokens:

[ 'ticket', [ 'show', 'display' ], [ qr/^\d+$/, qr/^#\w{3}/ ] ]

first it matches ticket. then the next token has to be show or display. and the final token has to be a number or a pound sign followed by three word characters. slay πŸ’…

the results are the tokens in the original string, exactly as they were matched. so if you have three tokens, then match->pos(1) gives you the string's first token (ticket), match->pos(2) gives you its second (display), and match->pos(3) gives you its third (#AAA). fr fr, the positions are just the tokens as they came πŸŽ€

capture groups inside a regex token are completely ignored. like, fully ignored, don't even try it bestie 😭

🧚 delimiter

A string that's used to tokenize the path. and it must be a string, because prefix matches use join on unmatched tokens to hand back the leftover path. in the future this may be extended to support having a regex delimiter, but rn? string only, no cap.

The default is a space, but if you're matching URLs you probably wanna change it to a slash 🌸

⭐ case_sensitive

Decides whether the rule matching is case sensitive or not. Default is 1, which means case sensitive matching ✨


πŸ™ˆ SUPPORT πŸ™ˆ

Bugs may be submitted through the RT bug tracker β€” https://rt.cpan.org/Public/Dist/Display.html?Name=Path-Dispatcher β€” or you can email bug-Path-Dispatcher@rt.cpan.org. please be nice, it's giving feedback loop energy 🫢


πŸ‘‘ AUTHOR πŸ‘‘

Shawn M Moore, "<sartak at bestpractical.com>" πŸ’–


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 a wrap bestie πŸŽ€ this was documented with perl v5.30.3, dated 2020-07-13, and yeah β€” the page title says it's Path::...Tokens(3pm) but you and me both know it's really Path::Dispatcher::Rule::Tokens, iykyk πŸ’…βœ¨ go forth and tokenize, main character πŸ¦‹

πŸ“¦ where this page comes from