Skip to content

Instantly share code, notes, and snippets.

@rsimoes
Last active December 18, 2015 19:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rsimoes/5834506 to your computer and use it in GitHub Desktop.
Save rsimoes/5834506 to your computer and use it in GitHub Desktop.
package My::Types;
use strict;
use warnings;
use Type::Utils;
use Type::Library -base,
-declare => 'Percentage';
use Types::Standard qw(Num);
use Math::BigFloat;
declare Percentage,
as class_type({ class => 'Math::BigFloat' }),
# where { $_ >= 0 && $_ <= 1 };
where { 1 };
#coerce Percentage,
# from Num,
# via { Math::BigFloat->new($_) };
package My::Class;
use Moo;
has foo => (
is => 'rw',
isa => My::Types::Percentage,
coerce => My::Types::Percentage->coercion,
required => 1
);
package main;
use strict;
use warnings;
My::Class->new( foo => Math::BigFloat->new(0.5) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment