X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FDispatcher.pm;h=f78ad166faaf27523a172ece5d9a26d74e539ec5;hb=ffb820f8dcd7073ecb6a1ef8cf9b529be7784cd2;hp=cc40dc1f20a8c60309803472644c8b48cb945f5e;hpb=15e9b5ddb1d1368677b9dfd59ec5625d9b3459e1;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/Dispatcher.pm b/lib/Catalyst/Dispatcher.pm index cc40dc1..f78ad16 100644 --- a/lib/Catalyst/Dispatcher.pm +++ b/lib/Catalyst/Dispatcher.pm @@ -379,36 +379,35 @@ sub register { } sub find_or_create_namespace_node { - my ( $self, $namespace, $parent, $visitor ) = @_; + my ( $self, $namespace ) = @_; + + my $tree ||= $self->tree; - $parent ||= $self->tree; - $visitor ||= Tree::Simple::Visitor::FindByPath->new; + return $tree unless $namespace; - if ($namespace) { - for my $part ( split '/', $namespace ) { - $visitor->setSearchPath($part); - $parent->accept($visitor); - my $child = $visitor->getResult; + my @namespace = split '/', $namespace; + return $self->_find_or_create_namespace_node( $tree, @namespace ); +} - unless ($child) { +sub _find_or_create_namespace_node { + my ( $self, $parent, $part, @namespace ) = @_; - # Create a new tree node and an ActionContainer to form - # its value. + return $parent unless $part; - my $container = - Catalyst::ActionContainer->new( - { part => $part, actions => {} } ); - $child = $parent->addChild( Tree::Simple->new($container) ); - $visitor->setSearchPath($part); - $parent->accept($visitor); - $child = $visitor->getResult; - } + my $child = ( grep { $_->getNodeValue->part eq $part } $parent->getAllChildren )[0]; - $parent = $child; - } - } + unless ($child) { + # Create a new tree node and an ActionContainer to form + # its value. + + my $container = + Catalyst::ActionContainer->new( + { part => $part, actions => {} } ); + + $parent->addChild( $child = Tree::Simple->new($container) ); + } - return $parent; + $self->_find_or_create_namespace_node( $child, @namespace ); } =head2 $self->setup_actions( $class, $context )