sub finalize_uploads { my $c = shift; $c->engine->finalize_uploads( $c, @_ ) }
-=item $c->get_action( $action, $namespace, $inherit )
+=item $c->get_action( $action, $namespace )
Get an action in a given namespace.
sub get_action { my $c = shift; $c->dispatcher->get_action( $c, @_ ) }
+=item $c->get_actions( $action, $namespace )
+
+Get all actions of a given name in a namespace and all base namespaces.
+
+=cut
+
+sub get_actions { my $c = shift; $c->dispatcher->get_actions( $c, @_ ) }
+
=item handle_request( $class, @arguments )
Handles the request.
sub _BEGIN : Private {
my ( $self, $c ) = @_;
- my $begin = @{ $c->get_action( 'begin', $c->namespace, 1 ) }[-1];
+ my $begin = ($c->get_actions( 'begin', $c->namespace))[-1];
return 1 unless $begin;
- $begin->[0]->execute($c);
+ $begin->execute($c);
return !@{ $c->error };
}
sub _AUTO : Private {
my ( $self, $c ) = @_;
- my @auto = @{ $c->get_action( 'auto', $c->namespace, 1 ) };
+ my @auto = $c->get_actions('auto', $c->namespace);
foreach my $auto (@auto) {
- $auto->[0]->execute($c);
+ $auto->execute($c);
return 0 unless $c->state;
}
return 1;
sub _END : Private {
my ( $self, $c ) = @_;
- my $end = @{ $c->get_action( 'end', $c->namespace, 1 ) }[-1];
+ my $end = ($c->get_actions( 'end', $c->namespace))[-1];
return 1 unless $end;
- $end->[0]->execute($c);
+ $end->execute($c);
return !@{ $c->error };
}
sub match {
my ( $self, $c, $path ) = @_;
return if $path =~ m!/!; # Not at root yet, wait for it ...
- my $result = @{ $c->get_action( 'default', $c->req->path, 1 ) || [] }[-1];
+ my $result = ($c->get_actions('default', $c->req->path))[-1];
# Find default on namespace or super
if ($result) {
- $c->action( $result->[0] );
- $c->namespace( $result->[0]->namespace );
+ $c->action( $result );
+ $c->namespace( $result->namespace );
$c->req->action('default');
# default methods receive the controller name as the first argument
unshift @{ $c->req->args }, $path;
sub match {
my ( $self, $c, $path ) = @_;
return if @{ $c->req->args };
- my $result = @{ $c->get_action( 'index', $path ) || [] }[-1];
+ my $result = $c->get_action( 'index', $path );
- # Find default on namespace or super
if ($result) {
- $c->action( $result->[0] );
- $c->namespace( $result->[0]->namespace );
+ $c->action( $result );
+ $c->namespace( $result->namespace );
$c->req->action('index');
$c->req->match( $c->req->path );
return 1;
my $arguments = ( ref( $_[-1] ) eq 'ARRAY' ) ? pop(@_) : $c->req->args;
- my $results = [];
+ my $result;
my $command_copy = $command;
}
unless ( $command_copy =~ /\// ) {
- $results = $c->get_action( $command_copy, '/' );
+ $result = $c->get_action( $command_copy, '/' );
}
else {
my @extra_args;
DESCEND: while ( $command_copy =~ s/^(.*)\/(\w+)$/$1/ ) {
my $tail = $2;
- $results = $c->get_action( $tail, $1 );
- if ( @{$results} ) {
+ $result = $c->get_action( $tail, $1 );
+ if ( $result ) {
$command = $tail;
push( @{$arguments}, @extra_args );
last DESCEND;
}
}
- unless ( @{$results} ) {
+ unless ( $result ) {
unless ( $c->components->{$command} ) {
my $error =
namespace => $class,
}
);
- $results = [ [$action] ];
+ $result = $action;
}
else {
local $c->request->{arguments} = [ @{$arguments} ];
- for my $result ( @{$results} ) {
- $result->[0]->execute($c);
- return if scalar @{ $c->error };
- last unless $c->state;
- }
+ $result->execute($c);
return $c->state;
}
if ( $c->debug && @args );
}
-=item $self->get_action( $c, $action, $namespace, $inherit )
+=item $self->get_action( $c, $action, $namespace )
=cut
sub get_action {
- my ( $self, $c, $action, $namespace, $inherit ) = @_;
+ my ( $self, $c, $action, $namespace ) = @_;
return [] unless $action;
$namespace ||= '';
$namespace = '' if $namespace eq '/';
- $inherit ||= 0;
my @match = $self->get_containers($namespace);
- if ($inherit) { # Return [ [ $act_obj ], ... ] for valid containers
- return [
- map { [ $_->{$action} ] } # Make [ $action_obj ]
- grep { defined $_->{$action} } # If it exists in the container
- map { $_->actions } # Get action hash for container
- @match
- ];
- }
- else {
- my $node = $match[-1]->actions; # Only bother looking at the last one
+ my $node = $match[-1]->actions; # Only bother looking at the last one
- if ( defined $node->{$action}
- && ( $node->{$action}->namespace eq $namespace ) )
- {
- return [ [ $node->{$action} ] ];
- }
- else {
- return [];
- }
+ if ( defined $node->{$action}
+ && ( $node->{$action}->namespace eq $namespace ) )
+ {
+ return $node->{$action};
}
}
+=item $self->get_actions( $c, $action, $namespace )
+
+=cut
+
+sub get_actions {
+ my ( $self, $c, $action, $namespace ) = @_;
+ return [] unless $action;
+ $namespace ||= '';
+ $namespace = '' if $namespace eq '/';
+
+ my @match = $self->get_containers($namespace);
+
+ return
+ map { $_->{$action} }
+ grep { defined $_->{$action} } # If it exists in the container
+ map { $_->actions } # Get action hash for container
+ @match
+}
+
=item $self->get_containers( $namespace )
=cut