X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose%2FMeta%2FTypeConstraint%2FParameterizable.pm;h=4fdfbe69696b73d463fd23678d2aab049a485099;hb=08380fdb9f79107ab7aaf353edd03757ad3e8400;hp=7f7300495dc365e15dab14d8070c26da90f53989;hpb=eaa35e6e0f9132abf6ed0cec60515dd7259ce704;p=gitmo%2FMoose.git diff --git a/lib/Moose/Meta/TypeConstraint/Parameterizable.pm b/lib/Moose/Meta/TypeConstraint/Parameterizable.pm index 7f73004..4fdfbe6 100644 --- a/lib/Moose/Meta/TypeConstraint/Parameterizable.pm +++ b/lib/Moose/Meta/TypeConstraint/Parameterizable.pm @@ -4,10 +4,13 @@ use strict; use warnings; use metaclass; -our $VERSION = '0.50'; +our $VERSION = '0.57'; +$VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; use base 'Moose::Meta::TypeConstraint'; +use Moose::Meta::TypeConstraint::Parameterized; +use Moose::Util::TypeConstraints (); __PACKAGE__->meta->add_attribute('constraint_generator' => ( accessor => 'constraint_generator', @@ -39,6 +42,26 @@ sub _can_coerce_constraint_from { }; } +sub parse_parameter_str { + my ($self, $type_str) = @_; + return Moose::Util::TypeConstraints::find_or_create_isa_type_constraint($type_str); +} + +sub parameterize { + my ($self, $contained_tc) = @_; + + 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 { + Moose->throw_error("The type parameter must be a Moose meta type"); + } +} + 1; @@ -61,6 +84,14 @@ Moose::Meta::TypeConstraint::Parameterizable - Higher Order type constraints for =item B +=item B + +Given a string, convert it to a Perl structure. + +=item B + +Given an array of type constraints, parameterize the current type constraint. + =item B =back