[Jifty-commit] r875 - jifty/trunk/lib/Jifty
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Wed Apr 19 22:56:08 EDT 2006
Author: autrijus
Date: Wed Apr 19 22:56:07 2006
New Revision: 875
Modified:
jifty/trunk/lib/Jifty/Dispatcher.pm
Log:
* Jifty::Dispatcher: _compile_glob is now closer to unixy behaviour:
/*/ # one or more chars must match at *
/foo/* # one or more
/*foo # zero or more
/foo* # zero or more
/foo?? # captured as one unit
/foo???* # two units
also documented it more thoroughly in POD.
Modified: jifty/trunk/lib/Jifty/Dispatcher.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Dispatcher.pm (original)
+++ jifty/trunk/lib/Jifty/Dispatcher.pm Wed Apr 19 22:56:07 2006
@@ -886,9 +886,10 @@
}
# Make all metachars into capturing submatches
- unless ( $cond
- =~ s{( (?: \\ [*?] )+ )}{'('. $self->_compile_glob($1) .')'}egx )
- {
+ if ( $cond =~ / \\ [*?] /x) {
+ $cond = _compile_glob($cond);
+ }
+ else {
$cond = "($cond)";
}
@@ -901,13 +902,59 @@
Turns a metaexpression containing * and ? into a capturing perl regex pattern.
+The rules are:
+
+=over 4
+
+=item *
+
+A C<*> between two C</> characthers, or between a C</> and end of string,
+should at match one or more non-slash characters:
+
+ /foo/*/bar
+ /foo/*/
+ /foo/*
+ /*
+
+=item *
+
+All other C<*> can match zero or more non-slash characters:
+
+ /*bar
+ /foo*bar
+ *
+
+=item *
+
+Consecutive C<?> marks are captured together:
+
+ /foo???bar # One capture for ???
+ /foo??* # Two captures, one for ?? and one for *
+
+=back
+
=cut
sub _compile_glob {
my ( $self, $glob ) = @_;
- $glob =~ s{\\}{}g;
- $glob =~ s{\*}{[^/]+}g;
- $glob =~ s{\?}{[^/]}g;
+ $glob =~ s{
+ # Stars between two slashes, or between a slash and end-of-string,
+ # should at match one or more non-slash characters.
+ (?<= \\ /) # lookbehind for slash
+ \\ \* # star
+ (?= \\ / | \z) # lookahead for slash or end-of-string
+ }{([^/]+)}gx;
+ $glob =~ s{
+ # All other stars can match zero or more non-slash character.
+ \\ \*
+ }{([^/]*)}gx;
+ $glob =~ s{
+ # Consecutive question marks are captured as one unit;
+ # we do this by capturing them and then repeat the result pattern
+ # for that many times. The divide-by-two takes care of the
+ # extra backslashes.
+ ( (?: \\ \? )+ )
+ }{([^/]{${ \( length($1)/2 ) }})}gx;
$glob;
}
More information about the Jifty-commit
mailing list