my $caller = ( caller(1) )[0]->isa('Catalyst::Dispatcher')
&& ( ( caller(2) )[3] =~ /::detach$/ ) ? caller(3) : caller(1);
- my $namespace = '/';
my $arguments = ( ref( $_[-1] ) eq 'ARRAY' ) ? pop(@_) : $c->req->args;
my $results = [];
- if ( $command =~ /^\// ) {
- if ( $command =~ /^\/(\w+)$/ ) {
- $results = $c->get_action( $1, $namespace );
- }
- else {
- my $command_copy = $command;
- my @extra_args;
- DESCEND: while ( $command_copy =~ s/^\/(.*)\/(\w+)$/\/$1/ ) {
- my $tail = $2;
- if ( $results = $c->get_action( $tail, $1 ) ) {
- $command = $tail;
- $namespace = $command_copy;
- push( @{$arguments}, @extra_args );
- last DESCEND;
- }
- unshift( @extra_args, $tail );
- }
- }
- $command =~ s/^\///;
+ my $command_copy = $command;
+
+ unless ( $command_copy =~ s/^\/// ) {
+ my $namespace =
+ Catalyst::Utils::class2prefix( $caller, $c->config->{case_sensitive} ) || '';
+ $command_copy = "${namespace}/${command}";
}
+ unless ( $command_copy =~ /\// ) {
+ $results = $c->get_action( $command_copy, '/' );
+ }
else {
- $namespace =
- Catalyst::Utils::class2prefix( $caller, $c->config->{case_sensitive} )
- || '/';
- $results = $c->get_action( $command, $namespace );
+ my @extra_args;
+ DESCEND: while ( $command_copy =~ s/^(.*)\/(\w+)$/$1/ ) {
+ my $tail = $2;
+ $results = $c->get_action( $tail, $1 );
+ if ( @{$results} ) {
+ $command = $tail;
+ push( @{$arguments}, @extra_args );
+ last DESCEND;
+ }
+ unshift( @extra_args, $tail );
+ }
}
unless ( @{$results} ) {
for my $attr ( @{$attrs} ) {
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 =~ /^Path\(\s*(.+)\s*\)$/i ) {
+ push @{ $flags{path} }, $1;
+ }
+ elsif ( $attr =~ /^Private$/i ) { $flags{private}++ }
elsif ( $attr =~ /^(Regex|Regexp)\(\s*(.+)\s*\)$/i ) {
- $flags{regex} = $2;
+ push @{ $flags{regex} }, $2;
}
}
$parent = $child;
}
- my $forward = $prefix ? "$prefix/$method" : $method;
-
my $reverse = $prefix ? "$prefix/$method" : $method;
my $action = Catalyst::Action->new(
my $uid = $parent->getUID;
$self->actions->{private}->{$uid}->{$method} = $action;
- if ( $flags{path} ) {
- $flags{path} =~ s/^\w+//;
- $flags{path} =~ s/\w+$//;
- if ( $flags{path} =~ /^\s*'(.*)'\s*$/ ) { $flags{path} = $1 }
- if ( $flags{path} =~ /^\s*"(.*)"\s*$/ ) { $flags{path} = $1 }
+ my @path;
+ for my $path ( @{ $flags{path} } ) {
+ $path =~ s/^\w+//;
+ $path =~ s/\w+$//;
+ if ( $path =~ /^\s*'(.*)'\s*$/ ) { $path = $1 }
+ if ( $path =~ /^\s*"(.*)"\s*$/ ) { $path = $1 }
+ push @path, $path;
}
-
- if ( $flags{regex} ) {
- $flags{regex} =~ s/^\w+//;
- $flags{regex} =~ s/\w+$//;
- if ( $flags{regex} =~ /^\s*'(.*)'\s*$/ ) { $flags{regex} = $1 }
- if ( $flags{regex} =~ /^\s*"(.*)"\s*$/ ) { $flags{regex} = $1 }
+ $flags{path} = \@path;
+
+ my @regex;
+ for my $regex ( @{ $flags{regex} } ) {
+ $regex =~ s/^\w+//;
+ $regex =~ s/\w+$//;
+ if ( $regex =~ /^\s*'(.*)'\s*$/ ) { $regex = $1 }
+ if ( $regex =~ /^\s*"(.*)"\s*$/ ) { $regex = $1 }
+ push @regex, $regex;
}
+ $flags{regex} = \@regex;
- if ( $flags{local} || $flags{global} || $flags{path} ) {
- my $path = $flags{path} || $method;
- my $absolute = 0;
+ if ( $flags{local} || $flags{global} ) {
+ push( @{ $flags{path} }, $prefix ? "/$prefix/$method" : "/$method" )
+ if $flags{local};
- if ( $path =~ /^\/(.+)/ ) {
- $path = $1;
- $absolute = 1;
- }
+ push( @{ $flags{path} }, "/$method" ) if $flags{global};
+ }
- $absolute = 1 if $flags{global};
- my $name = $absolute ? $path : $prefix ? "$prefix/$path" : $path;
- $self->actions->{plain}->{$name} = $action;
+ for my $path ( @{ $flags{path} } ) {
+ if ( $path =~ /^\// ) { $path =~ s/^\/// }
+ else { $path = $prefix ? "$prefix/$path" : $path }
+ $self->actions->{plain}->{$path} = $action;
}
- if ( my $regex = $flags{regex} ) {
+ for my $regex ( @{ $flags{regex} } ) {
push @{ $self->actions->{compiled} }, [ $regex, qr#$regex# ];
$self->actions->{regex}->{$regex} = $action;
}