|
And just to make sure I answered your question, using:
my @attr :Field :Default(sub { print "this is a code ref" });
will assign a code ref as a default. However, your other example:
my @attr :Field :Default(my::defined::object->new());
will result in a single 'my::defined::object' object being generated, and then that same object being assigned every time a default is needed. The same would occur with an :InitArgs hash:
my %init_args :InitArgs = (
'attr' => {
'field' => \@attr,
'default' => my::defined::object->new(),
},
);
Now, if the 'single object reassigned for each default' is what you want, then I apologize for not understanding your question in the first case. However, if you want a different object generated by the code 'my::defined::object->new()' each time a default is needed, then you'll need to do preprocessing for that.
I hope I've answered everything for you. Sorry if I caused any confusion. |