[Bps-public-commit] r16388 - in Path-Dispatcher/trunk: lib/Path/Dispatcher/Rule

sartak at bestpractical.com sartak at bestpractical.com
Mon Oct 20 07:24:46 EDT 2008


Author: sartak
Date: Mon Oct 20 07:24:45 2008
New Revision: 16388

Modified:
   Path-Dispatcher/trunk/   (props changed)
   Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule/Tokens.pm

Log:
 r74177 at onn:  sartak | 2008-10-20 07:24:42 -0400
 Rule::Tokens doc


Modified: Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule/Tokens.pm
==============================================================================
--- Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule/Tokens.pm	(original)
+++ Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule/Tokens.pm	Mon Oct 20 07:24:45 2008
@@ -85,3 +85,53 @@
 
 1;
 
+__END__
+
+=head1 NAME
+
+Path::Dispatcher::Rule::Tokens - predicate is a list of tokens
+
+=head1 SYNOPSIS
+
+    my $rule = Path::Dispatcher::Rule::Tokens->new(
+        tokens    => [ "comment", "show", qr/^\d+$/ ],
+        delimiter => '/',
+        block     => sub { display_comment($3) },
+    );
+
+    $rule->match("/comment/show/25");
+
+=head1 DESCRIPTION
+
+Rules of this class use a list of tokens to match the path.
+
+=head1 ATTRIBUTES
+
+=head2 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 C<$1> will be the string's first token, C<$2> its
+second, and C<$3> its third. So matching "ticket display #AAA" would have
+"ticket" in C<$1>, "display" in C<$2>, and "#AAA" in C<$3>.
+
+Capture groups inside a regex token are completely ignored.
+
+=head2 delimiter
+
+A string that is used to tokenize the path. The delimiter must be a string
+because prefix matches use C<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.
+
+=cut
+



More information about the Bps-public-commit mailing list