}
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 };
}
unless ( @{$results} ) {
my $class = $command || '';
- my $path = $class . '.pm';
+ my $path = $class . '.pm';
$path =~ s/::/\//g;
- unless ( $INC{ $path } ) {
- my $error = qq/Unknown class "$class"/;
+ 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;
}
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;
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;
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 ) ) {
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';