7 my @types = qw/Any Item Bool Undef Defined Value Num Int Str ClassName
8 Ref ScalarRef ArrayRef HashRef CodeRef RegexpRef GlobRef
12 undef , [qw/Any Item Undef Bool/],
13 0 => [qw/Any Item Defined Bool Value Num Int Str/],
14 1 => [qw/Any Item Defined Bool Value Num Int Str/],
15 1.5 => [qw/Any Item Defined Value Num Str/],
16 '' => [qw/Any Item Defined Bool Value Str/],
17 't' => [qw/Any Item Defined Value Str/],
18 'f' => [qw/Any Item Defined Value Str/],
19 'undef' => [qw/Any Item Defined Value Str/],
20 'Test::More' => [qw/Any Item Defined Value Str ClassName/],
21 \undef => [qw/Any Item Defined Ref ScalarRef/],
22 \1 => [qw/Any Item Defined Ref ScalarRef/],
23 \"foo" => [qw/Any Item Defined Ref ScalarRef/],
24 [], => [qw/Any Item Defined Ref ArrayRef/],
25 [undef, \1] => [qw/Any Item Defined Ref ArrayRef/],
26 {} => [qw/Any Item Defined Ref HashRef/],
27 sub { die } => [qw/Any Item Defined Ref CodeRef/],
28 qr/.*/ => [qw/Any Item Defined Ref RegexpRef/],
29 \*STDOUT => [qw/Any Item Defined Ref GlobRef FileHandle/],
30 Test::Builder->new => [qw/Any Item Defined Ref Object/],
35 for (my $i = 1; $i < @type_values; $i += 2) {
36 my ($value, $valid_types) = @type_values[$i-1, $i];
37 my %is_invalid = map { $_ => 1 } @types;
38 delete @is_invalid{@$valid_types};
40 push @{ $values_for_type{$_}{invalid} }, $value
41 for grep { $is_invalid{$_} } @types;
43 push @{ $values_for_type{$_}{valid} }, $value
44 for grep { !$is_invalid{$_} } @types;
48 $plan += 5 * @{ $values_for_type{$_}{valid} || [] } for @types;
49 $plan += 4 * @{ $values_for_type{$_}{invalid} || [] } for @types;
58 for my $type (@types) {
66 can_ok(Class => @types);
68 for my $type (@types) {
69 for my $value (@{ $values_for_type{$type}{valid} }) {
71 my $via_new = Class->new($type => $value);
72 is_deeply($via_new->$type, $value, "correctly set a $type in the constructor");
76 my $via_set = Class->new;
77 is($via_set->$type, undef, "initially unset");
78 $via_set->$type($value);
79 is_deeply($via_set->$type, $value, "correctly set a $type in the setter");
83 for my $value (@{ $values_for_type{$type}{invalid} }) {
84 my $display = defined($value) ? $value : 'undef';
87 $via_new = Class->new($type => $value);
88 } qr/Attribute \($type\) does not pass the type constraint because: Validation failed for '$type' failed with value \Q$display\E/;
89 is($via_new, undef, "no object created");
91 my $via_set = Class->new;
93 $via_set->$type($value);
94 } qr/Attribute \($type\) does not pass the type constraint because: Validation failed for '$type' failed with value \Q$display\E/;
96 is($via_set->$type, undef, "value for $type not set");