in reply to Beware can for attrs
in thread (my?) problem with re-blessed references(?)
You're right and I thought about this a bit. If every package and ISA package has a %HAS (or HASA) hash containing valid attributes as keys, and defines a 'has' method, then its fairly simple to validate attributes in any package (and the attribute accessor/mutator methods could even be AUTOLOAD'ed if desired). The 'has' method would go something like this (untested):
I'm not yet saying that this is a good idea, just throwing it out there for comments/opinions/better options.sub has { my ($self, $attr) = @_; return 1 if exists $HAS{$attr}; return 1 if ${_}::has($self, $attr) for @ISA; return; } # Then in initialization or in AUTOLOAD... ... if ($self->has($attr)) { ...#set attr }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Beware can for attrs
by adrianh (Chancellor) on Dec 14, 2002 at 19:11 UTC |