Skip Menu |

This queue is for tickets about the Const-Fast CPAN distribution.

Report information
The Basics
Id: 84205
Status: resolved
Priority: 0/
Queue: Const-Fast

People
Owner: Nobody in particular
Requestors: victor.adam [...] derpymail.org
Cc:
AdminCc:

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



Subject: Can't create a constant array of CODE refs
Date: Mon, 25 Mar 2013 21:58:22 +0100
To: bug-const-fast [...] rt.cpan.org
From: Victor ADAM <victor.adam [...] derpymail.org>
I'm honestly surprised this went unnoticed for so long. Any attempt to create a read-only array or hash containing code references fails loudly: perl -MConst::Fast -e 'const @a => sub{}' Can't store CODE items at /home/grimy/perl/lib/site_perl/5.16.2/Const/Fast.pm line 28. It turns out CODE refs can't (and don't need to) be cloned, so the fix is to simpl add <code>&& reftype $_[0] ne 'CODE'</code> to the $needs_cloning check. Contextual diff below. --- Fast.pm 2012-09-07 23:50:33.000000000 +0200 +++ Fast.new 2013-03-25 21:41:42.960761305 +0100 @@ -24,7 +24,7 @@ sub _make_readonly { my (undef, $dont_clone) = @_; if (my $reftype = reftype $_[0] and not blessed($_[0]) and not &Internals::SvREADONLY($_[0])) { - my $needs_cloning = !$dont_clone && &Internals::SvREFCNT($_[0]) > 1; + my $needs_cloning = !$dont_clone && &Internals::SvREFCNT($_[0]) > 1 && reftype $_[0] ne 'CODE'; $_[0] = _dclone($_[0]) if $needs_cloning; &Internals::SvREADONLY($_[0], 1); if ($reftype eq 'SCALAR' || $reftype eq 'REF') {
On Mon Mar 25 16:58:36 2013, victor.adam@derpymail.org wrote: Show quoted text
> I'm honestly surprised this went unnoticed for so long. Any attempt to > create a read-only array or hash containing code references fails loudly: > > perl -MConst::Fast -e 'const @a => sub{}' > Can't store CODE items at > /home/grimy/perl/lib/site_perl/5.16.2/Const/Fast.pm line 28. > > It turns out CODE refs can't (and don't need to) be cloned, so the fix is > to simpl add <code>&& reftype $_[0] ne 'CODE'</code> to the $needs_cloning > check. Contextual diff below. > > --- Fast.pm 2012-09-07 23:50:33.000000000 +0200 > +++ Fast.new 2013-03-25 21:41:42.960761305 +0100 > @@ -24,7 +24,7 @@ > sub _make_readonly { > my (undef, $dont_clone) = @_; > if (my $reftype = reftype $_[0] and not blessed($_[0]) and not > &Internals::SvREADONLY($_[0])) { > - my $needs_cloning = !$dont_clone && &Internals::SvREFCNT($_[0]) > 1; > + my $needs_cloning = !$dont_clone && &Internals::SvREFCNT($_[0]) > 1 > && reftype $_[0] ne 'CODE'; > $_[0] = _dclone($_[0]) if $needs_cloning; > &Internals::SvREADONLY($_[0], 1); > if ($reftype eq 'SCALAR' || $reftype eq 'REF') {
Sorry for the slow reply, this has been fixed in Const::Fast 0.014. Leon
From: kr2 [...] sanger.ac.uk
Hi, I may have misunderstood, but does this mean we should be able to include code refs under 0.014? The following doesn't work for me: use Const::Fast 0.014 qw(const); # requires Const::Fast 0.014 or greater const my %CONF_DISPATCH => ('db' => {'BWA' => \&_bwa_bam_db, 'PINDEL' => \&_pindel_bam_db, 'BRASS' => \&_brass_bam_db, }, 'track' => {'BWA' => \&_bwa_track_block, 'PINDEL' => \&_pindel_track_block, 'BRASS' => \&_brass_track_block, }, );