Subject: | Cannot default to variable |
$ cat Foo.pm
package Foo;
use Moose;
use MooseX::Method::Signatures;
our $DEFAULT;
BEGIN{ $DEFAULT = 'baz' }
has something => ( is => 'rw', isa => 'Str',
lazy => 1, builder => '_make_something' );
method _make_something ( Str $value = $DEFAULT ) {
return $value;
}
1;
$ cat foo
#!/usr/local/bin/perl
use strict;
use warnings;
use 5.10.0;
use Foo;
my $foo = Foo->new;
say $foo->something;
$ ./foo
Validation failed for 'Tuple[Tuple[Object,Str],Dict[]]' with value [ [ Foo=HASH(0x8db0260),
undef ], { } ], Internal Validation Error is:
[+] Validation failed for 'Tuple[Object,Str]' with value [ Foo{ }, undef ]
[+] Validation failed for 'Str' with value undef at
/usr/local/lib/perl5/site_perl/5.11.4/MooseX/Method/Signatures/Meta/Method.pm line 435
MooseX::Method::Signatures::Meta::Method::validate('MooseX::Method::Signatures::Meta::Met
hod=HASH(0x996fc48)', 'ARRAY(0x99713a0)') called at
/usr/local/lib/perl5/site_perl/5.11.4/MooseX/Method/Signatures/Meta/Method.pm line 151
Foo::_make_something('Foo=HASH(0x8db0260)') called at accessor Foo::something
(defined at Foo.pm line 10) line 10
Foo::something('Foo=HASH(0x8db0260)') called at ./foo line 10
However, it succeeds as soon as the default is changed to a literal.