use Moose;
extends 'Catalyst::DispatchType';
-no Moose;
+use namespace::clean -except => 'meta';
=head1 NAME
=back
+=cut
+
+has _actions => (
+ is => 'rw', isa => 'HashRef', default => sub { +{} }
+);
+
=head1 METHODS
=head2 $self->match( $c, $path )
return if @{ $c->req->args };
my $result = $c->get_action( 'index', $path );
+ return 0 unless $result && exists $self->_actions->{ $result->reverse };
+
if ($result && $result->match($c)) {
$c->action($result);
$c->namespace( $result->namespace );
return 0;
}
+=head2 $self->register( $c, $action )
+
+Register an action with this DispatchType.
+
+=cut
+
+sub register {
+ my ( $self, $c, $action ) = @_;
+
+ $self->_actions->{ $action->reverse } = $action;
+
+ return 1;
+}
+
=head2 $self->uri_for_action( $action, $captures )
get a URI part for an action; always returns undef is $captures is set
}
}
+ my @dtypes = @{ $self->_dispatch_types };
+ my @normal_dtypes;
+ my @low_precedence_dtypes;
+
+ while (my $type = shift @dtypes) {
+ if ($type->isa('Catalyst::DispatchType::Index') ||
+ $type->isa('Catalyst::DispatchType::Default')) {
+ push @low_precedence_dtypes, $type;
+ } else {
+ push @normal_dtypes, $type;
+ }
+ }
+
# Pass the action to our dispatch types so they can register it if reqd.
- foreach my $type ( @{ $self->_dispatch_types } ) {
- $type->register( $c, $action );
+ my $was_registered = 0;
+ foreach my $type ( @normal_dtypes ) {
+ $was_registered = 1 if $type->register( $c, $action );
+ }
+
+ if (not $was_registered) {
+ foreach my $type ( @low_precedence_dtypes ) {
+ $type->register( $c, $action );
+ }
}
my $namespace = $action->namespace;
use Test::More tests => 1*$iters;
-use Catalyst::Test 'TestAppIndexDefault';
+use Catalyst::Test 'TestAppIndexActionName';
if ( $ENV{CAT_BENCHMARK} ) {
require Benchmark;
-package TestAppIndexDefault;
+package TestAppIndexActionName;
use strict;
use warnings;
use Catalyst;
-package TestAppIndexDefault::Controller::IndexChained;
+package TestAppIndexActionName::Controller::IndexChained;
use base 'Catalyst::Controller';