Skip Menu |
 

This queue is for tickets about the Scalar-Constant CPAN distribution.

Report information
The Basics
Id: 74485
Status: resolved
Priority: 0/
Queue: Scalar-Constant

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

Bug Information
Severity: Important
Broken in: 0.001003
Fixed in: 0.001004



Subject: Unexpected behaviour when defining a constant with a HASHREF or ARRAYREF value
Download (untitled) / with headers
text/plain 592b
If you try and declare a constant with an ARRAY ref value or HASH ref value, you get unexpected results. For example: use Scalar::Constant HASHREF => { a => 1, b => 2, c => 3 }; use Scalar::Constant ARRAYREF => [ 1, 2, 3 ]; It appears to have worked, until you then try and dereference the scalar. The error message you get is confusing, until you realise that because of how the module works, the hashref and arrayref got interpreted in a string context. Given how the module works, I think you should check ref() of the constant value, and croak if it's not a regular scalar value.
Download (untitled) / with headers
text/plain 723b
On Sat Jan 28 18:17:53 2012, NEILB wrote: Show quoted text
> If you try and declare a constant with an ARRAY ref value or HASH ref > value, > you get unexpected results. For example: > > use Scalar::Constant HASHREF => { a => 1, b => 2, c => 3 }; > use Scalar::Constant ARRAYREF => [ 1, 2, 3 ]; > > It appears to have worked, until you then try and dereference the > scalar. > The error message you get is confusing, until you realise that because > of how the module > works, the hashref and arrayref got interpreted in a string context. > > Given how the module works, I think you should check ref() of the > constant value, > and croak if it's not a regular scalar value.
But perhaps overloaded objects should still be allowed.
Download (untitled) / with headers
text/plain 181b
Only simple scalars are supported, not references. I've updated the doc to make this clear, and attempting to bind a reference will now croak. Thanks again for the feedback Neil!


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.