Re: [Newb] Mangling parameters, avoiding recursions?

[email protected] (Jesse Luehrs)
Newsgroups perl.moose
Message-ID <[email protected]>
On Sat, Jul 09, 2011 at 12:10:00AM +0200, Ekki Plicht (DF4OR) wrote:
> Several attributes of my class should be a bool, but get's thrown at with
> values like
> 1, Y, Ja, On for true
> 0, N, No, Nein, Off. '' (empty string) for false.
> 
> So I thought that an own subtype + coercion should help here:
> ----------------
> subtype 'MyBool',
>      as 'Str',
>   where { $_ =~ m/^j|^y|1|^on|^n|0|^off|\A\z/i };

The subtype itself should describe the thing you actually want to end up
with, not the incoming data (the incoming data is already described in
the coercion). This should be just "subtype 'MyBool', as 'Bool';".

-doy
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.