Object-InsideOut - Re: OIO and default value

Posted on Wed Dec 13 15:43:47 2006 by jdhedden in response to 3752 (See the whole thread of 13)
Re: OIO and default value
Defaults are specified in 3 places: The :InitArgs hash, the :Args attribute and the :Default attribute. They all need to work consistent with each other. Because :InitArgs are 'compiled', they can not be 'eval'ed at assignment time.
my %init_args :InitArgs = ( 'cref' => { 'field' => \@cref, 'default' => sub { return 'foo' }, }, );
In the above, because the default is a code ref, you cannot do a string eval on it.

Additionally, defaults are currently 'static' data. Implementing some sort of eval mechanism to get dynamic defaults would cause incompatibilities.

Therefore, you'll need to contend with preprocessing to do what you want. That's one of the reasons it was provided.
Write a response