From: Mark A. Stratman Date: Fri, 11 Mar 2011 19:31:17 +0000 (-0600) Subject: Add FAQ on requires and attribute-generated methods X-Git-Tag: 2.0103~18 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=be2630cf594037801e0b1063043cbf8fce6da7f4;p=gitmo%2FMoose.git Add FAQ on requires and attribute-generated methods --- diff --git a/lib/Moose/Manual/FAQ.pod b/lib/Moose/Manual/FAQ.pod index ec73df8..9ca7ff3 100644 --- a/lib/Moose/Manual/FAQ.pod +++ b/lib/Moose/Manual/FAQ.pod @@ -363,6 +363,26 @@ Outside the context of Moose, traits and roles generally mean exactly the same thing. The original paper called them traits, but Perl 6 will call them roles. +=head3 Can an attribute-generated method (e.g. an accessor) satisfy requires? + +Yes, just be sure to consume the role I declaring your +attribute. L provides +an example: + + package Breakable; + use Moose::Role; + requires 'stress'; + + package Car; + use Moose; + with 'Breakable'; + has 'stress' => ( is => 'rw', isa => 'Int' ); + +If you mistakenly consume the C role before declaring your +C attribute, you would see an error like this: + + 'Breakable' requires the method 'stress' to be implemented by 'Car' at... + =head2 Moose and Subroutine Attributes =head3 Why don't subroutine attributes I inherited from a superclass work?