Skip Menu |

This queue is for tickets about the Digest-Perl-MD5 CPAN distribution.

Report information
The Basics
Id: 78392
Status: resolved
Priority: 0/
Queue: Digest-Perl-MD5

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

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



Subject: Localize $_ to save naive modules from having it clobbered
Some modules (App::FatPacker) require their packages in such a way that modifying $_ without localizing it will break them. This patch just localizes $_ before reading from <DATA>. (I've also submitted a patch to App::FatPacker to have it stop doing that.)
Subject: digest-perl-md5.patch
--- /opt/perl5/perls/perl-5.16.0/lib/site_perl/5.16.0/Digest/Perl/MD5.pm 2004-08-27 16:28:25.000000000 -0400 +++ Digest/Perl/MD5.pm 2012-07-15 21:27:31.000000000 -0400 @@ -61,6 +61,7 @@ ); my $insert = "\n"; + local $_; while(<DATA>) { chomp; next unless /^[FGHI]/;
On Sun Jul 15 21:32:01 2012, WINTER wrote: Show quoted text
> Some modules (App::FatPacker) require their packages in such a way that > modifying $_ without localizing it will break them. This patch just > localizes $_ before reading from <DATA>. (I've also submitted a patch to > App::FatPacker to have it stop doing that.)
Due to bugs in earlier perls, it’s best to avoid local($_), as it does not play along nicely with tied variables. You should use local *_ (but beware that @_ will no longer be accessible) or for(my $dummy) {...}
On Mon Jul 16 01:04:32 2012, SPROUT wrote: Show quoted text
> Due to bugs in earlier perls, it’s best to avoid local($_), as it does > not play along nicely with tied > variables. > > You should use local *_ (but beware that @_ will no longer be > accessible) or for(my $dummy) {...}
Ah, good to know! The subroutine in question (gen_code) doesn't take any arguments so local *_ should be safe here. I picked it because it was the most minimal change I could make to fix the problem. However, that said, looking again, the changes needed to use a variable there are small. I've attached an updated patch that avoids using local.
Subject: no-local.patch
--- a/Digest/Perl/MD5.pm 2004-08-27 16:28:25.000000000 -0400 +++ b/Digest/Perl/MD5.pm 2012-07-16 01:16:42.000000000 -0400 @@ -61,10 +61,10 @@ ); my $insert = "\n"; - while(<DATA>) { - chomp; - next unless /^[FGHI]/; - my ($func,@x) = split /,/; + while(defined( my $data = <DATA> )) { + chomp $data; + next unless $data =~ /^[FGHI]/; + my ($func,@x) = split /,/, $data; my $c = $f{$func}; $c =~ s/X(\d)/$x[$1]/g; $c =~ s/(S\d{2})/$s{$1}/;
On Mon Jul 16 01:20:16 2012, WINTER wrote: Show quoted text
> > I've attached an updated patch that avoids using local.
Spent some time tracking down this bug, glad to know there's already a patch. Looks good, can you please apply it? My specific case was a script with a for loop which created an object from a library which dynamically require'd Spreadsheet::ParseExcel, which used this library and wiped out $_. I usually don't use $_ in a loop that calls any sort of external functions, but sometimes I forget to be paranoid...
Resolved in 1.9.