use warnings;
use metaclass;
-our $VERSION = '0.57';
+our $VERSION = '0.64';
$VERSION = eval $VERSION;
our $AUTHORITY = 'cpan:STEVAN';
};
}
-sub parse_parameter_str {
- my ($self, $type_str) = @_;
- return Moose::Util::TypeConstraints::find_or_create_isa_type_constraint($type_str);
+sub _parse_type_parameter {
+ my ($self, $type_parameter) = @_;
+ return Moose::Util::TypeConstraints::find_or_create_isa_type_constraint($type_parameter);
}
sub parameterize {
- my ($self, $contained_tc) = @_;
+ my ($self, $type_parameter) = @_;
- if($contained_tc->isa('Moose::Meta::TypeConstraint')) {
- my $tc_name = $self->name .'['. $contained_tc->name .']';
+ my $contained_tc = $self->_parse_type_parameter($type_parameter);
+
+ ## The type parameter should be a subtype of the parent's type parameter
+ ## if there is one.
+
+ if(my $parent = $self->parent) {
+ if($parent->can('type_parameter')) {
+ $contained_tc->is_a_type_of($parent->type_parameter)
+ || Moose->throw_error("$type_parameter is not a subtype of ".$parent->type_parameter);
+ }
+ }
+
+ if ( $contained_tc->isa('Moose::Meta::TypeConstraint') ) {
+ my $tc_name = $self->name . '[' . $contained_tc->name . ']';
return Moose::Meta::TypeConstraint::Parameterized->new(
name => $tc_name,
parent => $self,
type_parameter => $contained_tc,
- );
- } else {
+ );
+ }
+ else {
Moose->throw_error("The type parameter must be a Moose meta type");
}
}
=item B<generate_constraint_for>
-=item B<parse_parameter_str>
-
-Given a string, convert it to a Perl structure.
-
=item B<parameterize>
-Given an array of type constraints, parameterize the current type constraint.
+Given a single type constraint or type constraint string, this method
+parameterizes the type based on the given argument.
=item B<meta>