Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

path::dispatcher::rule::tokens(3pm) [debian man page]

Path::Dispatcher::Rule::Tokens(3pm)			User Contributed Perl Documentation		       Path::Dispatcher::Rule::Tokens(3pm)

NAME
Path::Dispatcher::Rule::Tokens - predicate is a list of tokens 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"); DESCRIPTION
Rules of this class use a list of tokens to match the path. ATTRIBUTES
tokens Each token can be a literal string, a regular expression, or a list of either (which are taken to mean alternations). For example, the tokens: [ 'ticket', [ 'show', 'display' ], [ qr/^d+$/, qr/^#w{3}/ ] ] first matches "ticket". Then, the next token must be "show" or "display". The final token must be a number or a pound sign followed by three word characters. The results are the tokens in the original string, as they were matched. If you have three tokens, then "match->pos(1)" will be the string's first token ("ticket"), "match->pos(2)" its second ("display"), and "match->pos(3)" its third ("#AAA"). Capture groups inside a regex token are completely ignored. delimiter A string that is used to tokenize the path. The delimiter must be a string because prefix matches use "join" on unmatched tokens to return the leftover path. In the future this may be extended to support having a regex delimiter. The default is a space, but if you're matching URLs you probably want to change this to a slash. case_sensitive Decide whether the rule matching is case sensitive. Default is 1, case sensitive matching. perl v5.12.4 2011-08-30 Path::Dispatcher::Rule::Tokens(3pm)

Check Out this Related Man Page

Path::Dispatcher::Cookbook(3pm) 			User Contributed Perl Documentation			   Path::Dispatcher::Cookbook(3pm)

NAME
Path::Dispatcher::Cookbook - A cookbook for Path::Dispatcher RECIPES
How can I change the path delimiter from a space ' ' to a slash '/'? 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; How can I do rule chaining (like in Catalyst)? 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: "; ... }; on score => sub { print "score: "; ... }; }; package main; MyDispatcher->run("show inventory"); # "Displaying inventory: ..." MyDispatcher->run("show score"); # "Displaying score: ..." How can I configure tab completion for shells? 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/^_gencomps*(.*)/ => sub { my $prefix = shift->pos(1); $prefix = "" if !defined($prefix); print "$_ " 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 perl v5.12.4 2011-08-30 Path::Dispatcher::Cookbook(3pm)
Man Page