Skip Menu |

This queue is for tickets about the Variable-Magic CPAN distribution.

Report information
The Basics
Id: 90205
Status: resolved
Priority: 0/
Queue: Variable-Magic

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

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



Subject: copy magic on subs puts raw CV in $_[3]
% cat wtf.pl #!perl use strict; use warnings; use Variable::Magic qw(wizard cast); my $wizard; BEGIN { $wizard = wizard copy => sub { print "\$_[3] is $_[3]\n"; print "\\\$_[3] is " . \$_[3] . "\n"; print "\\&{\$_[3]} is " . \&{$_[3]} . "\n"; }, ; } sub MODIFY_CODE_ATTRIBUTES { my ($pkg, $sub) = @_; cast &$sub, $wizard; return; } my $i; my $f = sub : Hello { $i }; __END__ % perl wtf.pl Use of uninitialized value $_[3] in concatenation (.) or string at wtf.pl line 10. $_[3] is \$_[3] is CODE(0x86320d8) \&{$_[3]} is CODE(0x86320d8) The documentation for copy says: "This magic only applies to tied arrays and hashes, and fires when you try to access or change their elements." This is clearly not the whole story because it also fires for subs ... which is a good thing because I need this functionality. But $_[3] seems to contain a raw CV, which I'm pretty sure isn't supposed to happen (hence it appearing as undef to Perl code). Instead I would've expected $_[3] to be a reference to a CV. (\&{$_[3]} seems to be good workaround because it's compatible with both.)
On Sun Nov 10 12:19:27 2013, MAUKE wrote: Show quoted text
> This is clearly not the whole story because it also fires for subs ... > which is a good thing because I need this functionality.
Unfortunately, you will find it only works in 5.18 onwards. See commit v5.16.0-32-g09fb282.
Thanks for your report. Since version 0.54, $_[3] is a code reference whenever the current magical object is a code reference. Vincent