Skip to content

Instantly share code, notes, and snippets.

@patch
Created May 2, 2013 15:24
Show Gist options
  • Save patch/5502982 to your computer and use it in GitHub Desktop.
Save patch/5502982 to your computer and use it in GitHub Desktop.
Coerce Moose attribute from Num to Math::BigFloat (untested).
use Moose;
use Moose::Util::TypeConstraints;
use Math::BigFloat;
subtype 'BigFloat',
as class_type('Math::BigFloat');
coerce 'BigFloat',
from 'Num',
via { Math::BigFloat->new($_) };
has 'amount' => (
is => 'rw',
isa => 'BigFloat',
coerce => 1,
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment