Re: coerce a sub-subtype
[email protected] (Chris Weyl) Mon, 16 Jun 2014 12:25:32 -0700
| Newsgroups | perl.moose |
|---|---|
| Message-ID | <CABSyATFmv3b3HVCBOUE6oMgUn=xGOtKYzjoouP7J5JrM_1Piaw@mail.gmail.com> |
On Mon, Jun 16, 2014 at 11:41 AM, John Macdonald <[email protected]> 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