Skip to content

Less hostile workaround for dot-in-inc #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions dist/base/lib/base.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ use vars qw($VERSION);
$VERSION = '2.24';
$VERSION =~ tr/_//d;

{
package #
base::__scope_guard;

sub DESTROY { $_[0]->[0]->() }
}

# constant.pm is slow
sub SUCCESS () { 1 }

Expand Down Expand Up @@ -91,14 +98,22 @@ sub import {

next if grep $_->isa($base), ($inheritor, @bases);

# Following blocks help isolate $SIG{__DIE__} changes
# Following blocks help isolate $SIG{__DIE__} and @INC changes
{
my $sigdie;
my ($sigdie, $redotty_scopeguard);
{
local $SIG{__DIE__};
my $fn = _module_to_filename($base);
local @INC = @INC;
pop @INC if my $dotty = $INC[-1] eq '.';

if ($INC[-1] eq '.') {
pop @INC;
my $localized_tail = $INC[-1];
$redotty_scopeguard = bless([ sub {
push @INC, '.'
if $localized_tail eq $INC[-1]||'';
} ], 'base::__scope_guard');
}

eval {
require $fn
};
Expand All @@ -120,7 +135,7 @@ 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).
ERROR
if ($dotty && -e $fn) {
if ($redotty_scopeguard && -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
Expand Down
30 changes: 30 additions & 0 deletions dist/base/t/extra_inc_via_base.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/perl -w

use strict;
use Test::More tests => 10; # one test is in each BaseInc* itself

use lib qw(t/lib);

# make it look like an older perl
BEGIN {
push @INC, '.'
if $INC[-1] ne '.';
}

use base 'BaseIncExtender';

BEGIN {
is $INC[0], 't/libleblab', 'Expected head @INC adjustment from within `use base`';
is $INC[1], 't/lib', 'Preexisting @INC adjustment still in @INC';
is $INC[-1], '.', 'Trailing . still in @INC ater `use base`';
}

use base 'BaseIncDoubleExtender';

BEGIN {
is $INC[0], 't/libloblub', 'Expected head @INC adjustment from within `use base`';
is $INC[1], 't/libleblab', 'Preexisting @INC adjustment still in @INC';
is $INC[2], 't/lib', 'Preexisting @INC adjustment still in @INC';
cmp_ok $INC[-2], 'ne', '.', 'Trailing . not reinserted erroneously';
is $INC[-1], 't/libonend', 'Expected tail @INC adjustment from within `use base`';
}
14 changes: 14 additions & 0 deletions dist/base/t/lib/BaseIncDoubleExtender.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package BaseIncDoubleExtender;

BEGIN {
::ok(
( $INC[-1] ne '.' ),
'. not at @INCs tail during `use base ...`',
);
}

use lib 't/libloblub';

push @INC, 't/libonend';

1;
12 changes: 12 additions & 0 deletions dist/base/t/lib/BaseIncExtender.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package BaseIncExtender;

BEGIN {
::ok(
( $INC[-1] ne '.' ),
'. not at @INCs tail during `use base ...`',
);
}

use lib 't/libleblab';

1;