use namespace::clean -except => [qw( meta )];
-our $VERSION = 0.05;
+our $VERSION = 0.06;
my $UndefMsg = q{Action for type '%s' not yet defined in library '%s'};
# predeclare our own types
use MooseX::Types
- -declare => [qw( PositiveInt NegativeInt )];
+ -declare => [qw(
+ PositiveInt NegativeInt
+ ArrayRefOfPositiveInt ArrayRefOfAtLeastThreeNegativeInts
+ LotsOfInnerConstraints StrOrArrayRef
+ )];
# import builtin types
use MooseX::Types::Moose 'Int';
from Int,
via { 1 };
+ # with parameterized constraints.
+
+ subtype ArrayRefOfPositiveInt,
+ as ArrayRef[PositiveInt];
+
+ subtype ArrayRefOfAtLeastThreeNegativeInts,
+ as ArrayRef[NegativeInt],
+ where { scalar(@$_) > 2 };
+
+ subtype LotsOfInnerConstraints,
+ as ArrayRef[ArrayRef[HashRef[Int]]];
+
+ # with TypeConstraint Unions
+
+ subtype StrOrArrayRef,
+ as Str|ArrayRef;
+
1;
=head2 Usage
A message that will be thrown when type functionality is used but the
type does not yet exist.
-=back
+=head1 NOTES REGARDING TYPE UNIONS
+
+L<MooseX::Types> uses L<MooseX::Types::TypeDecorator> to do some overloading
+which generally allows you to easily create union types:
+
+ subtype StrOrArrayRef,
+ as Str|ArrayRef;
+As with parameterized constrains, this overloading extends to modules using the
+types you define in a type library.
+
+ use Moose;
+ use MooseX::Types::Moose qw(HashRef Int);
+
+ has 'attr' => (isa=>HashRef|Int);
+
+And everything should just work as you'd think.
+
=head1 METHODS
=head2 import
}
$type_constraint = defined($type_constraint) ? $type_constraint
: MooseX::Types::UndefinedType->new($name);
+
+ my $type_decorator = $class->create_type_decorator($type_constraint);
- return $class->create_type_decorator($type_constraint);
+ if(@_) {
+ return ($type_decorator, @_);
+ } else {
+ return $type_decorator;
+ }
};
}
sub create_arged_type_constraint {
my ($class, $name, @args) = @_;
- ### This whole section is a real TODO :) Ugly hack to get the base tests working.
- my $fullname = $name."[$args[0]]";
- return Moose::Util::TypeConstraints::create_parameterized_type_constraint($fullname);
+ my $type_constraint = Moose::Util::TypeConstraints::find_or_create_type_constraint($name);
+ return $type_constraint->parameterize(@args)
}
=head2 create_base_type_constraint ($name)
sub create_type_decorator {
my ($class, $type_constraint) = @_;
- return MooseX::Types::TypeDecorator->new(type_constraint=>$type_constraint);
+ return MooseX::Types::TypeDecorator->new($type_constraint);
}
=head2 coercion_export_generator
Robert 'phaylon' Sedlacek C<E<lt>rs@474.atE<gt>>, with many thanks to
the C<#moose> cabal on C<irc.perl.org>.
+Additional features by John Napiorkowski (jnapiorkowski) <jjnapiork@cpan.org>.
+
=head1 LICENSE
This program is free software; you can redistribute it and/or modify