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

sartak at bestpractical.com sartak at bestpractical.com
Fri Mar 6 22:28:05 EST 2009


The branch, master has been updated
       via  c993c7890efb0611f77495c8b0aad74777a0cbfd (commit)
      from  25095835e93daec688eb790cc52ed8d277e14c6e (commit)

Summary of changes:
 lib/Path/Dispatcher/Declarative.pm |   66 +++++++++++++++---------------------
 t/104-config.t                     |    8 ++--
 t/800-cb-slash-path-delimiter.t    |    6 ++--
 3 files changed, 34 insertions(+), 46 deletions(-)

- Log -----------------------------------------------------------------
commit c993c7890efb0611f77495c8b0aad74777a0cbfd
Author: Shawn M Moore <sartak at gmail.com>
Date:   Fri Mar 6 22:27:46 2009 -0500

    Cleanup; make the options to Path::Dispatcher::Declarative, such as
    token_delimiter, Sub::Exporter options

diff --git a/lib/Path/Dispatcher/Declarative.pm b/lib/Path/Dispatcher/Declarative.pm
index 8485692..e4857e9 100644
--- a/lib/Path/Dispatcher/Declarative.pm
+++ b/lib/Path/Dispatcher/Declarative.pm
@@ -45,47 +45,35 @@ sub build_sugar {
 
     my $into = $CALLER;
 
-#    my $dispatcher = $class->dispatcher_class->new(
-#        name => $into,
-#    );
-#    my $builder = $class->builder_class->new(
-#        token_delimiter => sub { $into->token_delimiter },
-#        case_sensitive_tokens => sub { $into->case_sensitive_tokens },
-#        dispatcher => $dispatcher,
-#    );
-
-    # Why the lazy_builder shenanigans? Because token_delimiter/case_sensitive_tokens subroutines
-    # are probably not ready at import time.
-    my ($builder, $dispatcher);
-    my $lazy_builder = sub {
-        return $builder if $builder;
-        $dispatcher = $class->dispatcher_class->new(
-            name => $into,
-        );
-        $builder = $class->builder_class->new(
-            token_delimiter => $into->token_delimiter,
-            case_sensitive_tokens => $into->case_sensitive_tokens,
-            dispatcher => $dispatcher,
-        );
-        return $builder;
-    };
+    for my $option ('token_delimiter', 'case_sensitive_tokens') {
+        $arg->{$option} = $class->$option
+            if !exists($arg->{$option});
+    }
+
+    my $dispatcher = $class->dispatcher_class->new(name => $into);
+
+    my $builder = $class->builder_class->new(
+        dispatcher => $dispatcher,
+        %$arg,
+    );
 
     return {
-        dispatcher      => sub { $lazy_builder->()->dispatcher },
-
-        # NOTE on shift if $into: if caller is $into, then this function is being used as sugar
-        # otherwise, it's probably a method call, so discard the invocant
-        dispatch        => sub { shift if caller ne $into; $lazy_builder->()->dispatch(@_) },
-        run             => sub { shift if caller ne $into; $lazy_builder->()->run(@_) },
-
-        rewrite         => sub { $lazy_builder->()->rewrite(@_) },
-        on              => sub { $lazy_builder->()->on(@_) },
-        then            => sub (&) { $lazy_builder->()->then(@_) },
-        chain           => sub (&) { $lazy_builder->()->chain(@_) },
-        under           => sub { $lazy_builder->()->under(@_) },
-        redispatch_to   => sub { $lazy_builder->()->redispatch_to(@_) },
-        next_rule       => sub { $lazy_builder->()->next_rule(@_) },
-        last_rule       => sub { $lazy_builder->()->last_rule(@_) },
+        dispatcher    => sub { $builder->dispatcher },
+        rewrite       => sub { $builder->rewrite(@_) },
+        on            => sub { $builder->on(@_) },
+        under         => sub { $builder->under(@_) },
+        redispatch_to => sub { $builder->redispatch_to(@_) },
+        next_rule     => sub { $builder->next_rule(@_) },
+        last_rule     => sub { $builder->last_rule(@_) },
+
+        then  => sub (&) { $builder->then(@_) },
+        chain => sub (&) { $builder->chain(@_) },
+
+        # NOTE on shift if $into: if caller is $into, then this function is
+        # being used as sugar otherwise, it's probably a method call, so
+        # discard the invocant
+        dispatch => sub { shift if caller ne $into; $builder->dispatch(@_) },
+        run      => sub { shift if caller ne $into; $builder->run(@_) },
     };
 }
 
diff --git a/t/104-config.t b/t/104-config.t
index d0d28f4..e72e57b 100644
--- a/t/104-config.t
+++ b/t/104-config.t
@@ -7,10 +7,10 @@ my @calls;
 
 do {
     package RESTy::Dispatcher;
-    use Path::Dispatcher::Declarative -base;
-
-    sub token_delimiter { '/' }
-    sub case_sensitive_tokens { 0 }
+    use Path::Dispatcher::Declarative -base, -default => {
+        token_delimiter => '/',
+        case_sensitive_tokens => 0,
+    };
 
     on ['=', 'model', 'Comment'] => sub { push @calls, $3 };
 };
diff --git a/t/800-cb-slash-path-delimiter.t b/t/800-cb-slash-path-delimiter.t
index 44bdbb8..f91f35b 100644
--- a/t/800-cb-slash-path-delimiter.t
+++ b/t/800-cb-slash-path-delimiter.t
@@ -7,9 +7,9 @@ my @result;
 
 do {
     package MyDispatcher;
-    use Path::Dispatcher::Declarative -base;
-
-    sub token_delimiter { '/' }
+    use Path::Dispatcher::Declarative -base, -default => {
+        token_delimiter => '/',
+    };
 
     under show => sub {
         on inventory => sub {

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



More information about the Bps-public-commit mailing list