X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FDispatcher.pm;h=e8e37972d2ef1660b79116d9d4f576b70841bef2;hb=0299ba2263bf6d87703fcb5b5ee5377d7a985d87;hp=32ccd67d6e191e2ee679a2965126d1ae444ad4b2;hpb=47ce945eb2137ee3851d44eff2e5b640157867c8;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/Dispatcher.pm b/lib/Catalyst/Dispatcher.pm index 32ccd67..e8e3797 100644 --- a/lib/Catalyst/Dispatcher.pm +++ b/lib/Catalyst/Dispatcher.pm @@ -52,37 +52,37 @@ sub dispatch { } my $default = $action eq 'default' ? $namespace : undef; - my $results = $c->get_action( $action, $default ); + my $results = $c->get_action( $action, $default, $default ? 1 : 0 ); $namespace ||= '/'; if ( @{$results} ) { # Execute last begin $c->state(1); - if ( my $begin = @{ $c->get_action( 'begin', $namespace ) }[-1] ) { + if ( my $begin = @{ $c->get_action( 'begin', $namespace, 1 ) }[-1] ) { $c->execute( @{ $begin->[0] } ); return if scalar @{ $c->error }; } # Execute the auto chain - my $auto = 0; - for my $auto ( @{ $c->get_action( 'auto', $namespace ) } ) { + my $auto; + for $auto ( @{ $c->get_action( 'auto', $namespace, 1 ) } ) { $c->execute( @{ $auto->[0] } ); return if scalar @{ $c->error }; last unless $c->state; - $auto++; } # Execute the action or last default - my $mkay = $auto ? $c->state ? 1 : 0 : 1; + my $mkay = defined $auto ? $c->state ? 1 : 0 : 1; if ( ( my $action = $c->req->action ) && $mkay ) { - if ( my $result = @{ $c->get_action( $action, $default ) }[-1] ) { + if ( my $result = @{ $c->get_action( $action, $default, 1 ) }[-1] ) + { $c->execute( @{ $result->[0] } ); } } # Execute last end - if ( my $end = @{ $c->get_action( 'end', $namespace ) }[-1] ) { + if ( my $end = @{ $c->get_action( 'end', $namespace, 1 ) }[-1] ) { $c->execute( @{ $end->[0] } ); return if scalar @{ $c->error }; } @@ -135,11 +135,20 @@ sub forward { unless ( @{$results} ) { my $class = $command || ''; - my $path = $class . '.pm'; + my $path = $class . '.pm'; $path =~ s/::/\//g; - unless ( $INC{ $path } ) { - my $error = qq/Couldn't forward to "$class". Invalid or not loaded./; + unless ( $INC{$path} ) { + my $error = + qq/Couldn't forward to "$class". Invalid or not loaded./; + $c->error($error); + $c->log->debug($error) if $c->debug; + return 0; + } + + unless ( UNIVERSAL::isa( $class, 'Catalyst::Base' ) ) { + my $error = + qq/Can't forward to "$class". Class is not a Catalyst component./; $c->error($error); $c->log->debug($error) if $c->debug; return 0; @@ -153,7 +162,8 @@ sub forward { } else { - my $error = qq/Couldn't forward to "$class". Does not implement "$method"/; + my $error = + qq/Couldn't forward to "$class". Does not implement "$method"/; $c->error($error); $c->log->debug($error) if $c->debug; @@ -171,24 +181,24 @@ sub forward { return $c->state; } -=item $c->get_action( $action, $namespace ) +=item $c->get_action( $action, $namespace, $inherit ) Get an action in a given namespace. =cut sub get_action { - my ( $c, $action, $namespace ) = @_; + my ( $c, $action, $namespace, $inherit ) = @_; return [] unless $action; $namespace ||= ''; + $inherit ||= 0; if ($namespace) { $namespace = '' if $namespace eq '/'; my $parent = $c->tree; my @results; - my %allowed = ( begin => 1, auto => 1, default => 1, end => 1 ); - if ( $allowed{$action} ) { + if ($inherit) { my $result = $c->actions->{private}->{ $parent->getUID }->{$action}; push @results, [$result] if $result; my $visitor = Tree::Simple::Visitor::FindByPath->new; @@ -259,11 +269,13 @@ sub set_action { my %flags; for my $attr ( @{$attrs} ) { - if ( $attr =~ /^(Local|Relative)$/ ) { $flags{local}++ } - elsif ( $attr =~ /^(Global|Absolute)$/ ) { $flags{global}++ } - elsif ( $attr =~ /^Path\((.+)\)$/i ) { $flags{path} = $1 } - elsif ( $attr =~ /^Private$/i ) { $flags{private}++ } - elsif ( $attr =~ /^(Regex|Regexp)\((.+)\)$/i ) { $flags{regex} = $2 } + if ( $attr =~ /^(Local|Relative)$/ ) { $flags{local}++ } + elsif ( $attr =~ /^(Global|Absolute)$/ ) { $flags{global}++ } + elsif ( $attr =~ /^Path\(\s*(.+)\s*\)$/i ) { $flags{path} = $1 } + elsif ( $attr =~ /^Private$/i ) { $flags{private}++ } + elsif ( $attr =~ /^(Regex|Regexp)\(\s*(.+)\s*\)$/i ) { + $flags{regex} = $2; + } } if ( $flags{private} && ( keys %flags > 1 ) ) { @@ -347,7 +359,7 @@ sub setup_actions { for my $comp (@$comps) { $comp = ref $comp || $comp; - for my $action ( @{ $comp->_cache } ) { + for my $action ( @{ Catalyst::Utils::reflect_actions($comp) } ) { my ( $code, $attrs ) = @{$action}; my $name = ''; no strict 'refs';