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