use strict;
use warnings;
+use Carp::Clan qw( ^MooseX::Types );
use Moose::Util::TypeConstraints;
+use Moose::Meta::TypeConstraint::Union;
+
use overload(
'""' => sub {
shift->type_constraint->name;
},
'|' => sub {
- my @names = grep {$_} map {"$_"} @_;
- ## Don't know why I can't use the array version of this... If someone
- ## knows would like to hear from you.
- my $names = join('|', @names);
- Moose::Util::TypeConstraints::create_type_constraint_union($names);
+ my @tc = grep {ref $_} @_;
+ my $union = Moose::Meta::TypeConstraint::Union->new(type_constraints=>\@tc);
+ return Moose::Util::TypeConstraints::register_type_constraint($union);
},
);
sub new {
my ($class, %args) = @_;
- return bless \%args, $class;
+ if(
+ $args{type_constraint} && ref($args{type_constraint}) &&
+ ($args{type_constraint}->isa('Moose::Meta::TypeConstraint') ||
+ $args{type_constraint}->isa('MooseX::Types::UndefinedType'))
+ ) {
+ return bless \%args, $class;
+ } else {
+ croak "The argument 'type_constraint' is not valid.";
+ }
+
}
=head type_constraint ($type_constraint)
return $self->{type_constraint};
}
+=head2 isa
+
+handle $self->isa since AUTOLOAD can't.
+
+=cut
+
+sub isa {
+ my ($self, $target) = @_;
+ if(defined $target) {
+ my $isa = $self->type_constraint->isa($target);
+ return $isa;
+ } else {
+ return;
+ }
+}
+
+=head2 can
+
+handle $self->can since AUTOLOAD can't.
+
+=cut
+
+sub can {
+ my ($self, $target) = @_;
+ if(defined $target) {
+ my $can = $self->type_constraint->can($target);
+ return $can;
+ } else {
+ return;
+ }
+}
+
=head2 DESTROY
We might need it later
## test arrayrefbase normal and coercion
-ok $type->arrayrefbase([qw(a b c)])
- => 'Assigned arrayrefbase qw(a b c)';
+ok $type->arrayrefbase([qw(a b c d e)])
+ => 'Assigned arrayrefbase qw(a b c d e)';
-is_deeply $type->arrayrefbase, [qw(a b c)],
+is_deeply $type->arrayrefbase, [qw(a b c d e)],
=> 'Assignment is correct';
ok $type->arrayrefbase('d,e,f')