enable matching of empty string specs
Christian Walde [Tue, 4 Oct 2011 20:39:28 +0000 (22:39 +0200)]
lib/Web/Dispatch.pm
lib/Web/Dispatch/Parser.pm
t/dispatch_parser.t

index 9c5559f..69df554 100644 (file)
@@ -33,7 +33,7 @@ sub call {
 
 sub _dispatch {
   my ($self, $env, @match) = @_;
-  while (my $try = shift @match) {
+  while (defined(my $try = shift @match)) {
 
     return $try if ref($try) eq 'ARRAY';
     if (ref($try) eq 'HASH') {
index 8e66a05..6ebc51e 100644 (file)
@@ -35,6 +35,7 @@ sub parse {
 
 sub _parse_spec {
   my ($self, $spec, $nested) = @_;
+  return sub { {} } unless length($spec);
   for ($_[1]) {
     my @match;
     PARSE: { do {
index d0b8db4..8fe2b8e 100644 (file)
@@ -7,25 +7,20 @@ use Web::Dispatch::Parser;
 
 my $dp = Web::Dispatch::Parser->new;
 
-TODO: {
-   local $TODO = 'according to the synopsis this should work';
-   my $all = eval {
-     $dp->parse('');
-   };
-   ok $all;
-   eval {
-     is_deeply(
-       [ $all->({ REQUEST_METHOD => 'GET' }) ],
-       [ {} ],
-       'GET matches'
-     );
+{
+   my $all = $dp->parse('');
 
-     is_deeply(
-       [ $all->({ REQUEST_METHOD => 'POST' }) ],
-       [ {} ],
-       'POST matches'
-     );
-   };
+   is_deeply(
+     [ $all->({ REQUEST_METHOD => 'GET' }) ],
+     [ {} ],
+     'GET matches'
+   );
+
+   is_deeply(
+     [ $all->({ REQUEST_METHOD => 'POST' }) ],
+     [ {} ],
+     'POST matches'
+   );
 };
 
 {