Re: Superclass method modifiers don't run when attribute is extended/modified

[email protected] (Bernardo Rechea)
Newsgroups perl.moose
Message-ID <[email protected]>
Stevan Little wrote:

>> Hmm, perhaps it would be a start for a WTF entry?
> 
> Sure, patches welcome, or stop by #moose for a commit bit.

I'm attaching a patch. This is my first patch, done with 'diff -u', which I
hope is good enough. But if there is something wrong, please bear with me
and tell me what else would be appropriate.

Bernardo
WTF.pod.patch (text/x-diff, 1.6 KB)
--- /home/brb/localperl/lib/site_perl/5.10.0/Moose/Cookbook/WTF.pod	2007-12-31 11:46:06.000000000 -0500
+++ WTF.pod	2008-05-19 13:28:20.000000000 -0400
@@ -109,6 +109,26 @@
       return reverse @rv;
   };
 
+=head3 Why do the accessor modifiers of a superclass' attribute stop working after redefining or extending the attribute in a subclass?
+
+When an attribute is redefined or extended in a subclass, a completely new
+attribute accessor is created that overrides the original one. This happens
+through two mechanisms: if an attribute is redefined (with C<has 'some_attribute'>),
+everything related to the attribute (accessor methods, etc.)
+is generated anew for the subclass; if an attribute is extended (with
+C<has '+some_attribute'>), the corresponding superclass' attribute is first cloned,
+and then the requested extensions or modifications are applied to the clone.
+
+Method modifiers are applied specifically to methods in the class in which they
+are originally defined, and are not re-applied for each subclass. It doesn't
+matter whether a method was written by the user explicitly or by an attribute
+automatically, and so it will do nothing special if it's applied to an accessor.
+
+When redefining or extending an attribute, the code refs of the new accessors are
+different from those of the superclass. The modifiers of the superclass apply to the
+superclass' code refs, and unless new modifiers are defined for the subclass, no
+modifiers are applied to the subclass' code refs.
+
 =head2 Moose and Attributes
 
 =head3 Why don't attributes I inherited from a superclass work?
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.