Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

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

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

NAME
Path::Dispatcher::Rule - predicate and codeblock SYNOPSIS
my $rule = Path::Dispatcher::Rule::Regex->new( regex => qr/^quit/, block => sub { die "Program terminated by user. " }, ); $rule->match("die"); # undef, because "die" !~ /^quit/ my $match = $rule->match("quit"); # creates a Path::Dispatcher::Match $match->run; # exits the program DESCRIPTION
A rule has a predicate and an optional codeblock. Rules can be matched (which checks the predicate against the path) and they can be ran (which invokes the codeblock). This class is not meant to be instantiated directly, because there is no predicate matching function. Instead use one of the subclasses such as Path::Dispatcher::Rule::Tokens. ATTRIBUTES
block An optional block of code to be run. Please use the "run" method instead of invoking this attribute directly. prefix A boolean indicating whether this rule can match a prefix of a path. If false, then the predicate must match the entire path. One use-case is that you may want a catch-all rule that matches anything beginning with the token "ticket". The unmatched, latter part of the path will be available in the match object. METHODS
match path -> match Takes a path and returns a Path::Dispatcher::Match object if it matched the predicate, otherwise "undef". The match object contains information about the match, such as the results (e.g. for regex, a list of the captured variables), the "leftover" path if "prefix" matching was used, etc. run Runs the rule's codeblock. If none is present, it throws an exception. perl v5.12.4 2011-08-30 Path::Dispatcher::Rule(3pm)

Check Out this Related 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)
Man Page