Simon Cozens wrote:
I'm about to write a Class::Accessor subclass that allows validity checking
on the accessors it generates. For instance, you will be able to say
__PACKAGE__-mk_accessor(headers = Some::Header::Object);
and then this becomes a runtime error:
Foo-new({ headers = Completely::Different::Class-new() })
Really I want it just to make sure that certain things are defined when
the constructor is called, but additional assertions would be handy too.
So, uh, what would be a good name for it, then? Class::Accessor::Assert?
That sounds like an interesting sub class and a good name. I was
thinking of doing something similar but also adding a way to specify
additional behaviours.
For example if I specify a field is an array, $foo-get($field) will
return a list if wantarray is true and an additional method called
${field}_add will be created to allow to to push additional values into
the field.
In Class::Struct the syntax to specify an array like field is:
struct( foo = '@')
I was thinking about:
__PACKAGE__-mk_accessor( qw( +name @labels [EMAIL PROTECTED] ) );
Where + indicates a required field and @ indicates the list behaviour.
Clayton