From: Stevan Little Date: Tue, 18 Sep 2007 22:13:10 +0000 (+0000) Subject: s/container/parameterized/ X-Git-Tag: 0_26~9 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0fbd4b0a825a44f70a4e8537f50712dafac3c938;p=gitmo%2FMoose.git s/container/parameterized/ --- diff --git a/Changes b/Changes index 8541cb8..eb46bfe 100644 --- a/Changes +++ b/Changes @@ -61,7 +61,7 @@ Revision history for Perl extension Moose Moose::Meta::TypeConstraint::Union and is itself a subclass of Moose::Meta::TypeCoercion - * Moose::Meta::TypeConstraint::Container + * Moose::Meta::TypeConstraint::Parameterized - added this module (taken from MooseX::AttributeHelpers) to help construct nested collection types - added tests for this diff --git a/lib/Moose.pm b/lib/Moose.pm index 1289964..f363c93 100644 --- a/lib/Moose.pm +++ b/lib/Moose.pm @@ -258,7 +258,7 @@ $_->meta->make_immutable( 'Moose::Meta::TypeConstraint', 'Moose::Meta::TypeConstraint::Union', - 'Moose::Meta::TypeConstraint::Container', + 'Moose::Meta::TypeConstraint::Parameterized', 'Moose::Meta::TypeCoercion', 'Moose::Meta::Method', diff --git a/lib/Moose/Meta/TypeConstraint/Container.pm b/lib/Moose/Meta/TypeConstraint/Parameterized.pm similarity index 66% rename from lib/Moose/Meta/TypeConstraint/Container.pm rename to lib/Moose/Meta/TypeConstraint/Parameterized.pm index 53c0324..1eaba7d 100644 --- a/lib/Moose/Meta/TypeConstraint/Container.pm +++ b/lib/Moose/Meta/TypeConstraint/Parameterized.pm @@ -1,4 +1,4 @@ -package Moose::Meta::TypeConstraint::Container; +package Moose::Meta::TypeConstraint::Parameterized; use strict; use warnings; @@ -12,21 +12,21 @@ our $AUTHORITY = 'cpan:STEVAN'; use base 'Moose::Meta::TypeConstraint'; -__PACKAGE__->meta->add_attribute('container_type' => ( - accessor => 'container_type', - predicate => 'has_container_type', +__PACKAGE__->meta->add_attribute('type_parameter' => ( + accessor => 'type_parameter', + predicate => 'has_type_parameter', )); sub compile_type_constraint { my $self = shift; - ($self->has_container_type) - || confess "You cannot create a Container type without one"; + ($self->has_type_parameter) + || confess "You cannot create a Higher Order type without a type parameter"; - my $container_type = $self->container_type; + my $type_parameter = $self->type_parameter; - (blessed $container_type && $container_type->isa('Moose::Meta::TypeConstraint')) - || confess "The container type must be a Moose meta type"; + (blessed $type_parameter && $type_parameter->isa('Moose::Meta::TypeConstraint')) + || confess "The type parameter must be a Moose meta type"; my $constraint; @@ -35,14 +35,14 @@ sub compile_type_constraint { if ($parent_name eq 'ArrayRef') { $constraint = sub { foreach my $x (@$_) { - ($container_type->check($x)) || return + ($type_parameter->check($x)) || return } 1; }; } elsif ($parent_name eq 'HashRef') { $constraint = sub { foreach my $x (values %$_) { - ($container_type->check($x)) || return + ($type_parameter->check($x)) || return } 1; }; } @@ -64,7 +64,7 @@ __END__ =head1 NAME -Moose::Meta::TypeConstraint::Container +Moose::Meta::TypeConstraint::Parameterized - Higher Order type constraints for Moose =head1 DESCRIPTION @@ -74,9 +74,9 @@ Moose::Meta::TypeConstraint::Container =item B -=item B +=item B -=item B +=item B =item B diff --git a/lib/Moose/Util/TypeConstraints.pm b/lib/Moose/Util/TypeConstraints.pm index 849635f..3f9ca16 100644 --- a/lib/Moose/Util/TypeConstraints.pm +++ b/lib/Moose/Util/TypeConstraints.pm @@ -20,10 +20,10 @@ our $AUTHORITY = 'cpan:STEVAN'; # compiled. # creation and location -sub find_type_constraint ($); -sub find_or_create_type_constraint ($;$); -sub create_type_constraint_union (@); -sub create_container_type_constraint ($); +sub find_type_constraint ($); +sub find_or_create_type_constraint ($;$); +sub create_type_constraint_union (@); +sub create_parameterized_type_constraint ($); # dah sugah! sub type ($$;$$); @@ -45,7 +45,7 @@ sub _install_type_coercions ($$); use Moose::Meta::TypeConstraint; use Moose::Meta::TypeConstraint::Union; -use Moose::Meta::TypeConstraint::Container; +use Moose::Meta::TypeConstraint::Parameterized; use Moose::Meta::TypeCoercion; use Moose::Meta::TypeCoercion::Union; use Moose::Meta::TypeConstraint::Registry; @@ -125,24 +125,24 @@ sub create_type_constraint_union (@) { ); } -sub create_container_type_constraint ($) { +sub create_parameterized_type_constraint ($) { my $type_constraint_name = shift; - my ($base_type, $container_type) = _parse_container_type_constraint($type_constraint_name); + my ($base_type, $type_parameter) = _parse_parameterized_type_constraint($type_constraint_name); - (defined $base_type && defined $container_type) + (defined $base_type && defined $type_parameter) || confess "Could not parse type name ($type_constraint_name) correctly"; ($REGISTRY->has_type_constraint($base_type)) || confess "Could not locate the base type ($base_type)"; - return Moose::Meta::TypeConstraint::Container->new( + return Moose::Meta::TypeConstraint::Parameterized->new( name => $type_constraint_name, parent => $REGISTRY->get_type_constraint($base_type), - container_type => find_or_create_type_constraint( - $container_type => { + type_parameter => find_or_create_type_constraint( + $type_parameter => { parent => $REGISTRY->get_type_constraint('Object'), - constraint => sub { $_[0]->isa($container_type) } + constraint => sub { $_[0]->isa($type_parameter) } } ), ); @@ -159,8 +159,8 @@ sub find_or_create_type_constraint ($;$) { if (_detect_type_constraint_union($type_constraint_name)) { $constraint = create_type_constraint_union($type_constraint_name); } - elsif (_detect_container_type_constraint($type_constraint_name)) { - $constraint = create_container_type_constraint($type_constraint_name); + elsif (_detect_parameterized_type_constraint($type_constraint_name)) { + $constraint = create_parameterized_type_constraint($type_constraint_name); } else { # NOTE: @@ -313,12 +313,12 @@ sub _install_type_coercions ($$) { our $any = qr{ $type | $union }x; - sub _parse_container_type_constraint { + sub _parse_parameterized_type_constraint { $_[0] =~ m{ $type_capture_parts }x; return ($1, $2); } - sub _detect_container_type_constraint { + sub _detect_parameterized_type_constraint { $_[0] =~ m{ ^ $type_with_parameter $ }x; } @@ -573,14 +573,14 @@ test file. Given string with C<$pipe_seperated_types> or a list of C<@type_constraint_names>, this will return a L instance. -=item B +=item B Given a C<$type_name> in the form of: BaseType[ContainerType] this will extract the base type and container type and build an instance of -L for it. +L for it. =item B diff --git a/t/040_type_constraints/011_container_type_constraint.t b/t/040_type_constraints/011_container_type_constraint.t index eb54e3b..32b3430 100644 --- a/t/040_type_constraints/011_container_type_constraint.t +++ b/t/040_type_constraints/011_container_type_constraint.t @@ -8,17 +8,17 @@ use Test::Exception; BEGIN { use_ok('Moose::Util::TypeConstraints'); - use_ok('Moose::Meta::TypeConstraint::Container'); + use_ok('Moose::Meta::TypeConstraint::Parameterized'); } # Array of Ints -my $array_of_ints = Moose::Meta::TypeConstraint::Container->new( +my $array_of_ints = Moose::Meta::TypeConstraint::Parameterized->new( name => 'ArrayRef[Int]', parent => find_type_constraint('ArrayRef'), - container_type => find_type_constraint('Int'), + type_parameter => find_type_constraint('Int'), ); -isa_ok($array_of_ints, 'Moose::Meta::TypeConstraint::Container'); +isa_ok($array_of_ints, 'Moose::Meta::TypeConstraint::Parameterized'); isa_ok($array_of_ints, 'Moose::Meta::TypeConstraint'); ok($array_of_ints->check([ 1, 2, 3, 4 ]), '... [ 1, 2, 3, 4 ] passed successfully'); @@ -31,12 +31,12 @@ ok(!$array_of_ints->check(sub { () }), '... sub { () } failed successfully'); # Hash of Ints -my $hash_of_ints = Moose::Meta::TypeConstraint::Container->new( +my $hash_of_ints = Moose::Meta::TypeConstraint::Parameterized->new( name => 'HashRef[Int]', parent => find_type_constraint('HashRef'), - container_type => find_type_constraint('Int'), + type_parameter => find_type_constraint('Int'), ); -isa_ok($hash_of_ints, 'Moose::Meta::TypeConstraint::Container'); +isa_ok($hash_of_ints, 'Moose::Meta::TypeConstraint::Parameterized'); isa_ok($hash_of_ints, 'Moose::Meta::TypeConstraint'); ok($hash_of_ints->check({ one => 1, two => 2, three => 3 }), '... { one => 1, two => 2, three => 3 } passed successfully'); @@ -49,12 +49,12 @@ ok(!$hash_of_ints->check(sub { () }), '... sub { () } failed successfully'); # Array of Array of Ints -my $array_of_array_of_ints = Moose::Meta::TypeConstraint::Container->new( +my $array_of_array_of_ints = Moose::Meta::TypeConstraint::Parameterized->new( name => 'ArrayRef[ArrayRef[Int]]', parent => find_type_constraint('ArrayRef'), - container_type => $array_of_ints, + type_parameter => $array_of_ints, ); -isa_ok($array_of_array_of_ints, 'Moose::Meta::TypeConstraint::Container'); +isa_ok($array_of_array_of_ints, 'Moose::Meta::TypeConstraint::Parameterized'); isa_ok($array_of_array_of_ints, 'Moose::Meta::TypeConstraint'); ok($array_of_array_of_ints->check( diff --git a/t/040_type_constraints/012_container_type_coercion.t b/t/040_type_constraints/012_container_type_coercion.t index 8ca24b7..693a16e 100644 --- a/t/040_type_constraints/012_container_type_coercion.t +++ b/t/040_type_constraints/012_container_type_coercion.t @@ -8,19 +8,19 @@ use Test::Exception; BEGIN { use_ok('Moose::Util::TypeConstraints'); - use_ok('Moose::Meta::TypeConstraint::Container'); + use_ok('Moose::Meta::TypeConstraint::Parameterized'); } my $r = Moose::Util::TypeConstraints->get_type_constraint_registry; # Array of Ints -my $array_of_ints = Moose::Meta::TypeConstraint::Container->new( +my $array_of_ints = Moose::Meta::TypeConstraint::Parameterized->new( name => 'ArrayRef[Int]', parent => find_type_constraint('ArrayRef'), - container_type => find_type_constraint('Int'), + type_parameter => find_type_constraint('Int'), ); -isa_ok($array_of_ints, 'Moose::Meta::TypeConstraint::Container'); +isa_ok($array_of_ints, 'Moose::Meta::TypeConstraint::Parameterized'); isa_ok($array_of_ints, 'Moose::Meta::TypeConstraint'); $r->add_type_constraint($array_of_ints); @@ -29,12 +29,12 @@ is(find_type_constraint('ArrayRef[Int]'), $array_of_ints, '... found the type we # Hash of Ints -my $hash_of_ints = Moose::Meta::TypeConstraint::Container->new( +my $hash_of_ints = Moose::Meta::TypeConstraint::Parameterized->new( name => 'HashRef[Int]', parent => find_type_constraint('HashRef'), - container_type => find_type_constraint('Int'), + type_parameter => find_type_constraint('Int'), ); -isa_ok($hash_of_ints, 'Moose::Meta::TypeConstraint::Container'); +isa_ok($hash_of_ints, 'Moose::Meta::TypeConstraint::Parameterized'); isa_ok($hash_of_ints, 'Moose::Meta::TypeConstraint'); $r->add_type_constraint($hash_of_ints); diff --git a/t/040_type_constraints/013_advanced_type_creation.t b/t/040_type_constraints/013_advanced_type_creation.t index bb60379..9d15c7a 100644 --- a/t/040_type_constraints/013_advanced_type_creation.t +++ b/t/040_type_constraints/013_advanced_type_creation.t @@ -8,7 +8,7 @@ use Test::Exception; BEGIN { use_ok('Moose::Util::TypeConstraints'); - use_ok('Moose::Meta::TypeConstraint::Container'); + use_ok('Moose::Meta::TypeConstraint::Parameterized'); } my $r = Moose::Util::TypeConstraints->get_type_constraint_registry; @@ -17,8 +17,8 @@ my $r = Moose::Util::TypeConstraints->get_type_constraint_registry; # Array of Ints or Strings -my $array_of_ints_or_strings = Moose::Util::TypeConstraints::create_container_type_constraint('ArrayRef[Int | Str]'); -isa_ok($array_of_ints_or_strings, 'Moose::Meta::TypeConstraint::Container'); +my $array_of_ints_or_strings = Moose::Util::TypeConstraints::create_parameterized_type_constraint('ArrayRef[Int | Str]'); +isa_ok($array_of_ints_or_strings, 'Moose::Meta::TypeConstraint::Parameterized'); ok($array_of_ints_or_strings->check([ 1, 'two', 3 ]), '... this passed the type check'); ok($array_of_ints_or_strings->check([ 1, 2, 3 ]), '... this passed the type check'); @@ -30,8 +30,8 @@ $r->add_type_constraint($array_of_ints_or_strings); # Array of Ints or HashRef -my $array_of_ints_or_hash_ref = Moose::Util::TypeConstraints::create_container_type_constraint('ArrayRef[Int | HashRef]'); -isa_ok($array_of_ints_or_hash_ref, 'Moose::Meta::TypeConstraint::Container'); +my $array_of_ints_or_hash_ref = Moose::Util::TypeConstraints::create_parameterized_type_constraint('ArrayRef[Int | HashRef]'); +isa_ok($array_of_ints_or_hash_ref, 'Moose::Meta::TypeConstraint::Parameterized'); ok($array_of_ints_or_hash_ref->check([ 1, {}, 3 ]), '... this passed the type check'); ok($array_of_ints_or_hash_ref->check([ 1, 2, 3 ]), '... this passed the type check'); @@ -59,8 +59,8 @@ ok(!$pure_insanity->check([ [], {}, 1 ]), '... this didnt pass the type check'); # Array of Ints -my $array_of_ints = Moose::Util::TypeConstraints::create_container_type_constraint('ArrayRef[Int]'); -isa_ok($array_of_ints, 'Moose::Meta::TypeConstraint::Container'); +my $array_of_ints = Moose::Util::TypeConstraints::create_parameterized_type_constraint('ArrayRef[Int]'); +isa_ok($array_of_ints, 'Moose::Meta::TypeConstraint::Parameterized'); isa_ok($array_of_ints, 'Moose::Meta::TypeConstraint'); ok($array_of_ints->check([ 1, 2, 3, 4 ]), '... [ 1, 2, 3, 4 ] passed successfully'); @@ -73,8 +73,8 @@ ok(!$array_of_ints->check(sub { () }), '... sub { () } failed successfully'); # Array of Array of Ints -my $array_of_array_of_ints = Moose::Util::TypeConstraints::create_container_type_constraint('ArrayRef[ArrayRef[Int]]'); -isa_ok($array_of_array_of_ints, 'Moose::Meta::TypeConstraint::Container'); +my $array_of_array_of_ints = Moose::Util::TypeConstraints::create_parameterized_type_constraint('ArrayRef[ArrayRef[Int]]'); +isa_ok($array_of_array_of_ints, 'Moose::Meta::TypeConstraint::Parameterized'); isa_ok($array_of_array_of_ints, 'Moose::Meta::TypeConstraint'); ok($array_of_array_of_ints->check( @@ -86,8 +86,8 @@ ok(!$array_of_array_of_ints->check( # Array of Array of Array of Ints -my $array_of_array_of_array_of_ints = Moose::Util::TypeConstraints::create_container_type_constraint('ArrayRef[ArrayRef[ArrayRef[Int]]]'); -isa_ok($array_of_array_of_array_of_ints, 'Moose::Meta::TypeConstraint::Container'); +my $array_of_array_of_array_of_ints = Moose::Util::TypeConstraints::create_parameterized_type_constraint('ArrayRef[ArrayRef[ArrayRef[Int]]]'); +isa_ok($array_of_array_of_array_of_ints, 'Moose::Meta::TypeConstraint::Parameterized'); isa_ok($array_of_array_of_array_of_ints, 'Moose::Meta::TypeConstraint'); ok($array_of_array_of_array_of_ints->check( diff --git a/t/040_type_constraints/014_type_notation_parser.t b/t/040_type_constraints/014_type_notation_parser.t index f7f3908..5c3c9ba 100644 --- a/t/040_type_constraints/014_type_notation_parser.t +++ b/t/040_type_constraints/014_type_notation_parser.t @@ -11,7 +11,7 @@ BEGIN { ## check the containers -ok(Moose::Util::TypeConstraints::_detect_container_type_constraint($_), +ok(Moose::Util::TypeConstraints::_detect_parameterized_type_constraint($_), '... this correctly detected a container (' . $_ . ')') for ( 'ArrayRef[Foo]', @@ -20,7 +20,7 @@ ok(Moose::Util::TypeConstraints::_detect_container_type_constraint($_), 'ArrayRef[ArrayRef[Int | Foo]]', ); -ok(!Moose::Util::TypeConstraints::_detect_container_type_constraint($_), +ok(!Moose::Util::TypeConstraints::_detect_parameterized_type_constraint($_), '... this correctly detected a non-container (' . $_ . ')') for ( 'ArrayRef[]', @@ -38,7 +38,7 @@ ok(!Moose::Util::TypeConstraints::_detect_container_type_constraint($_), ); is_deeply( - [ Moose::Util::TypeConstraints::_parse_container_type_constraint($_) ], + [ Moose::Util::TypeConstraints::_parse_parameterized_type_constraint($_) ], $split_tests{$_}, '... this correctly split the container (' . $_ . ')' ) for keys %split_tests;