From: Vincent Pit Date: Sun, 29 Jun 2008 15:43:48 +0000 (+0200) Subject: Importing Regexp-Wildcards-0.03.tar.gz X-Git-Tag: v0.03^0 X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2FRegexp-Wildcards.git;a=commitdiff_plain;h=eafc1dab0ebd73e592fda42a9db18d6d4a64c96b Importing Regexp-Wildcards-0.03.tar.gz --- diff --git a/Changes b/Changes index 98afe3e..1490402 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,9 @@ Revision history for Regexp-Wildcards +0.03 2007-06-17 14:45 UTC + + Fix : Missing PREREQ_PM in Makefile.PL + + Fix : Typos in pod. + 0.02 2007-06-16 09:15 UTC + Fix : wc2re_unix should escape top-level commas. + Fix : added missing samples/wc2re.pl diff --git a/MANIFEST b/MANIFEST index f3ff075..2cd91d2 100644 --- a/MANIFEST +++ b/MANIFEST @@ -1,9 +1,9 @@ Changes +lib/Regexp/Wildcards.pm +Makefile.PL MANIFEST META.yml -Makefile.PL README -lib/Regexp/Wildcards.pm samples/wc2re.pl t/00-load.t t/01-import.t diff --git a/META.yml b/META.yml index f2ef79d..24e1ab8 100644 --- a/META.yml +++ b/META.yml @@ -1,12 +1,13 @@ --- #YAML:1.0 name: Regexp-Wildcards -version: 0.02 -abstract: Converts wildcards expressions to Perl regular expressions. +version: 0.03 +abstract: Converts wildcard expressions to Perl regular expressions. license: perl generated_by: ExtUtils::MakeMaker version 6.32 distribution_type: module requires: Test::More: 0 + Text::Balanced: 0 meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.2.html version: 1.2 diff --git a/Makefile.PL b/Makefile.PL index 20c7a46..e02d953 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -11,6 +11,7 @@ WriteMakefile( PL_FILES => {}, PREREQ_PM => { 'Test::More' => 0, + 'Text::Balanced' => 0, }, dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', }, clean => { FILES => 'Regexp-Wildcards-*' }, diff --git a/README b/README index 037d0d2..dab8850 100644 --- a/README +++ b/README @@ -1,9 +1,9 @@ NAME - Regexp::Wildcards - Converts wildcards expressions to Perl regular + Regexp::Wildcards - Converts wildcard expressions to Perl regular expressions. VERSION - Version 0.02 + Version 0.03 SYNOPSIS use Regexp::Wildcards qw/wc2re/; @@ -16,16 +16,12 @@ SYNOPSIS DESCRIPTION In many situations, users may want to specify patterns to match but don't need the full power of regexps. Wildcards make one of those sets - of simplified rules. This module converts wildcards expressions to Perl + of simplified rules. This module converts wildcard expressions to Perl regular expressions, so that you can use them for matching. It handles the "*" and "?" jokers, as well as Unix bracketed alternatives "{,}", and uses the backspace ("\") as an escape character. Wrappers are provided to mimic the behaviour of Windows and Unix shells. -EXPORT - Four functions are exported only on request : "wc2re", "wc2re_unix", - "wc2re_win32" and "wc2re_jokers". - FUNCTIONS "wc2re_unix" This function takes as its only argument the wildcard string to process, @@ -38,14 +34,13 @@ FUNCTIONS "{" and "}". Commas outside of any bracket-delimited block will also be escaped. - # This is a valid brackets expression which is correctly handled. + # This is a valid bracket expression, and is completely translated. print 'ok' if wc2re_unix('{a{b,c}d,e}') eq '(?:a(?:b|c)d|e)'; - Unbalanced bracket expressions can always be rescued, but it may change - completely its meaning. For example : + The function handles unbalanced bracket expressions, by escaping + everything it can't recognize. For example : - # The first comma is replaced, and the remaining brackets and comma are - # escaped. + # The first comma is replaced, and the remaining brackets and comma are escaped. print 'ok' if wc2re_unix('{a\\{b,c}d,e}') eq '(?:a\\{b|c)d\\,e\\}'; # All the brackets and commas are escaped. @@ -72,6 +67,10 @@ FUNCTIONS rules to apply, currently either "unix", "win32" or "jokers". If the type is undefined, it defaults to "unix". +EXPORT + These four functions are exported only on request : "wc2re", + "wc2re_unix", "wc2re_win32" and "wc2re_jokers". + DEPENDENCIES Text::Balanced, which is bundled with perl since version 5.7.3 @@ -81,8 +80,8 @@ SEE ALSO Net::FTPServer has a method for that. Only jokers are translated, and escaping won't preserve them. - File::Find::Match::Util has a "wildcar" function that compiles a - matcher. Only handles "*". + File::Find::Match::Util has a "wildcard" function that compiles a + matcher. It only handles "*". Text::Buffer has the "convertWildcardToRegex" class method that handles jokers. diff --git a/lib/Regexp/Wildcards.pm b/lib/Regexp/Wildcards.pm index 62141e2..a077628 100644 --- a/lib/Regexp/Wildcards.pm +++ b/lib/Regexp/Wildcards.pm @@ -7,15 +7,15 @@ use Text::Balanced qw/extract_bracketed/; =head1 NAME -Regexp::Wildcards - Converts wildcards expressions to Perl regular expressions. +Regexp::Wildcards - Converts wildcard expressions to Perl regular expressions. =head1 VERSION -Version 0.02 +Version 0.03 =cut -our $VERSION = '0.02'; +our $VERSION = '0.03'; =head1 SYNOPSIS @@ -28,26 +28,7 @@ our $VERSION = '0.02'; =head1 DESCRIPTION -In many situations, users may want to specify patterns to match but don't need the full power of regexps. Wildcards make one of those sets of simplified rules. This module converts wildcards expressions to Perl regular expressions, so that you can use them for matching. It handles the C<*> and C jokers, as well as Unix bracketed alternatives C<{,}>, and uses the backspace (C<\>) as an escape character. Wrappers are provided to mimic the behaviour of Windows and Unix shells. - -=head1 EXPORT - -Four functions are exported only on request : C, C, C and C. - -=cut - -use base qw/Exporter/; - -my %types = ( - 'jokers' => \&wc2re_jokers, - 'unix' => \&wc2re_unix, - 'win32' => \&wc2re_win32 -); - -our @EXPORT = (); -our @EXPORT_OK = ('wc2re', map { 'wc2re_' . $_ } keys %types); -our @EXPORT_FAIL = qw/extract do_jokers do_commas do_brackets do_bracketed/; -our %EXPORT_TAGS = ( all => [ @EXPORT_OK ] ); +In many situations, users may want to specify patterns to match but don't need the full power of regexps. Wildcards make one of those sets of simplified rules. This module converts wildcard expressions to Perl regular expressions, so that you can use them for matching. It handles the C<*> and C jokers, as well as Unix bracketed alternatives C<{,}>, and uses the backspace (C<\>) as an escape character. Wrappers are provided to mimic the behaviour of Windows and Unix shells. =head1 FUNCTIONS @@ -55,13 +36,12 @@ our %EXPORT_TAGS = ( all => [ @EXPORT_OK ] ); This function takes as its only argument the wildcard string to process, and returns the corresponding regular expression according to standard Unix wildcard rules. It successively escapes all unprotected regexp special characters that doesn't hold any meaning for wildcards, turns jokers into their regexp equivalents, and changes bracketed blocks into C<(?:|)> alternations. If brackets are unbalanced, it will try to substitute as many of them as possible, and then escape the remaining C<{> and C<}>. Commas outside of any bracket-delimited block will also be escaped. - # This is a valid brackets expression which is correctly handled. + # This is a valid bracket expression, and is completely translated. print 'ok' if wc2re_unix('{a{b,c}d,e}') eq '(?:a(?:b|c)d|e)'; -Unbalanced bracket expressions can always be rescued, but it may change completely its meaning. For example : +The function handles unbalanced bracket expressions, by escaping everything it can't recognize. For example : - # The first comma is replaced, and the remaining brackets and comma are - # escaped. + # The first comma is replaced, and the remaining brackets and comma are escaped. print 'ok' if wc2re_unix('{a\\{b,c}d,e}') eq '(?:a\\{b|c)d\\,e\\}'; # All the brackets and commas are escaped. @@ -117,6 +97,12 @@ A generic function that wraps around all the different rules. The first argument =cut +my %types = ( + 'jokers' => \&wc2re_jokers, + 'unix' => \&wc2re_unix, + 'win32' => \&wc2re_win32 +); + sub wc2re { my ($wc, $type) = @_; return unless defined $wc; @@ -124,6 +110,19 @@ sub wc2re { return $types{lc $type}($wc); } +=head1 EXPORT + +These four functions are exported only on request : C, C, C and C. + +=cut + +use base qw/Exporter/; + +our @EXPORT = (); +our @EXPORT_OK = ('wc2re', map { 'wc2re_' . $_ } keys %types); +our @EXPORT_FAIL = qw/extract do_jokers do_commas do_brackets do_bracketed/; +our %EXPORT_TAGS = ( all => [ @EXPORT_OK ] ); + =head1 DEPENDENCIES L, which is bundled with perl since version 5.7.3 @@ -134,7 +133,7 @@ Some modules provide incomplete alternatives as helper functions : L has a method for that. Only jokers are translated, and escaping won't preserve them. -L has a C function that compiles a matcher. Only handles C<*>. +L has a C function that compiles a matcher. It only handles C<*>. L has the C class method that handles jokers.