Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

rebuilding lazy Moose attributes

by jabowery (Beadle)
on Aug 20, 2013 at 18:10 UTC ( #1050219=perlquestion: print w/ replies, xml ) Need Help??
jabowery has asked for the wisdom of the Perl Monks concerning the following question:

A solution offered to the problem of change propagation in lazy Moose attributes was to use lazy_build => 1 in the lazy attribute and then, in the attributes referenced by the builder:

has 'attr1' => ( ... trigger => \&clear_attr2, );
However, this requires maintaining back-references in the source code that could have been created along with the memoized value at build time. Is there a MooseX that does this automatically?

Comment on rebuilding lazy Moose attributes
Select or Download Code
Replies are listed 'Best First'.
Re: rebuilding lazy Moose attributes
by tobyink (Abbot) on Aug 20, 2013 at 21:48 UTC

    I tend to use 'ro' attributes as much as possible and thus avoid things like this.

    I have a module Trait::Attribute::Derived that offers a bunch of sugar for deriving one attribute from another, but it doesn't offer this feature. Perhaps it should?

    package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1050219]
Approved by Jim
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (8)
As of 2015-07-30 09:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (270 votes), past polls