1Path::Dispatcher::CookbUosoekr(3Cpomn)tributed Perl DocuPmaetnht:a:tDiiosnpatcher::Cookbook(3pm)
2
3
4
6 Path::Dispatcher::Cookbook - A cookbook for Path::Dispatcher
7
9 version 1.08
10
12 Path::Dispatcher::Cookbook - A cookbook for Path::Dispatcher
13
15 How can I change the path delimiter from a space ' ' to a slash '/'?
16 When importing the Path::Dispatcher::Declarative sugar, specify the
17 "token_delimiter" option for the "default" group.
18
19 package My::Dispatcher;
20 use Path::Dispatcher::Declarative -base, -default => {
21 token_delimiter => '/',
22 };
23
24 Or define a subclass of Path::Dispatcher::Declarative with a
25 "token_delimiter" method:
26
27 package Web::Dispatcher::Maker;
28 use base 'Path::Dispatcher::Declarative';
29
30 use constant token_delimiter => '/';
31
32
33 package My::Dispatcher;
34 use Web::Dispatcher::Maker -base;
35
36 How can I do rule chaining (like in Catalyst)?
37 You can use a "chain" rule approximate chaining behavior:
38
39 package MyDispatcher;
40 use Path::Dispatcher::Declarative -base;
41
42 under show => sub {
43 chain {
44 print "Displaying ";
45 };
46 on inventory => sub {
47 print "inventory:\n";
48 ...
49 };
50 on score => sub {
51 print "score:\n";
52 ...
53 };
54 };
55
56 package main;
57
58 MyDispatcher->run("show inventory"); # "Displaying inventory:\n ..."
59
60 MyDispatcher->run("show score"); # "Displaying score:\n ..."
61
62 How can I configure tab completion for shells?
63 First add a dispatcher rule for generating completions based on the
64 path. Here we name it _gencomp, so that if the user types "app _gencomp
65 hel" it will print out the various completions of "hel".
66
67 on qr/^_gencomp\s*(.*)/ => sub {
68 my $prefix = shift->pos(1);
69 $prefix = "" if !defined($prefix);
70 print "$_\n" for dispatcher->complete($prefix);
71 };
72
73 Then tell your shell about how to use _gencomp. For zsh it might look
74 like this (replace "APP" with your binary name):
75
76 /usr/share/zsh/site-functions/_APP:
77 #compdef APP
78 typeset -a APP_completions
79 APP_completions=($($words[1] _gencomp $words[2,-1]))
80 compadd $APP_completions
81
82 For bash it might look like this:
83
84 /etc/bash_completion.d/APP.bash:
85 function _APP_()
86 {
87 COMPREPLY=($($1 _gencomp ${COMP_WORDS[COMP_CWORD]}))
88 }
89
90 complete -F _APP_ APP
91
93 Bugs may be submitted through the RT bug tracker
94 <https://rt.cpan.org/Public/Dist/Display.html?Name=Path-Dispatcher> (or
95 bug-Path-Dispatcher@rt.cpan.org <mailto:bug-Path-
96 Dispatcher@rt.cpan.org>).
97
99 Shawn M Moore, "<sartak at bestpractical.com>"
100
102 This software is copyright (c) 2020 by Shawn M Moore.
103
104 This is free software; you can redistribute it and/or modify it under
105 the same terms as the Perl 5 programming language system itself.
106
107
108
109perl v5.34.0 2022-01-21 Path::Dispatcher::Cookbook(3pm)