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

Gaal Yahas gaal at forum2.org
Sun Feb 29 04:58:47 PST 2004


[This is a reply to Yosef and Yuval both.]

On Sun, Feb 29, 2004 at 01:12:24AM +0200, Yuval Kogman wrote:
> On Sat, Feb 28, 2004 at 22:52:23 +0200, Yosef Meller wrote:

I didn't know inside-out objects before YAPC, and was very happy
to hear about them!

Although guarding against typos was the main thrust for using
them, accesors give you a few more benefits (this was the part
I had to rush through a bit). Most notably, set accessors provide
the most most obvious place for constraining and checking values.

You get a chance to do that with Class::Accessor, and if you want
more elaborate checks you can check out C::A::Assert.

C::A::Chained, C::A::Lvalue and C::A::Ref provide syntactic sugar for
all sorts of places where you might use accessors in real life.  I only
had pressing need for the last of the three -- that's why I wrote it :)

The main problem with the C::A suite of modules is that they don't
interact, that is, you can't curently (say) get both refaccessor and
lvalue semantics. This bothers me, and looks like some unfortunate
OOP design limitation.

Yuval writes:

> 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.

I didn't think so, because the hash keys, being stringified, are not
hard references any more, so you do get DESTROY called at the right
time and since you know the fields you can also delete the elements.
But while making sure by looking at the definition of this hack on the
web, I found this:

http://perlmonks.thepen.com/220776.html

So I'd have said "go for it", but instead have to say "it's been done". :/

-- 
Gaal Yahas <gaal at forum2.org>
http://gaal.livejournal.com/



More information about the Perl mailing list