Skip Menu |
 

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

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

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

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



Subject: Const::Fast won't make top-level references read-only
Download (untitled) / with headers
text/plain 1022b
_make_readonly() chases references, but the top level const() sub does not: $ perl -le 'use strict; use warnings; use Const::Fast; my $hashref = { "foo" => "bar", "baaz" => "quux" }; const($hashref => $hashref); ' Can't make variable readonly at -e line 1 $ perl -le 'use strict; use warnings; use Const::Fast; my $arrayref = [ 1, 2, 3, 4 ]; const($arrayref => $arrayref); ' Can't make variable readonly at -e line 1 ski@anito:~/mysrc/comma$ perl -le 'use strict; use warnings; use Const::Fast; my $val = 3; my $scalarref = \$val; const($scalarref => $scalarref);' Can't make variable readonly at -e line 1 $ perl -le 'use strict; use warnings; use Const::Fast; my $a = \{}; const($a => $a);' Can't make variable readonly at -e line 1 $ perl -le 'use strict; use warnings; use Const::Fast; my $a = bless( \ {}, "FOO" );const($a => $a);' Can't make variable readonly at -e line 1 ... etc. seems to me like this is a bug, or at least something that should be documented / overridable with an option to const().
Download (untitled) / with headers
text/plain 1.4k
I now see this is because we are not using the preferred idiom: const my $a = {}; # or whatever The problem with this idiom is it doesn't support locking a variable after performing some basic operations on it, for example: my %foo; $foo{...} = ... for (...); const(%foo); Any thoughts on supporting such usage? Thanks, Brian Szymanski On Fri Feb 24 10:40:40 2012, BRIANSKI wrote: Show quoted text
> _make_readonly() chases references, but the top level const() sub does > not: > > $ perl -le 'use strict; use warnings; use Const::Fast; my $hashref = { > "foo" => "bar", "baaz" => "quux" }; const($hashref => $hashref); ' > Can't make variable readonly at -e line 1 > > $ perl -le 'use strict; use warnings; use Const::Fast; my $arrayref =
[ Show quoted text
> 1, 2, 3, 4 ]; const($arrayref => $arrayref); ' > Can't make variable readonly at -e line 1 > > ski@anito:~/mysrc/comma$ perl -le 'use strict; use warnings; use > Const::Fast; my $val = 3; my $scalarref = \$val; const($scalarref => > $scalarref);' > Can't make variable readonly at -e line 1 > > $ perl -le 'use strict; use warnings; use Const::Fast; my $a = \{}; > const($a => $a);' > Can't make variable readonly at -e line 1 > > $ perl -le 'use strict; use warnings; use Const::Fast; my $a = bless(
\ Show quoted text
> {}, "FOO" );const($a => $a);' > Can't make variable readonly at -e line 1 > > ... etc. seems to me like this is a bug, or at least something that > should be documented / overridable with an option to const().
Download (untitled) / with headers
text/plain 1.1k
On Fri Feb 24 10:40:40 2012, BRIANSKI wrote: Show quoted text
> _make_readonly() chases references, but the top level const() sub does > not: > > $ perl -le 'use strict; use warnings; use Const::Fast; my $hashref = { > "foo" => "bar", "baaz" => "quux" }; const($hashref => $hashref); ' > Can't make variable readonly at -e line 1 > > $ perl -le 'use strict; use warnings; use Const::Fast; my $arrayref = [ > 1, 2, 3, 4 ]; const($arrayref => $arrayref); ' > Can't make variable readonly at -e line 1 > > ski@anito:~/mysrc/comma$ perl -le 'use strict; use warnings; use > Const::Fast; my $val = 3; my $scalarref = \$val; const($scalarref => > $scalarref);' > Can't make variable readonly at -e line 1 > > $ perl -le 'use strict; use warnings; use Const::Fast; my $a = \{}; > const($a => $a);' > Can't make variable readonly at -e line 1 > > $ perl -le 'use strict; use warnings; use Const::Fast; my $a = bless( \ > {}, "FOO" );const($a => $a);' > Can't make variable readonly at -e line 1 > > ... etc. seems to me like this is a bug, or at least something that > should be documented / overridable with an option to const().
Yes, this is a bug, thanks for the report. It has been fixed in Const::Fast 0.011. Leon


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.