Skip Menu |
 

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

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

People
Owner: LEONT [...] cpan.org
Requestors: garu [...] cpan.org
Cc:
AdminCc:

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



Subject: document (or fix?) CAVEAT: hash autovivification
Download (untitled) / with headers
text/plain 947b
Hi there! I found something of a caveat while using Const::Fast. Hash autovivification in Perl creates keys when testing definedness. So if you have a constant hash you will *not* be able to check if a value is defined unless you make sure it exists first. Otherwise you'll get this: $ perl -MConst::Fast -Mstrict -Mwarnings -E 'const my %a => (foo => 1, bar => 2); say 1 unless $a{baz}' Attempt to access disallowed key 'baz' in a restricted hash at -e line 1. Unless there's a way to suppress this warning with Const::Fast, those checks on constant hashes should probably use 'exists' instead: $ perl -MConst::Fast -Mstrict -Mwarnings -E 'const my %a => (foo => 1, bar => 2); say 1 unless exists $a{baz}' 1 If it's not possible (or not desired) to remove that message, I really think the 'defined x exists' issue in constant hashes should be mentioned under the CAVEATS section of the documentation. Thanks for such a nice module, btw :)
Download (untitled) / with headers
text/plain 686b
On Sun Oct 17 17:53:09 2010, GARU wrote: Show quoted text
> Hi there! > > I found something of a caveat while using Const::Fast. Hash > autovivification in Perl creates keys when testing definedness. So if > you have a constant hash you will *not* be able to check if a value is > defined unless you make sure it exists first. Otherwise you'll get this:
Hi Breno, Thanks for your bug report. This is an issue in the perl core, it does not make a distinction between restricted and readonly hashes. It can not be solved in my module, so a note in the documentation would indeed be a good idea. I might try to send p5p a patch on this if it's feasible, but I haven't taken a deep look at it yet. 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.