From: Christian Walde Date: Fri, 22 Nov 2013 16:20:55 +0000 (+0100) Subject: refactor _construct_node to reduce code duplication X-Git-Tag: v0.021~13 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FWeb-Simple.git;a=commitdiff_plain;h=79dda56fb35fea04e7c8d4d9b856efd31e2c8956;hp=e5250d96fc8320272ab2ddc39b445649f980815f refactor _construct_node to reduce code duplication --- diff --git a/lib/Web/Dispatch.pm b/lib/Web/Dispatch.pm index 07537a4..e32aced 100644 --- a/lib/Web/Dispatch.pm +++ b/lib/Web/Dispatch.pm @@ -123,21 +123,17 @@ sub _to_try { if (ref($try) eq 'CODE') { if (defined(my $proto = prototype($try))) { - $self->_construct_node(match => $proto, run => $try)->to_app; + $self->_construct_node(match => $proto, run => $try); } else { $try } } elsif (!ref($try) and ref($more->[0]) eq 'CODE') { - $self->_construct_node(match => $try, run => shift(@$more))->to_app; + $self->_construct_node(match => $try, run => shift(@$more)); } elsif ( (blessed($try) && $try->isa('Web::Dispatch::Matcher')) and (ref($more->[0]) eq 'CODE') ) { - $self->node_class->new({ - %{$self->node_args}, - match => $try, - run => shift(@$more) - })->to_app; + $self->_construct_node(match => $try, run => shift(@$more)); } elsif (blessed($try) && $try->can('to_app')) { $try->to_app; } else { @@ -147,8 +143,8 @@ sub _to_try { sub _construct_node { my ($self, %args) = @_; - $args{match} = $self->_parser->parse($args{match}); - $self->node_class->new({ %{$self->node_args}, %args }); + $args{match} = $self->_parser->parse($args{match}) if !ref $args{match}; + $self->node_class->new({ %{$self->node_args}, %args })->to_app; } 1;