In perl.git, the branch blead has been updated <http://perl5.git.perl.org/perl.git/commitdiff/593ec880111baafd3d3ba9f38961d3b1fb7a00c0?hp=3fdf66f3176c84b8e8c3d510c0694640530b27e0>
- Log ----------------------------------------------------------------- commit 593ec880111baafd3d3ba9f38961d3b1fb7a00c0 Merge: 3fdf66f de937bd Author: Tony Cook <[email protected]> Date: Fri Oct 3 15:30:35 2014 +1000 [perl #122455] fix XSLoader loading other namespaces commit de937bde1656ced37af51591845e3f6573dbe0cd Author: Tony Cook <[email protected]> Date: Fri Oct 3 15:20:45 2014 +1000 bump $XSLoader::VERSION M dist/XSLoader/XSLoader_pm.PL commit 30837b2a7d75fc49f0e4a9eab53e400d4a673e59 Author: Graham Knop <[email protected]> Date: Fri Aug 1 08:30:42 2014 -0400 Allow XSLoader to load modules from a different namespace When trying to locate the binary component of a module, use the caller package to find the library root directory, not the passed in module name. Since the file path it is using is always taken from the caller, using the passed in package prevents it from finding the library root. If in the package File::Spec::Unix, and given XSLoader::load("Cwd"), the library root is three levels up from the filename of the File::Spec::Unix module, not one. M dist/XSLoader/XSLoader_pm.PL M dist/XSLoader/t/XSLoader.t commit 8e6aa27cd01d9a7bbb717248991e6168c5dad598 Author: Tony Cook <[email protected]> Date: Thu Aug 7 11:06:45 2014 +1000 [perl #122455] TODO test for XSLoader mishandling of namespaces M dist/XSLoader/t/XSLoader.t ----------------------------------------------------------------------- Summary of changes: dist/XSLoader/XSLoader_pm.PL | 7 ++++--- dist/XSLoader/t/XSLoader.t | 32 +++++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/dist/XSLoader/XSLoader_pm.PL b/dist/XSLoader/XSLoader_pm.PL index e382058..893846a 100644 --- a/dist/XSLoader/XSLoader_pm.PL +++ b/dist/XSLoader/XSLoader_pm.PL @@ -10,7 +10,7 @@ print OUT <<'EOT'; package XSLoader; -$VERSION = "0.17"; +$VERSION = "0.18"; #use strict; @@ -48,7 +48,8 @@ package XSLoader; sub load { package DynaLoader; - my ($module, $modlibname) = caller(); + my ($caller, $modlibname) = caller(); + my $module = $caller; if (@_) { $module = $_[0]; @@ -84,7 +85,7 @@ EOT print OUT <<'EOT'; my $modpname = join('/',@modparts); - my $c = @modparts; + my $c = () = split(/::/,$caller,-1); $modlibname =~ s,[\\/][^\\/]+$,, while $c--; # Q&D basename EOT diff --git a/dist/XSLoader/t/XSLoader.t b/dist/XSLoader/t/XSLoader.t index 20ca32b..0f279fa 100644 --- a/dist/XSLoader/t/XSLoader.t +++ b/dist/XSLoader/t/XSLoader.t @@ -33,7 +33,7 @@ my %modules = ( 'Time::HiRes'=> q| ::can_ok( 'Time::HiRes' => 'usleep' ) |, # 5.7.3 ); -plan tests => keys(%modules) * 3 + 8; +plan tests => keys(%modules) * 3 + 9; # Try to load the module use_ok( 'XSLoader' ); @@ -96,3 +96,33 @@ SKIP: { like $@, "/^Invalid version format/", 'correct error msg for invalid versions'; } + +SKIP: { + skip "Devel::Peek not available", 1 + unless $extensions =~ /\bDevel::Peek\b/; + + # XSLoader::load() assumes it's being called from a module, so + # pretend it is, first find when Devel/Peek.pm is + use File::Spec::Functions; + my $peek_file = catdir("Devel", "Peek.pm"); + my $module_path; + for my $dir (@INC) { + if (-f catfile($dir, $peek_file)) { + $module_path = catfile($dir, "Not", "Devel", "Peek.pm"); + last; + } + } + + skip "Cannot find $peek_file", 2 + unless $module_path; + + # [perl #122455] + # die instead of falling back to DynaLoader + local *XSLoader::bootstrap_inherit = sub { die "Fallback to DynaLoader\n" }; + ::ok( eval <<EOS, "test correct path searched for modules") +package Not::Devel::Peek; +#line 1 "$module_path" +XSLoader::load("Devel::Peek"); +EOS + or ::diag $@; +} -- Perl5 Master Repository
