} elsif (!ref($try) and ref($more->[0]) eq 'CODE') {
$self->_construct_node(match => $try, run => shift(@$more))->to_app;
} elsif (
+ !ref($try) and blessed($more->[0]) and $more->[0]->isa('Plack::Middleware')
+ ) {
+ die "Middleware needs to be wrapped in a sub.";
+ } elsif (
(blessed($try) && $try->isa('Web::Dispatch::Matcher'))
and (ref($more->[0]) eq 'CODE')
) {
match => $try,
run => shift(@$more)
})->to_app;
+ } elsif (blessed($try) && $try->isa('Plack::Middleware')) {
+ die "Middleware needs a route definition and has to be wrapped in a sub.";
} elsif (blessed($try) && $try->can('to_app')) {
$try->to_app;
} else {
array_with_sub();
array_with_no_sub();
middleware_as_only_route();
+plain_middleware_with_route();
route_returns_middleware_plus_extra();
route_returns_undef();
my $get = run_request( GET => 'http://localhost/' );
cmp_ok $get->code, '==', 500, "a route definition consisting of only a middleware causes a bail";
- like $get->content, qr[Multiple results but first one is a middleware \(Plack::Middleware=],
+ like $get->content, qr[Middleware needs a route definition and has to be wrapped in a sub.],
+ "the error message explains the need for a route def and a code ref";
+}
+
+sub plain_middleware_with_route {
+ @dispatch = ( '' => bless {}, "Plack::Middleware" );
+
+ my $get = run_request( GET => 'http://localhost/' );
+
+ cmp_ok $get->code, '==', 500, "a route definition consisting of a string and a plain middleware causes a bail";
+ like $get->content, qr[Middleware needs to be wrapped in a sub.],
"the error message mentions the middleware class";
}