In perl.git, the branch blead has been updated <http://perl5.git.perl.org/perl.git/commitdiff/df5a3819cf43fd65bb6db52619f7b36d3d11063f?hp=a9e68e41c8119940fa49cfc2da687e6818eece80>
- Log ----------------------------------------------------------------- commit df5a3819cf43fd65bb6db52619f7b36d3d11063f Author: Nicholas Clark <[email protected]> Date: Mon Oct 18 10:55:15 2010 +0200 Convert File::Glob::import to $Exporter::ExportLevel and grep. Previously it was using goto & and splice, and was not as simple to read. M ext/File-Glob/Glob.pm commit 22bc907ae9b9703f36931e4de30ca013ddb732f6 Author: Nicholas Clark <[email protected]> Date: Mon Oct 18 10:22:44 2010 +0200 Convert File::Glob::import to use given/when. M ext/File-Glob/Glob.pm commit 1d89eaefc9389231706769754db5b13acbd4e25d Author: Nicholas Clark <[email protected]> Date: Mon Oct 18 09:47:12 2010 +0200 Remove MacOS classic support from File::Glob's tests. M ext/File-Glob/t/basic.t M ext/File-Glob/t/case.t M ext/File-Glob/t/global.t M ext/File-Glob/t/taint.t ----------------------------------------------------------------------- Summary of changes: ext/File-Glob/Glob.pm | 24 ++++++------ ext/File-Glob/t/basic.t | 14 ++------ ext/File-Glob/t/case.t | 9 +---- ext/File-Glob/t/global.t | 88 ++++++++++++---------------------------------- ext/File-Glob/t/taint.t | 7 +--- 5 files changed, 41 insertions(+), 101 deletions(-) diff --git a/ext/File-Glob/Glob.pm b/ext/File-Glob/Glob.pm index 5ae3c6d..4219c7e 100644 --- a/ext/File-Glob/Glob.pm +++ b/ext/File-Glob/Glob.pm @@ -5,6 +5,7 @@ our($VERSION, @ISA, @EXPORT_OK, @EXPORT_FAIL, %EXPORT_TAGS, $AUTOLOAD, $DEFAULT_FLAGS); require XSLoader; +use feature 'switch'; @ISA = qw(Exporter); @@ -40,21 +41,20 @@ $VERSION = '1.09'; sub import { require Exporter; - my $i = 1; - while ($i < @_) { - if ($_[$i] =~ /^:(case|nocase|globally)$/) { - splice(@_, $i, 1); - $DEFAULT_FLAGS &= ~GLOB_NOCASE() if $1 eq 'case'; - $DEFAULT_FLAGS |= GLOB_NOCASE() if $1 eq 'nocase'; - if ($1 eq 'globally') { - local $^W; + local $Exporter::ExportLevel = $Exporter::ExportLevel + 1; + Exporter::import(grep { + my $passthrough; + given ($_) { + $DEFAULT_FLAGS &= ~GLOB_NOCASE() when ':case'; + $DEFAULT_FLAGS |= GLOB_NOCASE() when ':nocase'; + when (':globally') { + no warnings 'redefine'; *CORE::GLOBAL::glob = \&File::Glob::csh_glob; } - next; + $passthrough = 1; } - ++$i; - } - goto &Exporter::import; + $passthrough; + } @_); } sub AUTOLOAD { diff --git a/ext/File-Glob/t/basic.t b/ext/File-Glob/t/basic.t index b9d46b1..e331380 100644 --- a/ext/File-Glob/t/basic.t +++ b/ext/File-Glob/t/basic.t @@ -2,12 +2,7 @@ BEGIN { chdir 't' if -d 't'; - if ($^O eq 'MacOS') { - @INC = qw(: ::lib ::macos:lib); - } else { - @INC = '.'; - push @INC, '../lib'; - } + @INC = '../lib'; require Config; import Config; if ($Config{'extensions'} !~ /\bFile\/Glob\b/i) { print "1..0\n"; @@ -40,7 +35,7 @@ if ($^O eq 'VMS') { $ENV{PATH} = "/bin"; delete @ENV{qw(BASH_ENV CDPATH ENV IFS)}; my @correct = (); -if (opendir(D, $^O eq "MacOS" ? ":" : ".")) { +if (opendir(D, ".")) { @correct = grep { !/^\./ } sort readdir(D); closedir D; } @@ -131,10 +126,7 @@ is_deeply(\...@a, [($vms_mode ? 'test.' : 'TEST'), 'a', 'b']); # "~" should expand to $ENV{HOME} $ENV{HOME} = "sweet home"; @a = bsd_glob('~', GLOB_TILDE | GLOB_NOMAGIC); -SKIP: { - skip $^O, 1 if $^O eq "MacOS"; - is_deeply(\...@a, [$ENV{HOME}]); -} +is_deeply(\...@a, [$ENV{HOME}]); # GLOB_ALPHASORT (default) should sort alphabetically regardless of case mkdir "pteerslo", 0777; diff --git a/ext/File-Glob/t/case.t b/ext/File-Glob/t/case.t index 87f3b9f..04c307c 100644 --- a/ext/File-Glob/t/case.t +++ b/ext/File-Glob/t/case.t @@ -2,12 +2,7 @@ BEGIN { chdir 't' if -d 't'; - if ($^O eq 'MacOS') { - @INC = qw(: ::lib ::macos:lib); - } else { - @INC = '.'; - push @INC, '../lib'; - } + @INC = '../lib'; require Config; import Config; if ($Config{'extensions'} !~ /\bFile\/Glob\b/i) { print "1..0\n"; @@ -22,7 +17,7 @@ use File::Glob qw(:glob csh_glob); $loaded = 1; print "ok 1\n"; -my $pat = $^O eq "MacOS" ? ":op:G*.t" : "op/G*.t"; +my $pat = "op/G*.t"; # Test the actual use of the case sensitivity tags, via csh_glob() import File::Glob ':nocase'; diff --git a/ext/File-Glob/t/global.t b/ext/File-Glob/t/global.t index c0abbc5..9eb2de6 100644 --- a/ext/File-Glob/t/global.t +++ b/ext/File-Glob/t/global.t @@ -2,12 +2,7 @@ BEGIN { chdir 't' if -d 't'; - if ($^O eq 'MacOS') { - @INC = qw(: ::lib ::macos:lib); - } else { - @INC = '.'; - push @INC, '../lib'; - } + @INC = '../lib'; require Config; import Config; if ($Config{'extensions'} !~ /\bFile\/Glob\b/i) { print "1..0\n"; @@ -36,20 +31,16 @@ use File::Glob ':globally'; $loaded = 1; print "ok 1\n"; -$_ = $^O eq "MacOS" ? ":op:*.t" : "op/*.t"; +$_ = "op/*.t"; my @r = glob; -print "not " if $_ ne ($^O eq "MacOS" ? ":op:*.t" : "op/*.t"); +print "not " if $_ ne ("op/*.t"); print "ok 2\n"; print "# |@r|\nnot " if @r < 3; print "ok 3\n"; # check if <*/*> works -if ($^O eq "MacOS") { - @r = <:*:*.t>; -} else { - @r = <*/*.t>; -} +...@r = <*/*.t>; # at least t/global.t t/basic.t, t/taint.t print "not " if @r < 3; print "ok 4\n"; @@ -57,55 +48,34 @@ my $r = scalar @r; # check if scalar context works @r = (); -if ($^O eq "MacOS") { - while (defined($_ = <:*:*.t>)) { - #print "# $_\n"; - push @r, $_; - } -} else { - while (defined($_ = <*/*.t>)) { - #print "# $_\n"; - push @r, $_; - } +while (defined($_ = <*/*.t>)) { + #print "# $_\n"; + push @r, $_; } print "not " if @r != $r; print "ok 5\n"; # check if list context works @r = (); -if ($^O eq "MacOS") { - for (<:*:*.t>) { - #print "# $_\n"; - push @r, $_; - } -} else { - for (<*/*.t>) { - #print "# $_\n"; - push @r, $_; - } +for (<*/*.t>) { + #print "# $_\n"; + push @r, $_; } print "not " if @r != $r; print "ok 6\n"; # test if implicit assign to $_ in while() works @r = (); -if ($^O eq "MacOS") { - while (<:*:*.t>) { - #print "# $_\n"; - push @r, $_; - } -} else { - while (<*/*.t>) { - #print "# $_\n"; - push @r, $_; - } +while (<*/*.t>) { + #print "# $_\n"; + push @r, $_; } print "not " if @r != $r; print "ok 7\n"; # test if explicit glob() gets assign magic too my @s = (); -while (glob($^O eq 'MacOS' ? ':*:*.t' : '*/*.t')) { +while (glob('*/*.t')) { #print "# $_\n"; push @s, $_; } @@ -116,7 +86,7 @@ print "ok 8\n"; package Foo; use File::Glob ':globally'; @s = (); -while (glob($^O eq 'MacOS' ? ':*:*.t' : '*/*.t')) { +while (glob('*/*.t')) { #print "# $_\n"; push @s, $_; } @@ -126,26 +96,14 @@ print "ok 9\n"; # test if different glob ops maintain independent contexts @s = (); my $i = 0; -if ($^O eq "MacOS") { - while (<:*:*.t>) { - #print "# $_ <"; - push @s, $_; - while (<:bas*:*.t>) { - #print " $_"; - $i++; - } - #print " >\n"; - } -} else { - while (<*/*.t>) { - #print "# $_ <"; - push @s, $_; - while (<bas*/*.t>) { - #print " $_"; - $i++; - } - #print " >\n"; - } +while (<*/*.t>) { + #print "# $_ <"; + push @s, $_; + while (<bas*/*.t>) { + #print " $_"; + $i++; + } + #print " >\n"; } print "not " if "@r" ne "@s" or not $i; print "ok 10\n"; diff --git a/ext/File-Glob/t/taint.t b/ext/File-Glob/t/taint.t index 4c09903..fe2fa23 100644 --- a/ext/File-Glob/t/taint.t +++ b/ext/File-Glob/t/taint.t @@ -2,12 +2,7 @@ BEGIN { chdir 't' if -d 't'; - if ($^O eq 'MacOS') { - @INC = qw(: ::lib ::macos:lib); - } else { - @INC = '.'; - push @INC, '../lib'; - } + @INC = '../lib'; require Config; import Config; if ($Config{'extensions'} !~ /\bFile\/Glob\b/i) { print "1..0\n"; -- Perl5 Master Repository
