X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FDispatchType%2FRegex.pm;fp=lib%2FCatalyst%2FDispatchType%2FRegex.pm;h=225096d3d75145be2fb81e6d159f7628b2118bea;hb=b40f98247e6d1c1a68517059d8bcbea48a93d8ad;hp=0d6da04b2f05bef060b5c84ae47a0b4cd19618cd;hpb=4a41d5d1ec3187cc41e15767b21c14b2aee31740;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/DispatchType/Regex.pm b/lib/Catalyst/DispatchType/Regex.pm index 0d6da04..225096d 100644 --- a/lib/Catalyst/DispatchType/Regex.pm +++ b/lib/Catalyst/DispatchType/Regex.pm @@ -168,6 +168,39 @@ sub uri_for_action { return undef; } +=head2 $self->splice_captures_from( $c, $action, $args ) + +Iterates over the regular expressions defined for the action. Stops when +the number of captures equals the number of supplied args. Replaces the +list of args with a list containing an array ref of args + +=cut + +sub splice_captures_from { + my ($self, $c, $action, $args) = @_; my $regexes; + + return 0 unless ($regexes = $action->attributes->{Regex}); + + foreach my $orig (@{ $regexes }) { + my $re = "$orig"; $re =~ s/^\^//; $re =~ s/\$$//; + my $num_caps = 0; + + while (my ($front, $rest) = split /\(/, $re, 2) { + last unless (defined $rest); + + ($rest, $re) = Text::Balanced::extract_bracketed( "(${rest}", '('); + $num_caps++; + } + + next unless ($num_caps == scalar @{ $args }); + + @{ $args } = ( [ @{ $args } ] ); + return 1; + } + + return 1; +} + =head1 AUTHORS Catalyst Contributors, see Catalyst.pm