I notice while looking around CPAN that there are about 6 million
Variations On A Theme By Bach^W^Wof Class::Accessor. Does anyone have
anything of note to say on any of them?

The reason I ask is that I have some code I'm trying to migrate away from
using lots of custom "home-built" dependencies and into some more
standard ones. We have some classes that define their fields by a hash,
such as:

 our %keys = (
    name => '$',
    path => '$',
    mappings => '%$',
 );

Where I hope the meaning is obvious. Within the accessor functions, all
the set methods (which I call "mutators", generally reserving the word
"accessor" to mean a get function) check the type passed in. So set_name
and set_path want a plain non-reference scalar, and set_mappings wants a
HASH reference.

I'd much prefer to use something standard and CPANised to do this with,
but it doesn't seem like anyone's really doing this sort of thing.
Ideally I might like it extended a bit, on the hypothetical idea of:

 our %keys = (
    name => { type => "$", regex => qr{^\w+$} },
    path => { type => "$", regex => qr{^[^ ]+$} },
    mappings => {
      type => '%$', key_regex => ....
    },
 );

To put more type checking in.. Maybe even find some way that an indexed
accessor of "mapping" could be defined, equivalent to

 sub set_mapping
 {
   my $self = shift;
   my ( $key, $newvalue ) = @_;

   # some code to check $key and $newvalue and throw a wobbly if
   # not of the right form

   $self->{mappings}->{$key} = $newvalue;
 }


Before I start writing any code in this direction - are there any
thoughts on this?

-- 
Paul "LeoNerd" Evans

[EMAIL PROTECTED]
ICQ# 4135350       |  Registered Linux# 179460
http://www.leonerd.org.uk/

Reply via email to