develooper Front page | perl.moose | Postings from June 2014

Re: coerce a sub-subtype

Thread Previous | Thread Next
From:
Chris Weyl
Date:
June 16, 2014 19:25
Subject:
Re: coerce a sub-subtype
Message ID:
CABSyATFmv3b3HVCBOUE6oMgUn=xGOtKYzjoouP7J5JrM_1Piaw@mail.gmail.com
On Mon, Jun 16, 2014 at 11:41 AM, John Macdonald <John.Macdonald@oicr.on.ca>
wrote:

> without the coerce, it does not do the conversion and only allows input
> that has the explicit leading 'chr', but with the coerce parameter it gives
> a compile time error complaining that the type needs to have a coercion.
>

By design, coercions are not inherited.  (Not making a value assessment
here, just confirming your (inadvertent) research :))

 Am I going to have to write the duplicate coercion code for every one of
> the 'real' sub-types that want to also have this optional prefix behaviour,
> or is there an alternate way to write this?
>

tl;dr: yes :)

Alternatively, it's possible to do a little type metaclass fiddling to find
the parent type's coercions and pull those into the child's set.  This is
what we do in MooseX::AttributeShortcuts, for instance, when using the
one-off subtyping behaviour.

~Chris

-- 
Chris Weyl
Ex astris scientia

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