I would say that your declaration for 'x' is fine as is. It is your declaration for 'y' that needs to be lazy and have a builder because you can't depend upon 'x' to have been defined before 'y' is.
has 'y' => ( is => 'rw',
isa => 'str',
lazy => 1,
builder => '_build_y' );
sub _build_y {
my $self = shift;
return $self->{x}.'y' );
}
Update:
You should bear in mind that while this would okay for when the object is being constructed, you should also consider the case if 'x' can be changed later on. At that point 'y' would probably not hold what you want, so you should consider reading about predicates and clearers, as well as triggers.
The answer to the question "Can we do this?" is always an emphatic "Yes!" Just give me enough time and money.
|