> [inherited attributes]
> [get/set accessor methods]
> [regex validation of set]
> [better way?]

I'm not sure about there being a *better* way,
but I'm sure there are a lot of *other* ways.

Various thoughts...

Perl has the concept of tied data items. The basic
operations on those data items, like setting the
value, are done via arbitrary procedures you write.
I can see one implementing what you describe, as
a tied hash. To see a little more of what people
have done with tie's in general:
http://search.cpan.org/search?mode=module&query=tie

Of course, there may be other tied hash implementations
not on cpan.

If you don't have Damian Conway's book, get it.

You might be interested in considering how CLOS
(common lisp object system) notions relate to what
you are doing. With CLOS, firing a method (which
could be an Accessor method), meant the method
dispatcher first looked to see if any Before methods
matched the argument signature. If so, it fired the
matching Before method(s). Those Before methods
could then modify the dispatch process, eg abort the
dispatch. At least, this is how it worked when I last
looked at CLOS, about 10 years ago.

This is a very general framework with what you are
doing being one of many things that are naturally
expressed using it. You could have a Before method
that validates the argument to an Accessor method 
against a regex, and accepts/aborts the dispatch. 
But to get this to work with Perl, you'd have to play
with the guts of method dispatch, something I would
guess is a relatively non-trivial undertaking.

Reply via email to