From: Yuval Kogman Date: Sat, 8 Apr 2006 18:58:19 +0000 (+0000) Subject: recursive namespace creation ;-) X-Git-Tag: 5.7099_04~644 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=8505565b33db11c9c5059225b5fbb7cd7d79eb94 recursive namespace creation ;-) --- diff --git a/lib/Catalyst/Dispatcher.pm b/lib/Catalyst/Dispatcher.pm index cc40dc1..961ce15 100644 --- a/lib/Catalyst/Dispatcher.pm +++ b/lib/Catalyst/Dispatcher.pm @@ -379,36 +379,42 @@ sub register { } sub find_or_create_namespace_node { - my ( $self, $namespace, $parent, $visitor ) = @_; + my ( $self, $namespace ) = @_; + + my $tree ||= $self->tree; + my $visitor ||= Tree::Simple::Visitor::FindByPath->new; - $parent ||= $self->tree; - $visitor ||= Tree::Simple::Visitor::FindByPath->new; - if ($namespace) { - for my $part ( split '/', $namespace ) { - $visitor->setSearchPath($part); - $parent->accept($visitor); - my $child = $visitor->getResult; + return $tree unless $namespace; - unless ($child) { + my @namespace = split '/', $namespace; + return $self->_find_or_create_namespace_node( $tree, $visitor, @namespace ); +} - # Create a new tree node and an ActionContainer to form - # its value. +sub _find_or_create_namespace_node { + my ( $self, $parent, $visitor, $part, @namespace ) = @_; - my $container = - Catalyst::ActionContainer->new( - { part => $part, actions => {} } ); - $child = $parent->addChild( Tree::Simple->new($container) ); - $visitor->setSearchPath($part); - $parent->accept($visitor); - $child = $visitor->getResult; - } + return $parent unless $part; - $parent = $child; - } - } + $visitor->setSearchPath($part); + $parent->accept($visitor); + my $child = $visitor->getResult; + + unless ($child) { + + # Create a new tree node and an ActionContainer to form + # its value. + + my $container = + Catalyst::ActionContainer->new( + { part => $part, actions => {} } ); + $child = $parent->addChild( Tree::Simple->new($container) ); + $visitor->setSearchPath($part); + $parent->accept($visitor); + $child = $visitor->getResult; + } - return $parent; + $self->_find_or_create_namespace_node( $child, $visitor, @namespace ); } =head2 $self->setup_actions( $class, $context )