Path::...okbook(3pm)

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

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

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