subtype 'Value' => as 'Item' => where { !ref($_) };
subtype 'Ref' => as 'Item' => where { ref($_) };
-subtype 'Bool' => as 'Item' => where { "$_" eq '1' || "$_" eq '0' };
+subtype 'Bool' => as 'Item' => where { !defined($_) || $_ eq "" || "$_" eq '1' || "$_" eq '0' };
-subtype 'Int' => as 'Value' => where { Scalar::Util::looks_like_number($_) };
-subtype 'Str' => as 'Value' => where { !Scalar::Util::looks_like_number($_) };
+subtype 'Str' => as 'Value' => where { defined($_) };
-subtype 'ScalarRef' => as 'Ref' => where { ref($_) eq 'SCALAR' };
+subtype 'Num' => as 'Value' => where { Scalar::Util::looks_like_number($_) };
+subtype 'Int' => as 'Num' => where { "$_" =~ /^[0-9]+$/ };
+
+subtype 'ScalarRef' => as 'Ref' => where { ref($_) eq 'SCALAR' };
subtype 'CollectionRef' => as 'Ref' => where { ref($_) eq 'ARRAY' || ref($_) eq 'HASH' };
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
-=cut
\ No newline at end of file
+=cut
use warnings;
use Moose;
- has 'balance' => (isa => 'Int', is => 'rw', default => 0);
+ has 'balance' => (isa => 'Num', is => 'rw', default => 0);
sub deposit {
my ($self, $amount) = @_;
with 'Ord';
- has 'amount' => (is => 'rw', isa => 'Int', default => 0);
+ has 'amount' => (is => 'rw', isa => 'Num', default => 0);
sub compare {
my ($self, $other) = @_;
use warnings;
use Moose::Role;
- has 'value' => (isa => 'Int', is => 'ro');
+ has 'value' => (isa => 'Num', is => 'ro');
around 'validate' => sub {
my $c = shift;
=> via { HTTPHeader->new(array => $_[0]) }
=> from HashRef
=> via { HTTPHeader->new(hash => $_[0]) };
+
+
+{
+ package Math::BigFloat;
+ sub new { bless { }, shift }; # not a moose class ;-)
+}
+
+subtype "Math::BigFloat"
+ => as "Math::BigFloat"
+ => where { 1 };
+
+coerce "Math::BigFloat"
+ => from Num
+ => via { Math::BigFloat->new( $_ ) };
+
Moose::Util::TypeConstraints->export_type_contstraints_as_functions();