Subject: | Private methods cannot be used as builders for attributes |
Date: | Tue, 9 Aug 2016 17:54:34 +0200 |
To: | bug-MooseX-Privacy [...] rt.cpan.org |
From: | Felix Kuehnl <felix [...] bioinf.uni-leipzig.de> |
The current version v0.05 of MooseX::Privacy does not allow private
methods to be used as builders for attributes. As an example, consider
the following code:
use warnings;
use v5.12;
package Felix::Private {
use Moose;
use MooseX::Privacy;
has 'name' => (
is => 'ro',
isa => 'Str',
builder => 'get_horst',
traits => ['Private'],
);
sub greet {
my $self = shift;
say 'Hi, my name is ' . $self->name;
}
private_method 'get_horst' => sub {
return 'Horst';
};
}
use Felix::Private;
my $private = Felix::Private->new(); # Dies
# my $private = Felix::Private->new(name => 'Klaus'); # Works fine
$private->greet();
Experienced behavior: The code dies with error "The
Felix::Private::get_horst method is private at [...] line 27.".
Expected behavior: Since the builder is called from within the class, it
should be possible to execute the method. The code should print "Hi, my
name is Horst".
Felix