That's a step in the right direction, at least, but return sub { $_ = "1;"; 0; }; (with or without the explicit return) gets me
Foo.pm did not return a true value at -e line 1.
...which is very odd, seeing as that's the exact same thing you're returning from your example code. Requiring any combination of Foo and Local::Foo without my sub in place works fine, so I'm fairly confident that the problem is with the sub, not the modules being loaded.
In case there's some other error I'm missing, here's the current version of the sub I'm inserting into @INC:
BEGIN { unshift @INC, \&require_local }
sub require_local {
# Exit immediately if we're not processing overrides
return if $core_only;
my (undef, $filename) = @_;
# Keep track of what files we've already seen to avoid infinite lo
+ops
return if exists $already_seen{$filename};
$already_seen{$filename}++;
# We only want to check overrides in $base_namespace
return unless $filename =~ /^$base_namespace/;
# OK, that all passed, so we can load up the actual files
# Get the original version first, then overlay the local version
say STDERR "requiring $filename";
require $filename;
my $local_file = $filename;
if ($base_namespace) {
$local_file =~ s[^$base_namespace][${base_namespace}/Local];
} else {
# Empty base namespace is probably a bad idea, but it should b
+e
# handled anyhow
$local_file = 'Local/' . $local_file;
}
$already_seen{$local_file}++;
say STDERR "requiring $local_file";
# Failure to load local version is not fatal, since it may not exi
+st
no warnings 'redefine';
eval { require $local_file };
say STDERR "Done.";
return sub { $_ = "1;"; 0; };
}
All three messages are appear on STDOUT, along with the subroutine redefined warning for the sub I've duplicated in Local/Foo.pm, so the sub is definitely running all the way through. It just seems to be returning a false value. (I also tried return sub { $_ = "1;"; 1; }; and, as I expected, it went into an infinite loop waiting for the returned sub to declare EOF.) | [reply] [d/l] [select] |
What version of perl did you test that with? On
This is perl, v5.10.1 (*) built for i686-linux-gnu-thread-multi
(with 40 registered patches, see perl -V for more detail)
(it's the default system perl from latest Ubuntu) your example doesn't seem to be working for me:
$ perl -E 'use lib sub {say "Using $_[1]"; sub {$_ = "1;"; 0}}, sub {d
+ie}; use Blah; say "Hi!";'
Using Blah.pm
Blah.pm did not return a true value at -e line 1.
BEGIN failed--compilation aborted at -e line 1.
| [reply] [d/l] [select] |
Tested to be working on all versions of 5.12.
| [reply] |