* Sean Allen <[email protected]> [2009-01-23T16:20:51]
> I'm reading the docs for initializer and am totally lost as to what it
> does, can someone explain?
>
> I keep reading the words but put together, just not getting it.
Say you have an attribute like this:
has attr => (
is => 'rw',
required => 1,
default => 10,
trigger => sub { ... },
);
When the attribute is changed, the trigger is called. That does not happen,
though, when the object is created, even though the attribute is set then --
from "no attribute exists because the object is not initialized" to 10.
To have code run when the attribute is *initialized* (set during instance
initialization) you make an initialized.
The test code in Class-MOP might be demonstrative:
http://cpansearch.perl.org/src/DROLSKY/Class-MOP-0.76/t/024_attribute_initializer.t
--
rjbs