From: Stevan Little Date: Fri, 28 Mar 2008 20:27:31 +0000 (+0000) Subject: some doc tweaks and removing the ->includes_type from TC::Union for now X-Git-Tag: 0_55~248 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=aed8776196d14fe1376f14b02f450f6a4f483771;p=gitmo%2FMoose.git some doc tweaks and removing the ->includes_type from TC::Union for now --- diff --git a/Changes b/Changes index 3401695..1d001b2 100644 --- a/Changes +++ b/Changes @@ -16,12 +16,8 @@ Revision history for Perl extension Moose - added tests for this (Dave Rolsky) * Moose::Meta::Attribute - - inherited attributes may now be extended without restriction on type - and some other attributes (Sartak) - - * Moose::Meta::TypeConstraint::Union - - includes_type method for finding if a type (or a subtype of it) is - included in the union (Sartak) + - inherited attributes may now be extended without + restriction on the type ('isa') (Sartak) - added tests for this (Sartak) 0.40 Fri. March 14, 2008 diff --git a/lib/Moose.pm b/lib/Moose.pm index 5c310be..2f415d1 100644 --- a/lib/Moose.pm +++ b/lib/Moose.pm @@ -700,8 +700,12 @@ Change if the attribute lazily initializes the slot. =item I -You I allowed to change the type, B the new type is a -subtype of the old type. +You I allowed to change the type without restriction. + +It is recommended that you use this freedom with caution. We used to +only allow for extension only if the type was a subtype of the parent's +type, but we felt that was too restrictive and is better left as a +policy descision. =item I diff --git a/lib/Moose/Meta/TypeConstraint/Union.pm b/lib/Moose/Meta/TypeConstraint/Union.pm index 1337b0e..0f538e3 100644 --- a/lib/Moose/Meta/TypeConstraint/Union.pm +++ b/lib/Moose/Meta/TypeConstraint/Union.pm @@ -68,31 +68,6 @@ sub is_subtype_of { return 0; } -sub includes_type { - my ($self, $type) = @_; - - my $has_type = sub { - my $subtype = shift; - - for my $type (@{ $self->type_constraints }) { - return 1 if $subtype->is_a_type_of($type); - } - - return 0; - }; - - if ($type->isa('Moose::Meta::TypeConstraint::Union')) { - for my $t (@{ $type->type_constraints }) { - return 0 unless $has_type->($t); - } - } - else { - return 0 unless $has_type->($type); - } - - return 1; -} - 1; __END__ diff --git a/t/040_type_constraints/024_union_includes.t b/t/040_type_constraints/024_union_includes.t deleted file mode 100644 index 7f32ae4..0000000 --- a/t/040_type_constraints/024_union_includes.t +++ /dev/null @@ -1,65 +0,0 @@ -#!/usr/bin/perl - -use strict; -use warnings; - -use Test::More tests => 41; -use Test::Exception; - -BEGIN { - use_ok('Moose::Util::TypeConstraints'); -} - -my $Str = find_type_constraint('Str'); -my $Undef = find_type_constraint('Undef'); -my $Item = find_type_constraint('Item'); -my $Value = find_type_constraint('Value'); -my $ClassName = find_type_constraint('ClassName'); -my $Num = find_type_constraint('Num'); -my $Int = find_type_constraint('Int'); - -for my $type ($Str, $Undef, $Item, $Value, $ClassName, $Num, $Int) { - isa_ok($type, 'Moose::Meta::TypeConstraint'); -} - -my $Str_or_Undef = Moose::Meta::TypeConstraint::Union->new(type_constraints => [$Str, $Undef]); -my $Value_or_Undef = Moose::Meta::TypeConstraint::Union->new(type_constraints => [$Value, $Undef]); -my $Int_or_ClassName = Moose::Meta::TypeConstraint::Union->new(type_constraints => [$Int, $ClassName]); - -for my $type ($Str_or_Undef, $Value_or_Undef, $Int_or_ClassName) { - isa_ok($type, 'Moose::Meta::TypeConstraint::Union'); -} - -ok($Str_or_Undef->includes_type($Str), "Str | Undef includes Str"); -ok($Str_or_Undef->includes_type($Undef), "Str | Undef includes Undef"); -ok(!$Str_or_Undef->includes_type($Item), "Str | Undef doesn't include supertype Item"); -ok(!$Str_or_Undef->includes_type($Value), "Str | Undef doesn't include supertype Value"); -ok($Str_or_Undef->includes_type($ClassName), "Str | Undef includes Str subtype ClassName"); -ok(!$Str_or_Undef->includes_type($Num), "Str | Undef doesn't include Num"); -ok(!$Str_or_Undef->includes_type($Int), "Str | Undef doesn't include Int"); -ok(!$Str_or_Undef->includes_type($Value_or_Undef), "Str | Undef doesn't include supertype Value | Undef"); -ok($Str_or_Undef->includes_type($Str_or_Undef), "Str | Undef includes Str | Undef"); -ok(!$Str_or_Undef->includes_type($Int_or_ClassName), "Str | Undef doesn't include Int | ClassName"); - -ok($Value_or_Undef->includes_type($Value), "Value | Undef includes Value"); -ok($Value_or_Undef->includes_type($Undef), "Value | Undef includes Undef"); -ok(!$Value_or_Undef->includes_type($Item), "Value | Undef doesn't include supertype Item"); -ok($Value_or_Undef->includes_type($Str), "Value | Undef includes subtype Str"); -ok($Value_or_Undef->includes_type($ClassName), "Value | Undef includes subtype ClassName"); -ok($Value_or_Undef->includes_type($Num), "Value | Undef includes subtype Num"); -ok($Value_or_Undef->includes_type($Int), "Value | Undef includes subtype Int"); -ok($Value_or_Undef->includes_type($Str_or_Undef), "Value | Undef includes Str | Undef"); -ok($Value_or_Undef->includes_type($Value_or_Undef), "Value | Undef includes Value | Undef"); -ok($Value_or_Undef->includes_type($Int_or_ClassName), "Value | Undef includes Int | ClassName"); - -ok($Int_or_ClassName->includes_type($Int), "Int | ClassName includes Int"); -ok($Int_or_ClassName->includes_type($ClassName), "Int | ClassName includes ClassName"); -ok(!$Int_or_ClassName->includes_type($Str), "Int | ClassName doesn't include supertype Str"); -ok(!$Int_or_ClassName->includes_type($Undef), "Int | ClassName doesn't include Undef"); -ok(!$Int_or_ClassName->includes_type($Item), "Int | ClassName doesn't include supertype Item"); -ok(!$Int_or_ClassName->includes_type($Value), "Int | ClassName doesn't include supertype Value"); -ok(!$Int_or_ClassName->includes_type($Num), "Int | ClassName doesn't include supertype Num"); -ok(!$Int_or_ClassName->includes_type($Str_or_Undef), "Int | ClassName doesn't include Str | Undef"); -ok(!$Int_or_ClassName->includes_type($Value_or_Undef), "Int | ClassName doesn't include Value | Undef"); -ok($Int_or_ClassName->includes_type($Int_or_ClassName), "Int | ClassName includes Int | ClassName"); -