X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FDispatcher.pm;h=89de3caa22e02c84b734ba3984657f470161732b;hb=8199eac32fd36ac2eb0754ef934d7159de23277d;hp=eb4662c5e7ab92d30d33115634f950d767ab4a41;hpb=fbcc39ad23f2bbecf5d84c9ba581e6af86fcd460;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/Dispatcher.pm b/lib/Catalyst/Dispatcher.pm index eb4662c..89de3ca 100644 --- a/lib/Catalyst/Dispatcher.pm +++ b/lib/Catalyst/Dispatcher.pm @@ -130,37 +130,33 @@ sub forward { 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/^\/// ) { + $command_copy = + Catalyst::Utils::class2prefix( $caller, $c->config->{case_sensitive} ) + . "/${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} ) { @@ -354,10 +350,12 @@ sub set_action { 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; } } @@ -388,8 +386,6 @@ sub set_action { $parent = $child; } - my $forward = $prefix ? "$prefix/$method" : $method; - my $reverse = $prefix ? "$prefix/$method" : $method; my $action = Catalyst::Action->new( @@ -403,35 +399,40 @@ sub set_action { 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; }