Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Test-Simple CPAN distribution.

Report information
The Basics
Id: 73543
Status: resolved
Priority: 0/
Queue: Test-Simple

People
Owner: Nobody in particular
Requestors: 'spro^^*%*^6ut# [...] &$%*c
Cc:
AdminCc:

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



Subject: Use of local $_
In case you didn’t know, local($_) is evil. It interferes with a caller’s tied $_. This was supposedly fixed in Perl 5.14, but is actually still half broken. See <https://rt.perl.org/rt3/Ticket/Display.html?id=105912>. In earlier versions, it’s fully broken. (And Test::Simple still runs on earlier versions.) It actually surprisingly easy to run into this when an object provides a hash-like interface: for($thing->bar->baz->{foo}) { $_->frobnicate(0); $_->primble(1); $_->turnamate; } I downloaded MSCHWERN/Test-Simple-1.005000_002.tar.gz and ran ack on it: $ ack 'local\s*\(?\s*\$_' lib/TB2/Mouse.pm 691: local $_ = $args[0]; 1573: local $_ = $thing; 1614: local $_ = $value; lib/Test/Builder/Tester.pm 260: local $_; 340: local $_; t/test.pl 168:# Trying to avoid setting $_, or relying on local $_ to work. You ought to be using for($thing) instead. If you need to set it to a new variable that you can then subsequently modify, use for(my $dummy) { ... } or local *_ = \my $dummy;
Subject: Re: [rt.cpan.org #73543] Use of local $_
Date: Thu, 29 Dec 2011 02:57:39 -0800
To: bug-Test-Simple [...] rt.cpan.org
From: Michael G Schwern <schwern [...] pobox.com>
On 2011.12.28 4:53 PM, Father Chrysostomos via RT wrote: Show quoted text
> In case you didn’t know, local($_) is evil.
I did not know. Show quoted text
> $ ack 'local\s*\(?\s*\$_' > lib/TB2/Mouse.pm > 691: local $_ = $args[0]; > 1573: local $_ = $thing; > 1614: local $_ = $value;
That is just a copy of Mouse::Tiny. Would you be so kind as to report the problem to the Mouse folks? Show quoted text
> lib/Test/Builder/Tester.pm > 260: local $_; > 340: local $_;
Those appear to be unnecessary paranoia. $_ in map is already localized. I'll remove them now. https://github.com/schwern/test-more/commit/3e70c59093e205224ab597537cbf80e6166dc3ea Show quoted text
> You ought to be using for($thing) instead.
Instead of map? Show quoted text
> If you need to set it to a > new variable that you can then subsequently modify, use for(my $dummy) > { ... } or local *_ = \my $dummy;
On Thu Dec 29 05:57:51 2011, schwern@pobox.com wrote: Show quoted text
> On 2011.12.28 4:53 PM, Father Chrysostomos via RT wrote:
> > In case you didn’t know, local($_) is evil.
> > I did not know. > >
> > $ ack 'local\s*\(?\s*\$_' > > lib/TB2/Mouse.pm > > 691: local $_ = $args[0]; > > 1573: local $_ = $thing; > > 1614: local $_ = $value;
> > That is just a copy of Mouse::Tiny. Would you be so kind as to report > the > problem to the Mouse folks?
Reported as #73592. Show quoted text
>
> > lib/Test/Builder/Tester.pm > > 260: local $_; > > 340: local $_;
> > Those appear to be unnecessary paranoia. $_ in map is already > localized. > I'll remove them now. > https://github.com/schwern/test- > more/commit/3e70c59093e205224ab597537cbf80e6166dc3ea > >
> > You ought to be using for($thing) instead.
> > Instead of map?
No, map is fine. You can probably tell I didn’t run the code. :-) I ran into a problem testing one of my modules on an alpha Test::More. I had added tests to make sure my module didn’t use local $_, because I actually ran into a problem with it in real-world code. So I just downloaded the latest Test::Simple and ran ack. Show quoted text
>
> > If you need to set it to a > > new variable that you can then subsequently modify, use for(my
> $dummy)
> > { ... } or local *_ = \my $dummy;
On Wed Dec 28 16:53:40 2011, SPROUT wrote: Show quoted text
> In case you didn’t know, local($_) is evil. It interferes with a > caller’s tied $_. This was > supposedly fixed in Perl 5.14, but is actually still half broken. See > <https://rt.perl.org/rt3/Ticket/Display.html?id=105912>. In earlier > versions, it’s fully > broken. (And Test::Simple still runs on earlier versions.) > > It actually surprisingly easy to run into this when an object provides > a hash-like interface: > > for($thing->bar->baz->{foo}) { > $_->frobnicate(0); > $_->primble(1); > $_->turnamate; > } > > I downloaded MSCHWERN/Test-Simple-1.005000_002.tar.gz and ran ack on > it: > > $ ack 'local\s*\(?\s*\$_' > lib/TB2/Mouse.pm > 691: local $_ = $args[0]; > 1573: local $_ = $thing; > 1614: local $_ = $value; > > lib/Test/Builder/Tester.pm > 260: local $_; > 340: local $_; > > t/test.pl > 168:# Trying to avoid setting $_, or relying on local $_ to work. > > You ought to be using for($thing) instead. If you need to set it to a > new variable that you can > then subsequently modify, use for(my $dummy) { ... } or local *_ = \my > $dummy;
This bug was files against a dead branch of Test-Simple. no longer applicable.