Hi Dave,

'after' is called after a method call.

If you want a block of code to be called every time you set an attribute, you 
want to use a trigger:

has 'foo' => (
        is => 'rw',
        trigger => sub {
                # will be called when setting the attribute via 'new' or via 
the writer method
                my ( $self, $newval, $oldval ) = @_;
                ...
        }
);

- Jeff

-----Original Message-----
From: Dave Howorth [mailto:dhowo...@mrc-lmb.cam.ac.uk] 
Sent: Friday, October 05, 2012 10:24 AM
To: moose@perl.org
Subject: attribute initialisation and after

I wrote a Moose class and the class 'has' an attribute. The attribute also has 
an 'after' modifier.

But when I create an object of the class and supply an initial value for the 
attribute to the 'new' method, it appears that the 'after' modifier is not 
called. It is called if I later access the attribute.

My expectation is that initialisation of an attribute would invoke the 
attribute's setter and the modifier, so reality doesn't match my expectation - 
is there something that explains why reality is as it is so I can adjust my 
expectation?

Cheers, Dave

Reply via email to