http://www.perlmonks.org?node_id=888791


in reply to Re: Moose - ensuring a getter returns a number
in thread Moose - ensuring a getter returns a number

Thanks for the idea.

Is there anything that can be done with Moose type constraints?

  • Comment on Re^2: Moose - ensuring a getter returns a number

Replies are listed 'Best First'.
Re^3: Moose - ensuring a getter returns a number
by stvn (Monsignor) on Feb 18, 2011 at 05:14 UTC

    Not likely, since Perl is so permissive about what is a number and what is a string, the Moose type constraint for numbers allows them to also be strings as well.

    The solution with the around is actually pretty good, or as another responder points out, make sure that the value is a number before it is actually added to your data object.

    -stvn