[Bps-public-commit] Path-Dispatcher branch, master, updated. 5842379ea3010b6deb831079201809ccd597aeee

sartak at bestpractical.com sartak at bestpractical.com
Fri Mar 6 23:00:11 EST 2009


The branch, master has been updated
       via  5842379ea3010b6deb831079201809ccd597aeee (commit)
      from  78b0b10849c2ee077c0ba734314238fccac64389 (commit)

Summary of changes:
 lib/Path/Dispatcher/Cookbook.pod |   26 ++++++++++++++++++++------
 t/021-declarative-defaults.t     |   25 +++++++++++++++++++++++++
 2 files changed, 45 insertions(+), 6 deletions(-)
 create mode 100644 t/021-declarative-defaults.t

- Log -----------------------------------------------------------------
commit 5842379ea3010b6deb831079201809ccd597aeee
Author: Shawn M Moore <sartak at gmail.com>
Date:   Fri Mar 6 22:59:54 2009 -0500

    Bring Cookbook up to date, add tests to make sure I'm not lying

diff --git a/lib/Path/Dispatcher/Cookbook.pod b/lib/Path/Dispatcher/Cookbook.pod
index 65f04e2..f3fbcfd 100644
--- a/lib/Path/Dispatcher/Cookbook.pod
+++ b/lib/Path/Dispatcher/Cookbook.pod
@@ -8,22 +8,35 @@ Path::Dispatcher::Cookbook - A cookbook for Path::Dispatcher
 
 =head2 How can I change the path delimiter from a space ' ' to a slash '/'?
 
-In your Dispatcher object, define the C<token_delimiter> subroutine to return a slash '/':
+When importing the L<Path::Dispatcher::Declarative> sugar, specify the
+C<token_delimiter> option for the C<default> group.
 
-    package MyDispatcher;
-    use Path::Dispatcher::Declarative -base;
+    package My::Dispatcher;
+    use Path::Dispatcher::Declarative -base, -default => {
+        token_delimiter => '/',
+    };
 
-    sub token_delimiter { '/' } # Or whatever delimiter you want to use
+Or define a subclass of L<Path::Dispatcher::Declarative> with a
+C<token_delimiter> method:
+
+    package Web::Dispatcher;
+    use base 'Path::Dispatcher::Declarative';
+    
+    use constant token_delimiter => '/';
+    
+    
+    package My::Other::Dispatcher;
+    use Web::Dispatcher -base;
 
 =head2 How can I do rule chaining (like in Catalyst)?
 
-You can use a C<then> rule approximate chaining behavior:
+You can use a C<chain> rule approximate chaining behavior:
 
     package MyDispatcher;
     use Path::Dispatcher::Declarative -base;
 
     under show => sub {
-        then {
+        chain {
             print "Displaying ";
         };
         on inventory => sub {
@@ -43,3 +56,4 @@ You can use a C<then> rule approximate chaining behavior:
     MyDispatcher->run("display score"); # "Displaying score\n ..."
 
 =cut
+
diff --git a/t/021-declarative-defaults.t b/t/021-declarative-defaults.t
new file mode 100644
index 0000000..2422f63
--- /dev/null
+++ b/t/021-declarative-defaults.t
@@ -0,0 +1,25 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More tests => 1;
+
+my @calls;
+do {
+    package Web::Dispatcher;
+    use base 'Path::Dispatcher::Declarative';
+
+    use constant token_delimiter => '/';
+
+
+    package My::Other::Dispatcher;
+    # we can't use a package in the same file :/
+    BEGIN { Web::Dispatcher->import('-base') };
+
+    on ['foo', 'bar'] => sub {
+        push @calls, '/foo/bar';
+    };
+};
+
+My::Other::Dispatcher->run('/foo/bar');
+is_deeply([splice @calls], ['/foo/bar']);
+

-----------------------------------------------------------------------



More information about the Bps-public-commit mailing list