Last active
December 18, 2015 19:39
-
-
Save rsimoes/5834506 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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