Re: forced coercion
[email protected] (Karen Etheridge) Thu, 21 Aug 2014 16:33:15 -0700
| Newsgroups | perl.moose |
|---|---|
| Message-ID | <20140821233315.GJ50072@tequila> |
On Thu, Aug 21, 2014 at 09:23:00PM +0000, John Macdonald wrote: > So, how do I specify a type that starts with a base type, but then applies a coercion? All the examples I see of coercions have a "natural" base encoding, with the coercion providing a way to take some other type of value and turn it into the base - but when base is a validated string, it is hard to get it to actually use the coercion. Right, coercions are only applied if the data doesn't already validate against the type. So (saying this without puzzling through your lookahead assertion) you may need to define your new type as a totally separate type on its own, not derived from the first type, so it doesn't already validate, and therefore executes the coercion.