On Tue, 10 Nov 2009, Nathan Gass wrote:

They are mainly useful for overwriting. My current code for
MooseX::Attribute::Delegated at
http://github.com/xabbu42/MooseX-Attribute-Delegated
has to use a custom Method::Accessor and a custom Method::Constructor with two
mostly copy-pasted methods (see http://github.com/xabbu42/MooseX-Attribute-
Delegated/blob/master/lib/MooseX/Attribute/Delegated.pm)

Not to get too off-topic, but what is the point of what you're doing?

If you want to extract a bunch of attributes from a hashref passed to the constructor as one of its arguments, there are lots of simpler ways to do this.

Notably, a parameterized role that added a method modifier on BUILD would probably be a _much_ simpler solution. You could also just use a lazy builder.

as I see it, Method::Constructor defines the behavior of a constructor and
should not presuppose the way a specific attribute gets stored in the object.
How an attribute gets stored should instead be decided by the attribute meta-
object. Same story for Method::Accessor. I'll try to find an example on CPAN
for this point.

The Constructor doesn't assume anything about how attributes are stored, it asks the meta-instance to handle this detail. This is all really confusing without adding yet another layer of indirection.

My changes streamline some inconsistencies in the current code too. The
current code uses sometimes $attr->name and sometimes $attr->slots to decide
on the slot name. Overwriting the slots method of Meta::Attribute therefore
currently gives you a buggy attribute, since some code incorrectly still uses
the name of the attribute as slot name. This bug can of course be fixed without
my changes. The point is that bugs like this are easier avoided if all code
concerning inline attribute storage is concentrated in one place.

I'd like to see that bug fixed too.

However, attribute storage is already in one place, the meta instance.


-dave

/*============================================================
http://VegGuide.org               http://blog.urth.org
Your guide to all that's veg      House Absolute(ly Pointless)
============================================================*/

Reply via email to