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