can(undef) on 5.8.x blows up, work around it
Matt S Trout [Sat, 20 Dec 2014 21:11:44 +0000 (21:11 +0000)]
Conflicts:
Changes

Changes
lib/Web/Dispatch.pm
t/dispatch_misc.t

diff --git a/Changes b/Changes
index 04acb5f..30b28aa 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,7 @@
 Revision history for Web-Simple
 
+  - produce a sensible error for (GET => undef) on 5.8
+
 0.030 - 2014-08-07
   - make dispatch_misc.t handle Plack's MockHTTP's on error behaviour changing
 
index d34fe6e..a9df54c 100644 (file)
@@ -128,7 +128,7 @@ sub _to_try {
     }
   } elsif (!ref($try)
     and (ref($more->[0]) eq 'CODE'
-      or (!ref($more->[0]) and $self->dispatch_object
+      or ($more->[0] and !ref($more->[0]) and $self->dispatch_object
         and $self->dispatch_object->can($more->[0])))
   ) {
     $self->_construct_node(match => $try, run => shift(@$more));
index a4ab38a..0c27413 100644 (file)
@@ -17,6 +17,11 @@ my @dispatch;
     package MiscTest;
     sub dispatch_request { @dispatch }
     sub string_method { [ 999, [], [""] ]; }
+
+    sub can {
+        die "Passed undef to can, this blows up on 5.8" unless defined($_[1]);
+        shift->SUPER::can(@_)
+    }
 }
 
 my $app = MiscTest->new;
@@ -33,6 +38,7 @@ middleware_as_only_route();
 route_returns_middleware_plus_extra();
 route_returns_undef();
 matcher_nonsub_pair();
+matcher_undef_method();
 
 done_testing();
 
@@ -202,3 +208,13 @@ sub matcher_nonsub_pair {
     like $get->content, qr[No idea how we got here with Web::Dispatch::M],
       "the error message points out the broken definition";
 }
+
+sub matcher_undef_method {
+    @dispatch = ( 'GET', undef );
+
+    my $get = run_request( GET => 'http://localhost/' );
+
+    cmp_ok $get->code, '==', 500, "a route definition that pairs a WD::Matcher a non-sub dies";
+    like $get->content, qr[No idea how we got here with GET],
+      "the error message points out the broken definition";
+}