Skip Menu |
 

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

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

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

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



Subject: How can it be used with eval and/or require?
Download (untitled) / with headers
text/plain 841b
This works as documented: my @a = (1,2); use Const::Fast; const(@a); The following two variations do not work as I would expect: perl -e ' my @a = (1,2); require Const::Fast; Const::Fast::const(@a); ' Usage: Internals::SvREADONLY(SCALAR[, ON]) at ... perl -e ' my @a = (1,2); eval "use Const::Fast"; const(@a); ' Usage: Internals::SvREADONLY(SCALAR[, ON]) at ... What gives? If this is expected, could you document how to use Const::Fast with eval/require? I was trying to make it optional in one of my programs and I couldn't make sense from the examples above. Thanks,
Download (untitled) / with headers
text/plain 1.1k
On Mon Nov 21 02:15:16 2011, ANDK wrote: Show quoted text
> This works as documented: > > my @a = (1,2); > use Const::Fast; > const(@a); > > The following two variations do not work as I would expect: > > perl -e ' > my @a = (1,2); > require Const::Fast; > Const::Fast::const(@a); > ' > Usage: Internals::SvREADONLY(SCALAR[, ON]) at ... > > perl -e ' > my @a = (1,2); > eval "use Const::Fast"; > const(@a); > ' > Usage: Internals::SvREADONLY(SCALAR[, ON]) at ... > > What gives? If this is expected, could you document how to use > Const::Fast with eval/require? I was trying to make it optional in one > of my programs and I couldn't make sense from the examples above.
const() has a prototype. In your 2nd and 3rd examples, the prototype has not yet been seen when Perl compiles the call to const(). Calling it as &const(\@foo) or predeclaring it with a prototype will solve the problem.
Download (untitled) / with headers
text/plain 371b
On Mon Nov 21 03:41:49 2011, SPROUT wrote: Show quoted text
> const() has a prototype. In your 2nd and 3rd examples, the prototype > has not yet been seen > when Perl compiles the call to const(). Calling it as &const(\@foo) > or predeclaring it with a > prototype will solve the problem.
Correct. I should probably add a clearer warning though, as the error is rather unhelpful. 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.