From: Matt S Trout Date: Mon, 7 May 2012 17:58:28 +0000 (+0000) Subject: improve docs for isa and coerce X-Git-Tag: v0.091004~3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c4074652713f3c98b65636fc2f9d90e2d61c84b9;p=gitmo%2FMoo.git improve docs for isa and coerce --- diff --git a/Changes b/Changes index bab87c3..8e4ca17 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,4 @@ + - clarify how isa and coerce interact - support isa and coerce together for Moose - guard _accessor_maker_for calls in Moo::Role in case Moo isn't loaded - reset handlemoose state on mutation in case somebody reified the diff --git a/lib/Moo.pm b/lib/Moo.pm index 3f099c2..90469ab 100644 --- a/lib/Moo.pm +++ b/lib/Moo.pm @@ -371,6 +371,12 @@ one should do L +Since L does B run the C check before C if a coercion +subroutine has been supplied, C checks are not structural to your code +and can, if desired, be omitted on non-debug builds (although if this results +in an uncaught bug causing your program to break, the L authors guarantee +nothing except that you get to keep both halves). + If you want L style named types, look at L. @@ -396,9 +402,10 @@ do something like the following: $_[0] + 1 unless $_[0] % 2 }, -Coerce does not require C to be defined, but since L does -require it, the metaclass inflation for coerce-alone is a trifle insane -and if you attempt to subtype the result will almost certainly break. +Note that L will always fire your coercion - this is to permit +isa entries to be used purely for bug trapping, whereas coercions are +always structural to your code. We do, however, apply any supplied C +check after the coercion has run to ensure that it returned a valid value. L @@ -587,9 +594,13 @@ C 'lazy'> option supported by L and L. C is not supported since the author considers it a bad idea. C will show up in a L metaclass created from your class -but is otherwise ignored. Then again, L ignors it as well, so this +but is otherwise ignored. Then again, L ignores it as well, so this is arguably not an incompatibility. +Since C does not require C to be defined but L does +require it, the metaclass inflation for coerce-alone is a trifle insane +and if you attempt to subtype the result will almost certainly break. + Handling of warnings: when you C we enable FATAL warnings. The nearest similar invocation for L would be: