[Israel.pm] Followup on Gaal's talk on Class::Accessor - inside out classes.

Yuval Kogman lists at woobling.org
Sat Feb 28 15:12:24 PST 2004


On Sat, Feb 28, 2004 at 22:52:23 +0200, Yosef Meller wrote:

> In the lecture it was mentioned that using hash keys as an object's
> attributes makes it possible for a typo to go unnoticed and a very big
> bug to be hard to detect, which is true. The solution sugested was to
> use accessors even within your object to avoid the typos.

I forgot to say that the point of this is not only keeping from typos,
but also maintaining inheritence - if a subclass redefines an accessor,
and uses something else to represent the data, possibly with added
functionality, this will cause inconsistencies.

> There's a technique called inside out objects, in which an attribute,
> rather than being a key in a hash, is a hash in itself keyed by object
> references. Like so:

The though just occurred to me, why not make Class::Accessor::InsideOut?

sub make_accessor {
	my $class = shift;
	
	my %field;
	return sub { @_ ? $field{$_[0]} = $_[1] : $field{$_[0]}	}
}

Cleanup will be difficult though.

-- 
 ()  Yuval Kogman <nothingmuch at woobling.org> 0xEBD27418  perl hacker &
 /\  kung foo master: /me sneaks up from another MIME part: neeyah!!!!!




More information about the Perl mailing list