nesting error message
Matt S Trout [Sun, 22 Nov 2009 03:53:03 +0000 (22:53 -0500)]
lib/Web/Simple/DispatchParser.pm
t/dispatch_parser.t

index 6b43316..b3a86c8 100644 (file)
@@ -7,7 +7,7 @@ sub new { bless({}, ref($_[0])||$_[0]) }
 
 sub _blam {
   my ($self, $error) = @_;
-  my $hat = (' ' x pos).'^';
+  my $hat = (' ' x (pos||0)).'^';
   die "Error parsing dispatch specification: ${error}\n
 ${_}
 ${hat} here\n";
@@ -36,7 +36,7 @@ sub _parse_spec {
         or $self->_blam('No valid combinator - expected + or |');
     } until (pos == length) }; # accept trailing whitespace
     if ($nested and pos == length) {
-      pos = $nested;
+      pos = $nested - 1;
       $self->_blam("No closing ) found for opening (");
     }
     return $match[0] if (@match == 1);
index 7c5c0eb..19dff10 100644 (file)
@@ -162,3 +162,21 @@ is_deeply(
   [],
   '(GET+/foo)|POST does not match PUT /foo'
 );
+
+{
+  local $@;
+  ok(
+    !eval { $dp->parse_dispatch_specification('/foo+(GET'); 1 },
+    'Death with missing closing )'
+  );
+  my $err = q{
+    /foo+(GET
+         ^
+  };
+  (s/^\n//s,s/\n  $//s,s/^    //mg) for $err;
+  like(
+    $@,
+    qr{\Q$err\E},
+    "Error $@ matches\n${err}\n"
+  );
+}