in reply to [SOLVED] Moose trait (?) to set "undef" to, say, "empty string?"
Create a type that's a subtype of Str. For that type, create a coercion rule so that Undef is coerced to the empty string. Use that type and coerce=>1 for the attribute.
use Moose::Util::TypeConstraints; subtype 'MyStr', as 'Str'; coerce 'MyStr', from 'Undef', via { '' }; no Moose::Util::TypeConstraints; has foo => ( isa => 'MyStr', coerce => 1, ... );
Can't think of a good name for it.
|
|---|