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

sartak at bestpractical.com sartak at bestpractical.com
Wed Aug 27 11:57:09 EDT 2008


Author: sartak
Date: Wed Aug 27 11:57:09 2008
New Revision: 15538

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

Log:
 r70569 at onn:  sartak | 2008-08-27 11:57:05 -0400
 Add a synopsis which uses the API


Modified: Path-Dispatcher/trunk/lib/Path/Dispatcher.pm
==============================================================================
--- Path-Dispatcher/trunk/lib/Path/Dispatcher.pm	(original)
+++ Path-Dispatcher/trunk/lib/Path/Dispatcher.pm	Wed Aug 27 11:57:09 2008
@@ -149,6 +149,29 @@
 
 Path::Dispatcher - flexible dispatch
 
+=head1 SYNOPSIS
+
+    use Path::Dispatcher;
+    my $dispatcher = Path::Dispatcher->new;
+
+    $dispatcher->stage("on")->add_rule(
+        Path::Dispacher::Rule::Regex->new(
+            regex => qr{^/(foo)/.*},
+            block => sub { warn $1; }, # foo
+        )
+    );
+
+    $dispatcher->stage("on")->add_rule(
+        Path::Dispacher::Rule::CodeRef->new(
+            matcher => sub { /^\d+$/ && $_ % 2 == 0 },
+            block   => sub { warn "$_ is an even number" },
+        )
+    );
+
+    my $dispatch = $dispatcher->dispatch("/foo/bar");
+    die "404" unless $dispatch->has_matches;
+    $dispatch->run;
+
 =head1 DESCRIPTION
 
 We really like L<Jifty::Dispatcher> and wanted to use it for the command line.



More information about the Bps-public-commit mailing list