Skip Menu |

This queue is for tickets about the Moo CPAN distribution.

Report information
The Basics
Id: 90592
Status: resolved
Priority: 0/
Queue: Moo

People
Owner: Nobody in particular
Requestors: stevan.little [...] gmail.com
Cc:
AdminCc:

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



Subject: Unnecessary restriction on attribute names when using defaults
Consider the following perfectly valid and usable code: package Foo; use Moo; has '@bar' => ( is => 'ro', reader => 'get_bar', default => sub { [] } ); Foo->new; which reports the following error: Eval went very, very wrong: { my $default_for_@bar = ${$_[1]->{"\$default_for_\@bar"}}; # …. } Array found where operator expected at (eval 14) line 2, at end of line This works just fine with Moose: package Foo; use Moose; has '@bar' => ( is => 'ro', reader => 'get_bar', default => sub { [] } ); Foo->meta->make_immutable; Foo->new; You might want to consider removing this unnecessary restriction on attribute names by simply storing your default cache in a hash ref instead of making lexical variables. Just saying' - Stevan
I have a fix in the attr-name-clean branch. Going to wait a bit before merging in case I think of a better solution.
This is fixed in the git repo.
Resolved in 1.004000.