Joel Bernstein wrote:
On 1 May 2009, at 16:07, Alex Povolotsky wrote:
Hello!
I'm writing a webmail system, and I have to make a class accessing
EMail message. It can be multipart, so bodypart must be an array; it
should be lazy, to prevent fetching of data we're not going to display.
Unfortunately, manual for MooseX::AttributeHelpers is rather sparse.
Maybe someone can provide me with an example of lazy array attribute
with Moose?
sub _build_bodyparts {
my $self = shift;
my $bodyparts = [];
# ... fetch your bodyparts and stuff them into the arrayref
return $bodyparts;
}
Okay, I need to clarify. Can I build bodyparts as they are requested,
not all at once? For instance, one of parts could be a huge attach file,
I do not need to fetch it from server each time user reads a text.
If I do not need AttributeHelpers, how should I write the thing?
Of course, I can plainly write down all functions - but I'd prefer to
use existing framework as much as possible.
Alex.
P.S. Thanks a lot
Alex.