From: Christian Walde Date: Mon, 3 Oct 2011 14:00:40 +0000 (+0200) Subject: elsif christmas tree is back, but hidden away X-Git-Tag: v0.009~4 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FWeb-Simple.git;a=commitdiff_plain;h=6bd996190b137349cb89463b86c8031552ad1ef0 elsif christmas tree is back, but hidden away --- diff --git a/lib/Web/Dispatch.pm b/lib/Web/Dispatch.pm index 4c922d6..8fa3cd3 100644 --- a/lib/Web/Dispatch.pm +++ b/lib/Web/Dispatch.pm @@ -45,18 +45,8 @@ sub _dispatch { next unless @result and defined($result[0]); my $first = $result[0]; - - return $self->_unpack_array_match( $first ) - if ref($first) eq 'ARRAY'; - - return $self->_prepare_middleware( $first, \@result ) - if blessed($first) && $first->isa('Plack::Middleware'); - - return $self->_unwrap_middleware( $first, \@match, $env ) - if ref($first) eq 'HASH' and $first->{+MAGIC_MIDDLEWARE_KEY}; - - return $first - if blessed($first) && !$first->can('to_app'); + my $dispatch = $self->_valid_dispatch( $first, \@result, \@match, $env ); + return $dispatch if $dispatch; # make a copy so we don't screw with it assigning further up my $env = $env; @@ -66,6 +56,25 @@ sub _dispatch { return; } +sub _valid_dispatch { + my ( $self, $first, $result, $match, $env ) = @_; + + if ( ref($first) eq 'ARRAY' ) { + return $self->_unpack_array_match( $first ); + } + elsif ( blessed($first) && $first->isa('Plack::Middleware') ) { + return $self->_prepare_middleware( $first, $result ); + } + elsif ( ref($first) eq 'HASH' and $first->{+MAGIC_MIDDLEWARE_KEY} ) { + return $self->_unwrap_middleware( $first, $match, $env ); + } + elsif ( blessed($first) && !$first->can('to_app') ) { + return $first; + } + + return; +} + sub _unpack_array_match { my ( $self, $match ) = @_; return $match->[0] if @{$match} == 1 and ref($match->[0]) eq 'CODE';