Skip Menu |

This queue is for tickets about the ExtUtils-Depends CPAN distribution.

Report information
The Basics
Id: 100853
Status: resolved
Worked: 1 hour (60 min)
Priority: 0/
Queue: ExtUtils-Depends

People
Owner: Nobody in particular
Requestors: ETJ [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.402
Fixed in: (no value)



Subject: EUD::load uses wrong filename scheme
This line (https://metacpan.org/source/ExtUtils::Depends#L181) says: sub load { my $dep = shift; my @pieces = split /::/, $dep; my @suffix = qw/ Install Files /; my $relpath = File::Spec->catfile (@pieces, @suffix) . '.pm'; my $depinstallfiles = join "::", @pieces, @suffix; eval { require $relpath } or die " *** Can't load dependency information for $dep:\n $@\n"; This is a problem because this (https://metacpan.org/pod/distribution/perl/pod/perlfunc.pod#require) says: require Foo::Bar [...] will actually look for the "Foo/Bar.pm" file in the directories specified in the @INC array. In other words, the correct FS separator for require isn't the local FS separator, it's always "/". EUD needs to conform to that. If you would like a patch, I can push one as I'm a GNOME contributor.
Subject: Re: [rt.cpan.org #100853] EUD::load uses wrong filename scheme
Date: Thu, 11 Dec 2014 12:00:01 +0100
To: bug-ExtUtils-Depends [...] rt.cpan.org
From: "Torsten Schönfeld" <kaffeetisch [...] gmx.de>
"Ed J via RT" <bug-ExtUtils-Depends@rt.cpan.org>: Show quoted text
> This line (https://metacpan.org/source/ExtUtils::Depends#L181) says: > > sub load { > my $dep = shift; > my @pieces = split /::/, $dep; > my @suffix = qw/ Install Files /; > my $relpath = File::Spec->catfile (@pieces, @suffix) . '.pm'; > my $depinstallfiles = join "::", @pieces, @suffix; > eval { > require $relpath > } or die " *** Can't load dependency information for $dep:\n $@\n"; > > This is a problem because this (https://metacpan.org/pod/distribution/perl/pod/perlfunc.pod#require) says: > > require Foo::Bar [...] will actually look for the "Foo/Bar.pm" file in the directories specified in the @INC array. > > In other words, the correct FS separator for require isn't the local FS separator, it's always "/". EUD needs to conform to that.
What is the actual problem you're encountering?
This is the reason my %INC-hacking in the tests for my ::Inline changes didn't work properly on Windows. The problem is that using your scheme to ::load Mod::Install::Files, then doing "require Mod::Install::Files" (which will become more common as I succeed in spreading the use/support of EUD), will double-load Mod::Install::Files on eg Win32, causing possible side-effects, because the current scheme ignores the Perl spec. We need to replace File::Spec there, with "join '/', @stuff".
On 2014-12-11 08:18:22, ETJ wrote: Show quoted text
> This is the reason my %INC-hacking in the tests for my ::Inline > changes didn't work properly on Windows. > > The problem is that using your scheme to ::load Mod::Install::Files, > then doing "require Mod::Install::Files" (which will become more > common as I succeed in spreading the use/support of EUD), will double- > load Mod::Install::Files on eg Win32, causing possible side-effects, > because the current scheme ignores the Perl spec. > > We need to replace File::Spec there, with "join '/', @stuff".
Even better would be to abstract away that little snippet of code entirely, and use Module::Runtime -- see either require_module() to do the full require, or module_notional_filename() to do the package -> filename translation. Unless you're trying to keep dependencies to a bare minimum there's no need to avoid using Module::Runtime, since it's already in use by low level toolchain code.
Subject: Re: [rt.cpan.org #100853] EUD::load uses wrong filename scheme
Date: Mon, 15 Dec 2014 10:54:09 +0100
To: bug-ExtUtils-Depends [...] rt.cpan.org
From: "Torsten Schönfeld" <kaffeetisch [...] gmx.de>
"Ed J via RT" <bug-ExtUtils-Depends@rt.cpan.org>: Show quoted text
> The problem is that using your scheme to ::load Mod::Install::Files, then doing "require Mod::Install::Files" (which will become more common as I succeed in spreading the use/support of EUD), will double-load Mod::Install::Files on eg Win32, causing possible side-effects, because the current scheme ignores the Perl spec. > > We need to replace File::Spec there, with "join '/', @stuff".
OK, I see. Then yes, please submit a patch for this, ideally with a comment explaining the hard-coded '/' and with a test that ensures that we don't regress in the future.
Subject: Re: [rt.cpan.org #100853] EUD::load uses wrong filename scheme
Date: Mon, 15 Dec 2014 11:31:51 +0100
To: bug-ExtUtils-Depends [...] rt.cpan.org
From: "Torsten Schönfeld" <kaffeetisch [...] gmx.de>
"Karen Etheridge via RT" <bug-ExtUtils-Depends@rt.cpan.org>: Show quoted text
> Even better would be to abstract away that little snippet of code entirely, and use > Module::Runtime -- see either require_module() to do the full require, > or module_notional_filename() to do the package -> filename translation. > Unless you're trying to keep dependencies to a bare minimum there's no need to > avoid using Module::Runtime, since it's already in use by low level toolchain code.
But if I'm not mistaken, nothing in ExtUtils::Depends' dependency chain currently requires Module::Runtime, so we would impose a new install-time requirement for all our orthodox users, and even a new run-time dependency for everyone using Ed's new stuff. In this particular case, I don't think this tradeoff is worth it, because the problem is so easily fixed. If, in the future, we find another bug in this code path, the tradeoff might change. Thanks for the suggestion, in any case!
On Mon Dec 15 05:32:02 2014, TSCH wrote: Show quoted text
> so we would impose a new > install-time requirement for all our orthodox users, and even a new > run-time dependency for everyone using Ed's new stuff.
My Inline-supporting patch doesn't create a run-time dependency; it produces data (in code form) that can optionally be consumed by other user code that wishes to use Inline. I attach a patch to EUD with a test that without the .pm change passes on Linux, fails on Windows; with .pm change, passes on both. If you like it and would like me to save you trouble and push it to the GNOME repo myself, let me know.
Subject: 0001-Use-to-make-load-filename-not-File-Spec-perldoc-f-re.patch
From 11306be3cd01fb3f282d85e143e40a6195f6516b Mon Sep 17 00:00:00 2001 From: Ed J <mohawk2@users.noreply.github.com> Date: Thu, 1 Jan 2015 17:18:06 +0000 Subject: [PATCH] Use / to make ::load filename, not File::Spec - perldoc -f require --- lib/ExtUtils/Depends.pm | 3 ++- t/02_save_load.t | 26 +++++++++++++++++++++++--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/lib/ExtUtils/Depends.pm b/lib/ExtUtils/Depends.pm index 8e2f916..74043e1 100644 --- a/lib/ExtUtils/Depends.pm +++ b/lib/ExtUtils/Depends.pm @@ -178,7 +178,8 @@ sub load { my $dep = shift; my @pieces = split /::/, $dep; my @suffix = qw/ Install Files /; - my $relpath = File::Spec->catfile (@pieces, @suffix) . '.pm'; + # not File::Spec - see perldoc -f require + my $relpath = join('/', @pieces, @suffix) . '.pm'; my $depinstallfiles = join "::", @pieces, @suffix; eval { require $relpath diff --git a/t/02_save_load.t b/t/02_save_load.t index 83769fd..088af94 100644 --- a/t/02_save_load.t +++ b/t/02_save_load.t @@ -2,7 +2,7 @@ use strict; use warnings; -use Test::More tests => 38; +use Test::More tests => 40; use FindBin; use lib "$FindBin::Bin/lib"; @@ -44,7 +44,18 @@ $dep_info->install (@installed_files); use Data::Dumper; $Data::Dumper::Terse = 1; -$dep_info->save_config (catfile $tmp_inc, qw(DepTest Install Files.pm)); +my $IFpm = catfile $tmp_inc, qw(DepTest Install Files.pm); +$dep_info->save_config ($IFpm); + +{ +# ensure '/' used for config filename in require, not File::Spec +open my $fh, '<', $IFpm or die "read $IFpm: $!"; +my $text = join '', <$fh>; +close $fh; +($text =~ s/1;\s*\Z/warn "LOADING\n";\n$&/) or die "Text substitution failed!"; +open $fh, '>', $IFpm or die "write $IFpm: $!"; +print $fh $text; +} # --------------------------------------------------------------------------- # @@ -75,7 +86,16 @@ foreach my $file (@c_files, @xs_files) { # --------------------------------------------------------------------------- # -my $info = ExtUtils::Depends::load ('DepTest'); +my $info; +{ +my $warning = ''; +local $SIG{__WARN__} = sub { $warning .= join '', @_; }; +$info = ExtUtils::Depends::load ('DepTest'); +like $warning, qr/LOADING/, 'loaded once'; +$warning = ''; +require DepTest::Install::Files; +unlike $warning, qr/LOADING/, 'not loaded twice'; +} my $install_part = qr|DepTest.Install|; like ($info->{inc}, $install_part, "loaded inc"); -- 2.1.0
Subject: Re: [rt.cpan.org #100853] EUD::load uses wrong filename scheme
Date: Sat, 03 Jan 2015 14:30:30 +0100
To: bug-ExtUtils-Depends [...] rt.cpan.org
From: Torsten Schoenfeld <kaffeetisch [...] gmx.de>
On 01.01.2015 18:28, Ed J via RT wrote: Show quoted text
> On Mon Dec 15 05:32:02 2014, TSCH wrote:
>> so we would impose a new install-time requirement for all our >> orthodox users, and even a new run-time dependency for everyone >> using Ed's new stuff.
> > My Inline-supporting patch doesn't create a run-time dependency; it > produces data (in code form) that can optionally be consumed by > other user code that wishes to use Inline.
I didn't express myself clearly. What I meant is that, if we switched to Module::Runtime for loading the '*::Install::Files' module, then every module that uses your Inline-API would acquire a run-time dependency on Module::Runtime, since Inline stuff is usually done at run-time. Show quoted text
> I attach a patch to EUD with a test that without the .pm change > passes on Linux, fails on Windows; with .pm change, passes on both.
The code changes look fine, but I wonder if the tests could not be written more simply by examining %INC for entries matching /DepTest\.pm/ after 'EU:D:load' and 'require'?
On Sat Jan 03 08:30:42 2015, TSCH wrote: Show quoted text
> I didn't express myself clearly. What I meant is that, if we switched > to Module::Runtime for loading the '*::Install::Files' module, then > every module that uses your Inline-API would acquire a run-time > dependency on Module::Runtime, since Inline stuff is usually done at > run-time.
Yes, that makes perfect sense. Show quoted text
> The code changes look fine, but I wonder if the tests could not be > written more simply by examining %INC for entries matching /DepTest\.pm/ > after 'EU:D:load' and 'require'?
(For the record it would have to be m:DepTest.*Files\.pm:) I felt it best to be as direct as possible about detecting the real problem: double loading. Therefore I submit that this approach (which only adds a few lines) is best.
Subject: Re: [rt.cpan.org #100853] EUD::load uses wrong filename scheme
Date: Sun, 04 Jan 2015 16:51:43 +0100
To: bug-ExtUtils-Depends [...] rt.cpan.org
From: Torsten Schoenfeld <kaffeetisch [...] gmx.de>
On 03.01.2015 16:51, Ed J via RT wrote: Show quoted text
>> The code changes look fine, but I wonder if the tests could not be >> written more simply by examining %INC for entries matching >> /DepTest\.pm/ after 'EU:D:load' and 'require'?
> > (For the record it would have to be m:DepTest.*Files\.pm:) I felt it > best to be as direct as possible about detecting the real problem: > double loading. Therefore I submit that this approach (which only > adds a few lines) is best.
OK. Final nitpick: why not simply append to the file instead of overwriting it? open my $fh, '>>', $IFpm or die "append to $IFpm: $!"; print $fh qq(\nwarn "LOADING\n";\n);
On Sun Jan 04 10:51:55 2015, TSCH wrote: Show quoted text
> Final nitpick: why not simply append to the file instead of overwriting it? > > open my $fh, '>>', $IFpm or die "append to $IFpm: $!"; > print $fh qq(\nwarn "LOADING\n";\n);
Done!
Subject: 0001-Use-to-make-load-filename-not-File-Spec-perldoc-f-re.patch
From 913bff0bad8bc4a2a882420af0b7505b9c0841b1 Mon Sep 17 00:00:00 2001 From: Ed J <mohawk2@users.noreply.github.com> Date: Thu, 1 Jan 2015 17:18:06 +0000 Subject: [PATCH] Use / to make ::load filename, not File::Spec - perldoc -f require --- lib/ExtUtils/Depends.pm | 3 ++- t/02_save_load.t | 21 ++++++++++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/lib/ExtUtils/Depends.pm b/lib/ExtUtils/Depends.pm index 8e2f916..74043e1 100644 --- a/lib/ExtUtils/Depends.pm +++ b/lib/ExtUtils/Depends.pm @@ -178,7 +178,8 @@ sub load { my $dep = shift; my @pieces = split /::/, $dep; my @suffix = qw/ Install Files /; - my $relpath = File::Spec->catfile (@pieces, @suffix) . '.pm'; + # not File::Spec - see perldoc -f require + my $relpath = join('/', @pieces, @suffix) . '.pm'; my $depinstallfiles = join "::", @pieces, @suffix; eval { require $relpath diff --git a/t/02_save_load.t b/t/02_save_load.t index 83769fd..998817f 100644 --- a/t/02_save_load.t +++ b/t/02_save_load.t @@ -2,7 +2,7 @@ use strict; use warnings; -use Test::More tests => 38; +use Test::More tests => 40; use FindBin; use lib "$FindBin::Bin/lib"; @@ -44,7 +44,13 @@ $dep_info->install (@installed_files); use Data::Dumper; $Data::Dumper::Terse = 1; -$dep_info->save_config (catfile $tmp_inc, qw(DepTest Install Files.pm)); +my $IFpm = catfile $tmp_inc, qw(DepTest Install Files.pm); +$dep_info->save_config ($IFpm); + +# ensure '/' used for config filename in require, not File::Spec +open my $iffh, '>>', $IFpm or die "write $IFpm: $!"; +print $iffh qq{\nwarn "LOADING\\n";\n1;\n}; +undef $iffh; # --------------------------------------------------------------------------- # @@ -75,7 +81,16 @@ foreach my $file (@c_files, @xs_files) { # --------------------------------------------------------------------------- # -my $info = ExtUtils::Depends::load ('DepTest'); +my $info; +{ +my $warning = ''; +local $SIG{__WARN__} = sub { $warning .= join '', @_; }; +$info = ExtUtils::Depends::load ('DepTest'); +like $warning, qr/LOADING/, 'loaded once'; +$warning = ''; +require DepTest::Install::Files; +unlike $warning, qr/LOADING/, 'not loaded twice'; +} my $install_part = qr|DepTest.Install|; like ($info->{inc}, $install_part, "loaded inc"); -- 2.1.0
Subject: Re: [rt.cpan.org #100853] EUD::load uses wrong filename scheme
Date: Mon, 05 Jan 2015 12:31:47 +0100
To: bug-ExtUtils-Depends [...] rt.cpan.org
From: Torsten Schoenfeld <kaffeetisch [...] gmx.de>
Looks good. Please go ahead and push to master.
Subject: Re: [rt.cpan.org #100853] EUD::load uses wrong filename scheme
Date: Mon, 05 Jan 2015 12:31:47 +0100
To: bug-ExtUtils-Depends [...] rt.cpan.org
From: Torsten Schoenfeld <kaffeetisch [...] gmx.de>
Looks good. Please go ahead and push to master.
On Mon Jan 05 06:39:25 2015, TSCH wrote: Show quoted text
> Looks good. Please go ahead and push to master.
Done! Thanks.