Path::...okbook(3pm)
π Path::...okbook β the manual page, but make it make sense π
okay bestie, this is a User Contributed Perl Documentation page for Path::...okbook(3pm) β yes the header literally abbreviates it like that, it's giving mysterious π
. Buckle up, we're doing cookbook recipes for Path::Dispatcher and I promise it's gonna be delicious. π
β¨ NAME β¨
Path::Dispatcher::Cookbook β a cookbook for Path::Dispatcher. That's it, that's the whole name, no notes. π
πΈ VERSION πΈ
version 1.08 β locked in, slay. π
π NAME π
okay so not me noticing it says Path::Dispatcher::Cookbook again β "a cookbook for Path::Dispatcher" β like yes girl we heard you the first time, iconic of it honestly. ππ
π³ RECIPES π³
the actual good part, the main character energy, let's GO. π§
π¦ How can I change the path delimiter from a space ' ' to a slash '/'?
bestie, two ways, pick your fighter. π
Option one: when you import the Path::Dispatcher::Declarative sugar, just specify the token_delimiter option for the default group. Like so:
package My::Dispatcher;
use Path::Dispatcher::Declarative -base, -default => {
token_delimiter => '/',
};
Option two: define a subclass of Path::Dispatcher::Declarative with a token_delimiter method:
package Web::Dispatcher::Maker;
use base 'Path::Dispatcher::Declarative';
use constant token_delimiter => '/';
package My::Dispatcher;
use Web::Dispatcher::Maker -base;
both valid, both ate. β¨
π¦ How can I do rule chaining (like in Catalyst)?
you can use a chain rule to approximate chaining behavior β here's the vibe:
package MyDispatcher;
use Path::Dispatcher::Declarative -base;
under show => sub {
chain {
print "Displaying ";
};
on inventory => sub {
print "inventory:\n";
...
};
on score => sub {
print "score:\n";
...
};
};
package main;
MyDispatcher->run("show inventory"); # "Displaying inventory:\n ..."
MyDispatcher->run("show score"); # "Displaying score:\n ..."
the chain block runs first, then the matching on block does its thing β and look at those outputs, "Displaying inventory:\n ..." and "Displaying score:\n ...", chef's kiss. ππ₯
π¦ How can I configure tab completion for shells?
step one, bestie: add a dispatcher rule for generating completions based on the path. Here we name it _gencomp, so that if the user types app _gencomp hel it will print out the various completions of hel. Obsessed. π
on qr/^_gencomp\s*(.*)/ => sub {
my $prefix = shift->pos(1);
$prefix = "" if !defined($prefix);
print "$_\n" for dispatcher->complete($prefix);
};
step two: tell your shell about how to use _gencomp. For zsh it might look like this β and pls replace APP with your binary name:
/usr/share/zsh/site-functions/_APP:
#compdef APP
typeset -a APP_completions
APP_completions=($($words[1] _gencomp $words[2,-1]))
compadd $APP_completions
For bash it might look like this:
/etc/bash_completion.d/APP.bash:
function _APP_()
{
COMPREPLY=($($1 _gencomp ${COMP_WORDS[COMP_CWORD]}))
}
complete -F _APP_ APP
shell completion unlocked, you're welcome. π«Ά
π SUPPORT π
got bugs? (not the cute kind π) they may be submitted through the RT bug tracker <https://rt.cpan.org/Public/Dist/Display.html?Name=Path-Dispatcher> β or, alternatively, you can email bug-Path-Dispatcher@rt.cpan.org <mailto:bug-Path-Dispatcher@rt.cpan.org>. either way, we listen. π
π AUTHOR π
Shawn M Moore, "<sartak at bestpractical.com>" β thank you for your service, legend. π«‘
β COPYRIGHT AND LICENSE β
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. fr fr, free is free. π
and that's the whole cookbook bestie β go forth, dispatch those paths, and remember: the delimiter is whatever you want it to be, main character. π β¨
signing off from perl v5.30.3, dated 2020-07-13, on the Path::...okbook(3pm) manual page itself β stay iconic, xoxo ππ¦π
π¦ where this page comes from
- debian bookworm: libpath-dispatcher-perl 1.08-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libpath-dispatcher-perl 1.08-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu jammy: libpath-dispatcher-perl 1.08-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libpath-dispatcher-perl 1.08-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libpath-dispatcher-perl 1.08-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libpath-dispatcher-perl 1.08-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms