On Thu, Apr 5, 2012 at 8:38 AM, Joseph Brenner <span dir="ltr"><<a href="mailto:doom@kzsu.stanford.edu" target="_blank">doom@kzsu.stanford.edu</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


I've been messing about with Mouse.pm of late (a lightweight Moose<br>
substitute whose star may already be fading), and I've got a basic<br>
question/complaint.<br>
<br>
I'm used to doing href based objects with an init routine that's<br>
called by new, where I can do any initialization I might need to do.<br>
In Moose land I find myself doing things like this:<br></blockquote><div><br></div><div>There's BUILD (and BUILDARGS) if you want to hook into construction. </div><div><br></div><div><a href="http://search.cpan.org/~doy/Moose-2.0403/lib/Moose/Manual/Construction.pod" target="_blank">http://search.cpan.org/~doy/Moose-2.0403/lib/Moose/Manual/Construction.pod</a></div>


<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
use Moose<br>
has name        =><br>
     (is => 'rw',  isa => 'Str', required => 1);<br>
has subject     =><br>
     (is => 'rw',  isa => 'Str', default => sub{ 'Report about .<br>
$_[0]->name }, lazy => 1);<br>
has id              =><br>
     (is => 'rw',  isa => 'Str', default => sub{  lookup( $_[0]->name<br>
) },          lazy => 1);<br>
<br>
Where the "lazy" setting delays the use of the initialization code to<br>
the time when the field is first accessed, and that way I can be<br>
certain that the name field has settled down.<br></blockquote><div><br></div><div>I'm wondering if you don't really want to be using a builder instead of a default.   I tend to make heavy use of builders (mostly using lazy_build => 1) as that makes the code, well, build itself.</div>


<div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
I find myself worrying about what I would do if I needed more than two<br>
stages, instantiation and lazy access.  Like what if I wanted to put<br>
the id in the subject?<br></blockquote><div><br></div><div>has id => ( lazy_build => 1, ... );</div><div>sub _build_id { return shift->name }</div><div><br></div><div>has subject => ( lazy_build => 1, ... )l</div>


<div>sub _build_subject { return 'Report about '  . shift->id }</div><div> </div></div><div><br></div>-- <br>Bill Moseley<br><a href="mailto:moseley@hank.org" target="_blank">moseley@hank.org</a><br>