Re: Class::Accessor subclass

2003-12-10 Thread Clayton Scott
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




Re: Class::Accessor subclass

2003-12-10 Thread Simon Cozens
Richard Clamp:
 On Tue, Dec 09, 2003 at 06:32:01PM +, Simon Cozens wrote:
  So, uh, what would be a good name for it, then? Class::Accessor::Assert?
 
 Just ::Assert seems a little wide-ranging for what you have just now.

Well, I also want to be asserting that some members exist in the hash that's
been passed to new, for instance.

-- 
``Perl is the successfull attempt to make a braindump directly
executable.''
- Lutz Donnerhacke in de.org.ccc