From: John Napiorkowski Date: Thu, 11 Sep 2008 03:30:57 +0000 (+0000) Subject: first go at some test cases and basic implementation X-Git-Tag: 0.58~37^2~18 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=79135d0959bbe76b322d8a9fcf2900f7c3a508b4;p=gitmo%2FMoose.git first go at some test cases and basic implementation --- diff --git a/lib/Moose/Meta/TypeConstraint/Parameterizable.pm b/lib/Moose/Meta/TypeConstraint/Parameterizable.pm index 95193eb..530f026 100644 --- a/lib/Moose/Meta/TypeConstraint/Parameterizable.pm +++ b/lib/Moose/Meta/TypeConstraint/Parameterizable.pm @@ -9,6 +9,7 @@ $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; use base 'Moose::Meta::TypeConstraint'; +use Moose::Meta::TypeConstraint::Parameterized; __PACKAGE__->meta->add_attribute('constraint_generator' => ( accessor => 'constraint_generator', @@ -40,6 +41,24 @@ sub _can_coerce_constraint_from { }; } +sub parameterize { + my ($self, $args) = @_; + + unless(ref $args eq 'ARRAY') { + Moose->throw_error( + "The type constraint ".$self->name." requires it's argument to be an ArrayRef" + ); + } + + my $contained_tc = find_or_create_isa_type_constraint($args->[0]); + + return Moose::Meta::TypeConstraint::Parameterized->new( + name => $self->name .'['.$contained_tc->name.']', + parent => $self, + type_parameter => find_or_create_isa_type_constraint($contained_tc), + ); +} + 1; diff --git a/t/040_type_constraints/010_misc_type_tests.t b/t/040_type_constraints/010_misc_type_tests.t index 779bcf3..adbd0db 100644 --- a/t/040_type_constraints/010_misc_type_tests.t +++ b/t/040_type_constraints/010_misc_type_tests.t @@ -47,3 +47,18 @@ ok $subtype1 => 'made a subtype from our type object'; my $subtype2 = subtype 'New2' => as $subtype1; ok $subtype2 => 'made a subtype of our subtype'; + +# testing the parameterize method + +{ + package Test::Moose::Meta::TypeConstraint::Parameterizable; + + use Moose; + use Moose::Util::TypeConstraints; + + my $parameterizable = subtype 'parameterizable_hashref', + as 'HashRef'; + + my $parameterized = subtype 'parameterized_hashref', + as 'HashRef[Int]'; +} \ No newline at end of file