GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Path::Dispatcher::Cookbook(3) User Contributed Perl Documentation Path::Dispatcher::Cookbook(3)

Path::Dispatcher::Cookbook - A cookbook for Path::Dispatcher

version 1.08

Path::Dispatcher::Cookbook - A cookbook for Path::Dispatcher

When importing the Path::Dispatcher::Declarative sugar, specify the "token_delimiter" option for the "default" group.

    package My::Dispatcher;
    use Path::Dispatcher::Declarative -base, -default => {
        token_delimiter => '/',
    };

Or 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;

You can use a "chain" rule approximate chaining behavior:

    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 ..."

First 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".

    on qr/^_gencomp\s*(.*)/ => sub {
        my $prefix = shift->pos(1);
        $prefix = "" if !defined($prefix);
        print "$_\n" for dispatcher->complete($prefix);
    };

Then tell your shell about how to use _gencomp. For zsh it might look like this (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

Bugs may be submitted through the RT bug tracker <https://rt.cpan.org/Public/Dist/Display.html?Name=Path-Dispatcher> (or bug-Path-Dispatcher@rt.cpan.org <mailto:bug-Path-Dispatcher@rt.cpan.org>).

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.

2020-07-12 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.