[sf-perl] the mouse with antlers
Joseph Brenner
doom at kzsu.stanford.edu
Wed Apr 4 17:38:53 PDT 2012
I've been messing about with Mouse.pm of late (a lightweight Moose
substitute whose star may already be fading), and I've got a basic
question/complaint.
I'm used to doing href based objects with an init routine that's
called by new, where I can do any initialization I might need to do.
In Moose land I find myself doing things like this:
use Moose
has name =>
(is => 'rw', isa => 'Str', required => 1);
has subject =>
(is => 'rw', isa => 'Str', default => sub{ 'Report about .
$_[0]->name }, lazy => 1);
has id =>
(is => 'rw', isa => 'Str', default => sub{ lookup( $_[0]->name
) }, lazy => 1);
Where the "lazy" setting delays the use of the initialization code to
the time when the field is first accessed, and that way I can be
certain that the name field has settled down.
I find myself worrying about what I would do if I needed more than two
stages, instantiation and lazy access. Like what if I wanted to put
the id in the subject?
I'd have to do a gratuitous access of id to make sure it was defined
before accessing subject...
More information about the SanFrancisco-pm
mailing list