X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FEngine.pm;h=b7d525ea494b3bf50c0f98f9b21939b6318302b2;hb=1927c219b552ac80dff59c235a51d422ac5b9d25;hp=a0958110ac4baa5d84e383f3a88c3e59a07a66a7;hpb=890511ad3dac68ac7e9b8965dc7484beb4cee5fa;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/Engine.pm b/lib/Catalyst/Engine.pm index a095811..b7d525e 100644 --- a/lib/Catalyst/Engine.pm +++ b/lib/Catalyst/Engine.pm @@ -121,14 +121,13 @@ sub dispatch { $c->state(1); if ( my $begin = @{ $c->get_action( 'begin', $namespace ) }[-1] ) { $c->execute( @{ $begin->[0] } ); - return if scalar @{$c->error}; - last unless $c->state; + return if scalar @{ $c->error }; } # Execute the auto chain for my $auto ( @{ $c->get_action( 'auto', $namespace ) } ) { $c->execute( @{ $auto->[0] } ); - return if scalar @{$c->error}; + return if scalar @{ $c->error }; last unless $c->state; } @@ -142,8 +141,7 @@ sub dispatch { # Execute last end if ( my $end = @{ $c->get_action( 'end', $namespace ) }[-1] ) { $c->execute( @{ $end->[0] } ); - return if scalar @{$c->error}; - last unless $c->state; + return if scalar @{ $c->error }; } } else { @@ -210,7 +208,7 @@ sub execute { chomp $error; $error = qq/Caught exception "$error"/; } - + $c->log->error($error); $c->error($error); $c->state(0); @@ -415,6 +413,7 @@ sub forward { return 0; } my $caller = caller(0); + my $global = $command =~ /^\// ? 0 : 1; my $namespace = '/'; if ( $command =~ /^\// ) { $command =~ /^(.*)\/(\w+)$/; @@ -422,7 +421,7 @@ sub forward { $command = $2; } else { $namespace = _class2prefix($caller) || '/' } - my $results = $c->get_action( $command, $namespace ); + my $results = $c->get_action( $command, $namespace, $global ); unless ( @{$results} ) { my $class = $command; if ( $class =~ /[^\w\:]/ ) { @@ -442,37 +441,50 @@ sub forward { } for my $result ( @{$results} ) { $c->execute( @{ $result->[0] } ); + return if scalar @{ $c->error }; + last unless $c->state; } return $c->state; } -=item $c->get_action( $action, $namespace ) +=item $c->get_action( $action, $namespace, $global ) Get an action in a given namespace. =cut sub get_action { - my ( $c, $action, $namespace ) = @_; + my ( $c, $action, $namespace, $global ) = @_; return [] unless $action; $namespace ||= ''; if ($namespace) { - $namespace = '' if $namespace eq '/'; - my $parent = $c->tree; - my @results; - my $result = $c->actions->{private}->{ $parent->getUID }->{$action}; - push @results, [$result] if $result; - my $visitor = Tree::Simple::Visitor::FindByPath->new; - for my $part ( split '/', $namespace ) { - $visitor->setSearchPath($part); - $parent->accept($visitor); - my $child = $visitor->getResult; - my $uid = $child->getUID if $child; - my $match = $c->actions->{private}->{$uid}->{$action} if $uid; - push @results, [$match] if $match; - $parent = $child if $child; + if ($global) { + my @results; + for my $uid ( keys %{ $c->actions->{private} } ) { + if ( my $result = $c->actions->{private}->{$uid}->{$action} ) { + push @results, [$result]; + } + } + return \@results; + } + else { + $namespace = '' if $namespace eq '/'; + my $parent = $c->tree; + my @results; + my $result = $c->actions->{private}->{ $parent->getUID }->{$action}; + push @results, [$result] if $result; + my $visitor = Tree::Simple::Visitor::FindByPath->new; + for my $part ( split '/', $namespace ) { + $visitor->setSearchPath($part); + $parent->accept($visitor); + my $child = $visitor->getResult; + my $uid = $child->getUID if $child; + my $match = $c->actions->{private}->{$uid}->{$action} if $uid; + push @results, [$match] if $match; + $parent = $child if $child; + } + return \@results; } - return \@results; } elsif ( my $p = $c->actions->{plain}->{$action} ) { return [ [$p] ] } elsif ( my $r = $c->actions->{regex}->{$action} ) { return [ [$r] ] } @@ -796,7 +808,7 @@ sub set_action { $absolute = 1; } $absolute = 1 if $flags{global}; - my $name = $absolute ? $path : "$prefix/$path"; + my $name = $absolute ? $path : $prefix ? "$prefix/$path" : $path; $c->actions->{plain}->{$name} = [ $namespace, $code ]; } if ( my $regex = $flags{regex} ) {