G'day Hosen1989,
I suspect you may be mixing (and consequently, confusing) this type of Moose syntax:
has attribute => ( default => sub { 0 }, );
with normal Perl syntax for creating key-value pairs:
{ default => 0, }
sub { 0 } is a code reference.
For your simpler cases, like
description => sub{0}
you could just use
description => 0
However, regardless of the complexity of the code within sub { ... }, what you really want is the return value when that code is executed. For that, use
sub { ... }->()
Consider these three one-liners:
$ perl -wE 'my $x = { y => 0 }; say $x->{y}' 0
$ perl -wE 'my $x = { y => sub { 0 } }; say $x->{y}' CODE(0x7f8c34026a60)
$ perl -wE 'my $x = { y => sub { 0 }->() }; say $x->{y}' 0
-- Ken
In reply to Re: defined class variable with Moose
by kcott
in thread defined class variable with Moose
by Hosen1989
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |