in reply to Object design/structure with sub-objects (Moose)

Moose has lazy attributes that do what you want (if I understood your question correctly), see Moose::Manual::Attributes (search for "lazy").

But if performance is a big concern to you, you should evaluate if Moose doesn't slow you down too much. Hand-coding lazy attributes isn't all that difficult.

use 5.010; # for //=, but can be rewritten without it sub lazy_foo { $_[0]->{lazy_foo} //= $_[0]->construct_foo; }

Replies are listed 'Best First'.
Re^2: Object design/structure with sub-objects (Moose)
by Cagao (Monk) on Jun 06, 2011 at 12:31 UTC

    Cheers for the input.

    Yeah, the lazy-build approach was my first thought, and it would work easily without making things too complicated.

    I don't think Moose's implementation of lazy-build would be an issue, performance-wise, so would use their method rather than rolling my own.