in reply to Re: Moose trait (?) to set "undef" to, say, "empty string?"
in thread [SOLVED] Moose trait (?) to set "undef" to, say, "empty string?"

If by magick you mean the well documented way in which coercions work, the answer is yes. :\

Moose::Manual::Types: Moose will never try to coerce a value unless you explicitly ask for it. This is done by setting the coerce attribute option to a true value...
Moose::Cookbook::Basics::Recipe5: However, defining the coercion doesn't do anything until we tell Moose we want a particular attribute to be coerced...
Moose: coerce => (1|0) This will attempt to use coercion with the supplied type constraint to change the value passed into any accessors or constructors. You must supply a type constraint, and that type constraint must define a coercion...

See also, Moose::Manual::FAQ and probably other spots.

  • Comment on Re^2: Moose trait (?) to set "undef" to, say, "empty string?"

Replies are listed 'Best First'.
Re^3: Moose trait (?) to set "undef" to, say, "empty string?"
by locked_user sundialsvc4 (Abbot) on Nov 29, 2011 at 15:39 UTC

    Must be getting too old for this ...   I guessed (correctly) that it had to do with type-constraints and with coercions, but simply overlooked the importance of that flag.   I guess I decided too-quickly that maybe it was looking for a particular type-definition and not matching the coercion specification, instead of not attempting any coercion at all.   Merely specifying a coerce rule doesn’t cause it to be invoked.   Sigh.   Shows what ’ya get sometimes, for chasin’ them red herrings and jumpin’ to conclusions ...

    Thank you, sincerely, for pointing out these documentation references to me.