Skip Menu |

This queue is for tickets about the URI CPAN distribution.

Report information
The Basics
Id: 68179
Status: open
Priority: 0/
Queue: URI

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

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



Subject: weird URI/URI::Escape behavior with Readonly
This is weird. If I change this to assign the vars of the 'for' loop to a loop var instead of $_, it works as expected. However, I'm not passing $_ to the UserAgent at all, the call to get() uses a new string. Why would something in URI try to operate on and modify $_ at the scope of the caller's loop? This is perl 5.8.8 in CentOS. Thanks have a nice day. --mark-- #!/usr/bin/perl use strict; use warnings FATAL => 'all'; use English '-no_match_vars'; use YAML; use Readonly; use LWP; Readonly my @lame => qw( www.google.com www.yahoo.com ); my $ua = LWP::UserAgent->new(); for (@lame) { my $response = $ua->get("http://$_"); print Dump($response->headers); } __END__ hedges@foo:~$ ~/lame.pl Modification of a read-only value attempted at /usr/lib/perl5/site_perl/5.8.8/URI/_server.pm line 6 Compilation failed in require at /usr/lib/perl5/site_perl/5.8.8/URI/http.pm line 3. Compilation failed in require at (eval 15) line 3. Callback called exit. END failed--call queue aborted at /home/digicine/hedges/lame.pl line 6. In a more complex script it turned up as: Modification of a read-only value attempted at /usr/lib/perl5/site_perl/5.8.8/HTTP/Config.pm line 4 Compilation failed in require at /usr/lib/perl5/site_perl/5.8.8/LWP/UserAgent.pm line 746. Callback called exit.
This is certainly weird. With perl-5.14 this problem no longer exists. The perl5140delta says: local($_) strips all magic from $_ local() on scalar variables gives them a new value but keeps all their magic intact. This has proven problematic for the default scalar variable $_, where perlsub recommends that any subroutine that assigns to $_ should first localize it. This would throw an exception if $_ is aliased to a read‐only variable, and could in general have various unintentional side‐effects. Therefore, as an exception to the general rule, local($_) will not only assign a new value to $_, but also remove all existing magic from it as well. which might be this issue.