[Bps-public-commit] r16833 - in Path-Dispatcher/trunk: lib/Path/Dispatcher t
sartak at bestpractical.com
sartak at bestpractical.com
Fri Nov 14 13:04:31 EST 2008
Author: sartak
Date: Fri Nov 14 13:04:30 2008
New Revision: 16833
Added:
Path-Dispatcher/trunk/t/105-always.t
Modified:
Path-Dispatcher/trunk/ (props changed)
Path-Dispatcher/trunk/lib/Path/Dispatcher/Declarative.pm
Log:
r75490 at onn: sartak | 2008-11-14 13:04:09 -0500
Special case on '' => sub {} to match everything
Modified: Path-Dispatcher/trunk/lib/Path/Dispatcher/Declarative.pm
==============================================================================
--- Path-Dispatcher/trunk/lib/Path/Dispatcher/Declarative.pm (original)
+++ Path-Dispatcher/trunk/lib/Path/Dispatcher/Declarative.pm Fri Nov 14 13:04:30 2008
@@ -125,7 +125,7 @@
};
}
-my %rule_creator = (
+my %rule_creators = (
ARRAY => sub {
my ($self, $tokens, $block) = @_;
my $case_sensitive = $self->case_sensitive_tokens;
@@ -159,13 +159,23 @@
$block ? (block => $block) : (),
),
},
+ empty => sub {
+ my ($self, $undef, $block) = @_;
+ Path::Dispatcher::Rule::Always->new(
+ $block ? (block => $block) : (),
+ ),
+ },
);
sub _create_rule {
my ($self, $stage, $matcher, $block) = @_;
- my $rule_creator = $rule_creator{ ref $matcher }
- or die "I don't know how to create a rule for type $matcher";
+ my $rule_creator;
+ $rule_creator = $rule_creators{empty} if $matcher eq '';
+ $rule_creator ||= $rule_creators{ ref $matcher };
+
+ $rule_creator or die "I don't know how to create a rule for type $matcher";
+
return $rule_creator->($self, $matcher, $block);
}
Added: Path-Dispatcher/trunk/t/105-always.t
==============================================================================
--- (empty file)
+++ Path-Dispatcher/trunk/t/105-always.t Fri Nov 14 13:04:30 2008
@@ -0,0 +1,19 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More tests => 1;
+
+my @calls;
+
+do {
+ package MyApp::Dispatcher;
+ use Path::Dispatcher::Declarative -base;
+
+ on '' => sub {
+ push @calls, "empty: $_";
+ };
+};
+
+MyApp::Dispatcher->run("foo");
+is_deeply([splice @calls], ["empty: foo"]);
+
More information about the Bps-public-commit
mailing list