From: gfx Date: Fri, 19 Feb 2010 07:02:13 +0000 (+0900) Subject: Add type_parameter() and __is_parameterized() to Meta::TypeConstraint X-Git-Tag: 0.50_02~11 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMouse.git;a=commitdiff_plain;h=fc83f4cf2ef7708120a216bddc285b93082d7958 Add type_parameter() and __is_parameterized() to Meta::TypeConstraint --- diff --git a/lib/Mouse/Meta/TypeConstraint.pm b/lib/Mouse/Meta/TypeConstraint.pm index 023cb37..f6bdac8 100644 --- a/lib/Mouse/Meta/TypeConstraint.pm +++ b/lib/Mouse/Meta/TypeConstraint.pm @@ -211,12 +211,12 @@ sub parameterize{ || Carp::confess("The $name constraint cannot be used, because $param doesn't subtype from a parameterizable type"); return Mouse::Meta::TypeConstraint->new( - name => $name, - parent => $self, - parameter => $param, - constraint => $generator->($param), # must be 'constraint', not 'optimized' + name => $name, + parent => $self, + type_parameter => $param, + constraint => $generator->($param), # must be 'constraint', not 'optimized' - type => 'Parameterized', + type => 'Parameterized', ); } diff --git a/lib/Mouse/PurePerl.pm b/lib/Mouse/PurePerl.pm index 820968e..a946b03 100644 --- a/lib/Mouse/PurePerl.pm +++ b/lib/Mouse/PurePerl.pm @@ -511,6 +511,9 @@ sub name { $_[0]->{name} } sub parent { $_[0]->{parent} } sub message { $_[0]->{message} } +sub type_parameter { $_[0]->{type_parameter} } +sub __is_parameterized { exists $_[0]->{type_parameter} } + sub _compiled_type_constraint{ $_[0]->{compiled_type_constraint} } sub _compiled_type_coercion { $_[0]->{_compiled_type_coercion} } diff --git a/t/001_mouse/043-parameterized-type.t b/t/001_mouse/043-parameterized-type.t index 74b3ea9..3e223e2 100644 --- a/t/001_mouse/043-parameterized-type.t +++ b/t/001_mouse/043-parameterized-type.t @@ -1,7 +1,7 @@ #!/usr/bin/env perl use strict; use warnings; -use Test::More tests => 51; +use Test::More tests => 54; use Test::Exception; use Tie::Hash; @@ -210,4 +210,15 @@ while(my($k, $v) = each %th){ $th_clone{$k} = $v; } +is( $hash_of_int->type_parameter, 'Int' ); + +if('Mouse' eq ('Mo' . 'use')){ # under Mouse + ok $hash_of_int->__is_parameterized(); + ok!$hash_of_int->type_parameter->__is_parameterized(); +} +else{ # under Moose + ok $hash_of_int->can('type_parameter'); + ok!$hash_of_int->type_parameter->can('type_parameter'); +} + is_deeply \%th_clone, \%th, 'the hash iterator is initialized'; diff --git a/xs-src/MouseTypeConstraints.xs b/xs-src/MouseTypeConstraints.xs index 8188467..605c923 100644 --- a/xs-src/MouseTypeConstraints.xs +++ b/xs-src/MouseTypeConstraints.xs @@ -659,10 +659,13 @@ BOOT: INSTALL_SIMPLE_READER(TypeConstraint, parent); INSTALL_SIMPLE_READER(TypeConstraint, message); + INSTALL_SIMPLE_READER(TypeConstraint, type_parameter); + INSTALL_SIMPLE_READER_WITH_KEY(TypeConstraint, _compiled_type_constraint, compiled_type_constraint); INSTALL_SIMPLE_READER(TypeConstraint, _compiled_type_coercion); /* Mouse specific */ INSTALL_SIMPLE_PREDICATE_WITH_KEY(TypeConstraint, has_coercion, _compiled_type_coercion); + INSTALL_SIMPLE_PREDICATE_WITH_KEY(TypeConstraint, __is_parameterized, type_parameter); /* Mouse specific */ void compile_type_constraint(SV* self)