develooper Front page | perl.module-authors | Postings from November 2003

Re: Class::FakeAttributes -- Opinions Wanted

Thread Previous | Thread Next
From:
Fergal Daly
Date:
November 7, 2003 02:51
Subject:
Re: Class::FakeAttributes -- Opinions Wanted
Message ID:
20031107103725.GA32397@dyn.fergaldaly.com
On Fri, Nov 07, 2003 at 11:02:34AM +0100, A. Pagaltzis wrote:
> Even disregarding these differences, your code needs a lot of
> additions before it becomes useful in practice. The most glaring
> definiciency is that there's no provision for deleting an object
> instance's data from the hash on object destruction.

Absolutely, my code was presented in response to your complaint about having
to type refaddr all the time and that there was no easy way to do
::MethodMaker stuff with lexicals using inside out objects. That's all, I
wasn't planning on posting it on CPAN.

> It also lacks a provision for generating any kind of non-trivial
> accessors/mutators.

It lacks a whole lot more than that but there's no technical reason why it
couldn't do all the same stuff the others do.

That said, I've given up on automating non-trivial accessors/mutators. I
generally use my own very simple method maker which sets up an Attrs
package, stuffs a load of methods into it and pushes that package onto @ISA.
I never access the underlying data structure. So classes look like

package MyClass;

# this will create setColour, getColour, setSize and getSize in MyClass::Attrs
# and also do push(@ISA, "MyClass::Attrs");
use MM qw( Colour Size );

and if I want to do something fancy for a setter or getter I just override
like this

sub setSize
{
	my $self = shift;

	my $size = shift;

	die unless ($size > 0 and $size < 10);

	$self->SUPER::setSize($size);
}

It makes me happy.

> A real, general-case ::InsideOut will require a lot more work
> than that snippet.

A snippet was all it was ever meant to be,

F

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About