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

sartak at bestpractical.com sartak at bestpractical.com
Mon Oct 20 08:04:39 EDT 2008


Author: sartak
Date: Mon Oct 20 08:04:39 2008
New Revision: 16390

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

Log:
 r74181 at onn:  sartak | 2008-10-20 08:04:37 -0400
 Rule::Under doc


Modified: Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule/Under.pm
==============================================================================
--- Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule/Under.pm	(original)
+++ Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule/Under.pm	Mon Oct 20 08:04:39 2008
@@ -41,3 +41,55 @@
 
 1;
 
+__END__
+
+=head1 NAME
+
+Path::Dispatcher::Rule::Under - rules under a predicate
+
+=head1 SYNOPSIS
+
+    my $ticket = Path::Dispatcher::Rule::Tokens->new(
+        tokens => [ 'ticket' ],
+        prefix => 1,
+    );
+
+    my $create = Path::Dispatcher::Rule::Tokens->new(
+        tokens => [ 'create' ],
+        block  => sub { create_ticket() },
+    );
+
+    my $delete = Path::Dispatcher::Rule::Tokens->new(
+        tokens => [ 'delete', qr/^\d+$/ ],
+        block  => sub { delete_ticket($2) },
+    );
+
+    my $rule = Path::Dispatcher::Rule::Under->new(
+        predicate => $ticket,
+        rules     => [ $create, $delete ],
+    );
+
+    $rule->match("ticket create");
+    $rule->match("ticket delete 3");
+
+=head1 DESCRIPTION
+
+Rules of this class have two-phase matching: if the predicate is matched, then
+the contained rules are matched. The benefit of this is less repetition of the
+predicate, both in terms of code and in matching it.
+
+=head1 ATTRIBUTES
+
+=head2 predicate
+
+A rule (which I<must> match prefixes) whose match determines whether the
+contained rules are considered. The leftover path of the predicate is used
+as the path for the contained rules.
+
+=head2 rules
+
+A list of rules that will be try to be matched only if the predicate is
+matched.
+
+=cut
+



More information about the Bps-public-commit mailing list