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

sartak at bestpractical.com sartak at bestpractical.com
Fri Mar 6 22:43:54 EST 2009


The branch, master has been updated
       via  44392e6e8ab20a287ef4c917eb145da302720879 (commit)
      from  14b2e4449b86cbb2519336832b0e6b42e3c13d04 (commit)

Summary of changes:
 lib/Path/Dispatcher/Builder.pm |  102 ++++++++++++++++++++-------------------
 1 files changed, 52 insertions(+), 50 deletions(-)

- Log -----------------------------------------------------------------
commit 44392e6e8ab20a287ef4c917eb145da302720879
Author: Shawn M Moore <sartak at gmail.com>
Date:   Fri Mar 6 22:43:48 2009 -0500

    Make rule_creators a method

diff --git a/lib/Path/Dispatcher/Builder.pm b/lib/Path/Dispatcher/Builder.pm
index 63f9eaf..1f7798b 100644
--- a/lib/Path/Dispatcher/Builder.pm
+++ b/lib/Path/Dispatcher/Builder.pm
@@ -122,55 +122,57 @@ sub redispatch_to {
     $self->_add_rule($redispatch);
 }
 
-my %rule_creators = (
-    ARRAY => sub {
-        my ($self, $tokens, $block) = @_;
-
-        Path::Dispatcher::Rule::Tokens->new(
-            tokens => $tokens,
-            delimiter => $self->token_delimiter,
-            case_sensitive => $self->case_sensitive_tokens,
-            $block ? (block => $block) : (),
-        ),
-    },
-    HASH => sub {
-        my ($self, $metadata_matchers, $block) = @_;
-
-        if (keys %$metadata_matchers == 1) {
-            my ($field) = keys %$metadata_matchers;
-            my ($value) = values %$metadata_matchers;
-            my $matcher = $self->_create_rule($value);
-
-            return Path::Dispatcher::Rule::Metadata->new(
-                field   => $field,
+sub rule_creators {
+    return {
+        ARRAY => sub {
+            my ($self, $tokens, $block) = @_;
+
+            Path::Dispatcher::Rule::Tokens->new(
+                tokens => $tokens,
+                delimiter => $self->token_delimiter,
+                case_sensitive => $self->case_sensitive_tokens,
+                $block ? (block => $block) : (),
+            ),
+        },
+        HASH => sub {
+            my ($self, $metadata_matchers, $block) = @_;
+
+            if (keys %$metadata_matchers == 1) {
+                my ($field) = keys %$metadata_matchers;
+                my ($value) = values %$metadata_matchers;
+                my $matcher = $self->_create_rule($value);
+
+                return Path::Dispatcher::Rule::Metadata->new(
+                    field   => $field,
+                    matcher => $matcher,
+                    $block ? (block => $block) : (),
+                );
+            }
+
+            die "Doesn't support multiple metadata rules yet";
+        },
+        CODE => sub {
+            my ($self, $matcher, $block) = @_;
+            Path::Dispatcher::Rule::CodeRef->new(
                 matcher => $matcher,
                 $block ? (block => $block) : (),
-            );
-        }
-
-        die "Doesn't support multiple metadata rules yet";
-    },
-    CODE => sub {
-        my ($self, $matcher, $block) = @_;
-        Path::Dispatcher::Rule::CodeRef->new(
-            matcher => $matcher,
-            $block ? (block => $block) : (),
-        ),
-    },
-    Regexp => sub {
-        my ($self, $regex, $block) = @_;
-        Path::Dispatcher::Rule::Regex->new(
-            regex => $regex,
-            $block ? (block => $block) : (),
-        ),
-    },
-    empty => sub {
-        my ($self, $undef, $block) = @_;
-        Path::Dispatcher::Rule::Empty->new(
-            $block ? (block => $block) : (),
-        ),
-    },
-);
+            ),
+        },
+        Regexp => sub {
+            my ($self, $regex, $block) = @_;
+            Path::Dispatcher::Rule::Regex->new(
+                regex => $regex,
+                $block ? (block => $block) : (),
+            ),
+        },
+        empty => sub {
+            my ($self, $undef, $block) = @_;
+            Path::Dispatcher::Rule::Empty->new(
+                $block ? (block => $block) : (),
+            ),
+        },
+    };
+}
 
 sub _create_rule {
     my ($self, $matcher, $block) = @_;
@@ -178,14 +180,14 @@ sub _create_rule {
     my $rule_creator;
 
     if ($matcher eq '') {
-        $rule_creator = $rule_creators{empty};
+        $rule_creator = $self->rule_creators->{empty};
     }
     elsif (!ref($matcher)) {
-        $rule_creator = $rule_creators{ARRAY};
+        $rule_creator = $self->rule_creators->{ARRAY};
         $matcher = [$matcher];
     }
     else {
-        $rule_creator = $rule_creators{ ref $matcher };
+        $rule_creator = $self->rule_creators->{ ref $matcher };
     }
 
     $rule_creator or die "I don't know how to create a rule for type $matcher";

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



More information about the Bps-public-commit mailing list