On Fri, 28 Jan 2011 22:17:24 +0100, Jiří Pavlovský <j...@getnet.cz> wrote:
> >> subtype MaybeSubject =>  as 'Maybe[Subject]';
> >> coerce 'MaybeSubject'
> >> =>  from 'Subject'
> >> =>  via {
> >>      my $sanitized =sanitize_input($_);
> >>       $sanitized;
> >>
> >> };
> > This doesn't make any sense to me.
> >
> 
> Otherwise I get an error that attribute cannot have coearcion unless its 
> type has coearcion.

If your answer to "why are you doing this" is "otherwise I get an error", you
don't understand what you're doing and you're probably doing it wrong.

MaybeSubject is *more* permissive than Subject, so coercing doesn't make
logical sense.  It especially doesn't make sense to coerce with the block you
gave, since anything that matches Subject has already gone through
sanitize_input.

Also, this coercion should never fire, for the same reason your original one
wouldn't -- any valid Subject is already a valid Maybe[Subject].

Finally, Maybe[Anything] is often a design smell, and using Maybe in coercions
even more so.  Why do you need the possibility of undef?

hdp.

Reply via email to