In perl.git, the branch ap/baseincguard has been updated

<http://perl5.git.perl.org/perl.git/commitdiff/f7353e3479cc0ecf3d8962e6011b103af978647b?hp=72be9a047675de9450eb7a492c222490c1aef5e7>

- Log -----------------------------------------------------------------
commit f7353e3479cc0ecf3d8962e6011b103af978647b
Author: Aristotle Pagaltzis <[email protected]>
Date:   Thu Oct 20 15:46:17 2016 +0200

    base: simplify test name

R100    dist/base/t/incmodified-vs-incdot.t     dist/base/t/incdot.t

commit 731dfe2db5c1fe2489e6776c928fc6f22b757b9c
Author: Aristotle Pagaltzis <[email protected]>
Date:   Thu Oct 20 15:45:51 2016 +0200

    base: only hide @INC . from optional module loads
    
    This patch removes the error message improvements because the condition
    in which the extended error message would be shown no longer exists: it
    was only ever shown for non-optional module loads, but this patch stops
    base from modifying @INC in the first place when the module load is not
    optional.

M       dist/base/lib/base.pm
D       dist/base/t/incdot.t
M       dist/base/t/incmodified-vs-incdot.t
A       dist/base/t/lib/BaseIncChecker.pm
M       dist/base/t/lib/BaseIncDoubleExtender.pm
M       dist/base/t/lib/BaseIncExtender.pm
-----------------------------------------------------------------------

Summary of changes:
 dist/base/lib/base.pm                    | 22 ++++-----------------
 dist/base/t/incdot.t                     | 34 +++++++++++++++++++++-----------
 dist/base/t/incmodified-vs-incdot.t      | 27 -------------------------
 dist/base/t/lib/BaseIncChecker.pm        |  5 +++++
 dist/base/t/lib/BaseIncDoubleExtender.pm |  2 +-
 dist/base/t/lib/BaseIncExtender.pm       |  2 +-
 6 files changed, 34 insertions(+), 58 deletions(-)
 delete mode 100644 dist/base/t/incmodified-vs-incdot.t
 create mode 100644 dist/base/t/lib/BaseIncChecker.pm

diff --git a/dist/base/lib/base.pm b/dist/base/lib/base.pm
index 1c751eb..1216a48 100644
--- a/dist/base/lib/base.pm
+++ b/dist/base/lib/base.pm
@@ -103,9 +103,9 @@ sub import {
             {
                 local $SIG{__DIE__};
                 my $fn = _module_to_filename($base);
-                my $dotty = $INC[-1] eq '.' && ( $INC[-1] = sub {()} );
                 eval {
-                    my $redotty = $dotty && bless [ $dotty ], 
'base::__inc_scope_guard';
+                    my $redot = $INC[-1] eq '.' && !!%{"$base\::"} # only when 
optional
+                        && bless [ $INC[-1] = sub {()} ], 
'base::__inc_scope_guard';
                     require $fn
                 };
                 # Only ignore "Can't locate" errors from our eval require.
@@ -120,26 +120,12 @@ sub import {
                           || $@ =~ /Compilation failed in require at .* line 
[0-9]+(?:, <[^>]*> (?:line|chunk) [0-9]+)?\.\n\z/;
                 unless (%{"$base\::"}) {
                     require Carp;
-                    my @inc = $dotty ? @INC[0..$#INC-1] : @INC;
                     local $" = " ";
-                    my $e = <<ERROR;
+                    Carp::croak(<<ERROR);
 Base class package "$base" is empty.
     (Perhaps you need to 'use' the module which defines that package first,
-    or make that module available in \@INC (\@INC contains: @inc).
+    or make that module available in \@INC (\@INC contains: @INC).
 ERROR
-                    if ($dotty && -e $fn) {
-                        $e .= <<ERROS;
-    The file $fn does exist in the current directory.  But note
-    that base.pm, when loading a module, now ignores the current working
-    directory if it is the last entry in \@INC.  If your software worked on
-    previous versions of Perl, the best solution is to use FindBin to
-    detect the path properly and to add that path to \@INC.  As a last
-    resort, you can re-enable looking in the current working directory by
-    adding "use lib '.'" to your code.
-ERROS
-                    }
-                    $e =~ s/\n\z/)\n/;
-                    Carp::croak($e);
                 }
                 $sigdie = $SIG{__DIE__} || undef;
             }
diff --git a/dist/base/t/incdot.t b/dist/base/t/incdot.t
index 1619492..64cf8c8 100644
--- a/dist/base/t/incdot.t
+++ b/dist/base/t/incdot.t
@@ -1,19 +1,31 @@
 #!/usr/bin/perl -w
 
 use strict;
+use Test::More tests => 11;  # one test is in each BaseInc* itself
 
-use base ();
+use lib 't/lib';
 
-use Test::More tests => 2;
+# make it look like an older perl
+BEGIN { push @INC, '.' if $INC[-1] ne '.' }
 
-if ($INC[-1] ne '.') { push @INC, '.' }
+use base 'BaseIncChecker';
 
-my $inc = quotemeta "@INC[0..$#INC-1]";
+BEGIN { @BaseIncExtender::ISA = () } # make it look like an optional load
+use base 'BaseIncExtender';
 
-eval { 'base'->import("foo") };
-like $@, qr/\@INC contains: $inc\).\)/,
-    'Error does not list final dot in @INC (or mention use lib)';
-eval { 'base'->import('t::lib::Dummy') };
-like $@, qr<\@INC contains: $inc\).\n(?x:
-           )    The file t/lib/Dummy\.pm does exist in the current direct>,
-    'special cur dir message for existing files in . that are ignored';
+BEGIN {
+    is $INC[0], 't/lib/blahblah', 'modules loaded by base can prepend entries 
to @INC';
+    is $INC[1], 't/lib', 'previously prepended additional @INC entry remains';
+    is $INC[-1], '.', 'dot still at end @INC after using base';
+}
+
+BEGIN { @BaseIncDoubleExtender::ISA = () } # make it look like an optional load
+use base 'BaseIncDoubleExtender';
+
+BEGIN {
+    is $INC[0], 't/lib/blahdeblah', 'modules loaded by base can prepend 
entries to @INC';
+    is $INC[1], 't/lib/blahblah', 'previously prepended additional @INC entry 
remains';
+    is $INC[2], 't/lib', 'previously prepended additional @INC entry remains';
+    is $INC[-2], '.', 'dot still at previous end of @INC after using base';
+    is $INC[-1], 't/lib/on-end', 'modules loaded by base can append entries to 
@INC';
+}
diff --git a/dist/base/t/incmodified-vs-incdot.t 
b/dist/base/t/incmodified-vs-incdot.t
deleted file mode 100644
index a5288e8..0000000
--- a/dist/base/t/incmodified-vs-incdot.t
+++ /dev/null
@@ -1,27 +0,0 @@
-#!/usr/bin/perl -w
-
-use strict;
-use Test::More tests => 10;  # one test is in each BaseInc* itself
-
-use lib 't/lib';
-
-# make it look like an older perl
-BEGIN { push @INC, '.' if $INC[-1] ne '.' }
-
-use base 'BaseIncExtender';
-
-BEGIN {
-    is $INC[0], 't/lib/blahblah', 'modules loaded by base can prepend entries 
to @INC';
-    is $INC[1], 't/lib', 'previously prepended additional @INC entry remains';
-    is $INC[-1], '.', 'dot still at end @INC after using base';
-}
-
-use base 'BaseIncDoubleExtender';
-
-BEGIN {
-    is $INC[0], 't/lib/blahdeblah', 'modules loaded by base can prepend 
entries to @INC';
-    is $INC[1], 't/lib/blahblah', 'previously prepended additional @INC entry 
remains';
-    is $INC[2], 't/lib', 'previously prepended additional @INC entry remains';
-    is $INC[-2], '.', 'dot still at previous end of @INC after using base';
-    is $INC[-1], 't/lib/on-end', 'modules loaded by base can append entries to 
@INC';
-}
diff --git a/dist/base/t/lib/BaseIncChecker.pm 
b/dist/base/t/lib/BaseIncChecker.pm
new file mode 100644
index 0000000..2cbbbcc
--- /dev/null
+++ b/dist/base/t/lib/BaseIncChecker.pm
@@ -0,0 +1,5 @@
+package BaseIncChecker;
+
+BEGIN { ::ok( $INC[-1] eq '.', 'trailing dot remains in @INC during mandatory 
module load from base' ) }
+
+1;
diff --git a/dist/base/t/lib/BaseIncDoubleExtender.pm 
b/dist/base/t/lib/BaseIncDoubleExtender.pm
index 455c5de..86d88c3 100644
--- a/dist/base/t/lib/BaseIncDoubleExtender.pm
+++ b/dist/base/t/lib/BaseIncDoubleExtender.pm
@@ -1,6 +1,6 @@
 package BaseIncDoubleExtender;
 
-BEGIN { ::ok( $INC[-1] ne '.', 'no trailing dot in @INC during module load 
from base' ) }
+BEGIN { ::ok( $INC[-1] ne '.', 'no trailing dot in @INC during optional module 
load from base' ) }
 
 use lib 't/lib/blahdeblah';
 
diff --git a/dist/base/t/lib/BaseIncExtender.pm 
b/dist/base/t/lib/BaseIncExtender.pm
index 3b693ad..2e4e97b 100644
--- a/dist/base/t/lib/BaseIncExtender.pm
+++ b/dist/base/t/lib/BaseIncExtender.pm
@@ -1,6 +1,6 @@
 package BaseIncExtender;
 
-BEGIN { ::ok( $INC[-1] ne '.', 'no trailing dot in @INC during module load 
from base' ) }
+BEGIN { ::ok( $INC[-1] ne '.', 'no trailing dot in @INC during optional module 
load from base' ) }
 
 use lib 't/lib/blahblah';
 

--
Perl5 Master Repository

Reply via email to