I've found an interesting situation where require doesn't do the right thing. I've tested this from Perl v5.12.5 through v5.30.0 with the same result. It only seems to occur when local %INC
is used (even though it's preserving the state of %INC
as it would if it were not used).
Digging into it, it appears that %INC is set correctly for the filename, it's set to undef
.
#! /usr/bin/env perl
use strict;
use warnings;
use feature qw( say state );
sub _require;
sub _require {
state $i = 0;
local $_ = shift if @_;
local %INC = %INC; # With this line: "Return value is 1\n"
# Without:
# "9: Attempt to reload $_ aborted.\n"
# "9: Compilation failed in require at ...\n"
if ( my $return = eval {require} ) {
say "Return value is ", $return;
return $return;
} elsif ($@) {
return unless ++$i < 10;
foreach my $line ( split /\n/, $@ ) {
say $i, ": ", $line;
}
_require;
} else {
say "False value from require, but \$@ is also false";
}
}
$_ = @ARGV ? shift : "./t/Testing-failure.pm";
_require;
# t/Testing-failure.pm is below __END__
__END__
# An invalid Perl file
-
Flags:
Site configuration information for perl 5.18.2:
Configured by root at Sun Feb 24 21:26:39 PST 2019.
Summary of my perl5 (revision 5 version 18 subversion 2) configuration:
Platform:
osname=darwin, osvers=17.0, archname=darwin-thread-multi-2level
uname='darwin osx217.apple.com 17.0 darwin kernel version 16.1.0: mon oct 9 13:05:29 pdt 2017; root:xnu-3789.21.4.1.7~1development_x86_64 x86_64 '
config_args='-ds -e -Dprefix=/usr -Dccflags=-g -pipe -Dldflags= -Dman3ext=3pm -Duseithreads -Duseshrplib -Dinc_version_list=none -Dcc=cc'
hint=recommended, useposix=true, d_sigaction=define
useithreads=define, usemultiplicity=define
useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
use64bitint=define, use64bitall=define, uselongdouble=undef
usemymalloc=n, bincompat5005=undef
Compiler:
cc='cc', ccflags ='-arch x86_64 -arch i386 -g -pipe -fno-common -DPERL_DARWIN -fno-strict-aliasing -fstack-protector',
optimize='-Os',
cppflags='-g -pipe -fno-common -DPERL_DARWIN -fno-strict-aliasing -fstack-protector'
ccversion='', gccversion='4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.31)', gccosandvers=''
intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
alignbytes=8, prototype=define
Linker and Libraries:
ld='cc', ldflags ='-arch x86_64 -arch i386 -fstack-protector'
libpth=/usr/lib /usr/local/lib
libs=
perllibs=
libc=, so=dylib, useshrplib=true, libperl=libperl.dylib
gnulibc_version=''
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=bundle, d_dlsymun=undef, ccdlflags=' '
cccdlflags=' ', lddlflags='-arch x86_64 -arch i386 -bundle -undefined dynamic_lookup -fstack-protector'
Locally applied patches:
/Library/Perl/Updates/ comes before system perl directories
installprivlib and installarchlib points to the Updates directory
@inc for perl 5.18.2:
/Users/bkleemann/lib/perl/darwin-thread-multi-2level
/Users/bkleemann/lib/perl/darwin-thread-multi-2level
/Users/bkleemann/lib/perl
/Library/Perl/5.18/darwin-thread-multi-2level
/Library/Perl/5.18
/Network/Library/Perl/5.18/darwin-thread-multi-2level
/Network/Library/Perl/5.18
/Library/Perl/Updates/5.18.2/darwin-thread-multi-2level
/Library/Perl/Updates/5.18.2
/System/Library/Perl/5.18/darwin-thread-multi-2level
/System/Library/Perl/5.18
/System/Library/Perl/Extras/5.18/darwin-thread-multi-2level
/System/Library/Perl/Extras/5.18
.
Environment for perl 5.18.2:
DYLD_LIBRARY_PATH (unset)
HOME=/Users/bkleemann
LANG=en_US.UTF-8
LANGUAGE (unset)
LC_TERMINAL=iTerm2
LC_TERMINAL_VERSION=3.3.7
LD_LIBRARY_PATH (unset)
LOGDIR (unset)
PATH=/usr/local/Cellar/plenv/2.3.0/libexec:/Users/bkleemann/.plenv/shims:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/bkleemann/bin:.
PERL5LIB=/Users/bkleemann/lib/perl/darwin-thread-multi-2level:/Users/bkleemann/lib/perl
PERL_BADLANG (unset)
SHELL=/bin/bash
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4