6 use Test::More tests => 8; # tests => 26;
13 use_ok('Mouse::Util::TypeConstraints');
20 has 'array' => (is => 'ro');
21 has 'hash' => (is => 'ro');
26 => where { $_->isa('HTTPHeader') };
30 => via { HTTPHeader->new(array => $_[0]) }
32 => via { HTTPHeader->new(hash => $_[0]) };
35 Mouse::Util::TypeConstraints->export_type_constraints_as_functions();
37 my $header = HTTPHeader->new();
38 isa_ok($header, 'HTTPHeader');
40 ok(Header($header), '... this passed the type test');
41 ok(!Header([]), '... this did not pass the type test');
42 ok(!Header({}), '... this did not pass the type test');
44 my $anon_type = subtype Object => where { $_->isa('HTTPHeader') };
49 => via { HTTPHeader->new(array => $_[0]) }
51 => via { HTTPHeader->new(hash => $_[0]) };
52 } 'coercion of anonymous subtype succeeds';
56 foreach my $coercion (
57 find_type_constraint('Header')->coercion,
60 isa_ok($coercion, 'Mouse::Meta::TypeCoercion');
63 my $coerced = $coercion->coerce([ 1, 2, 3 ]);
64 isa_ok($coerced, 'HTTPHeader');
69 '... got the right array');
70 is($coerced->hash(), undef, '... nothing assigned to the hash');
74 my $coerced = $coercion->coerce({ one => 1, two => 2, three => 3 });
75 isa_ok($coerced, 'HTTPHeader');
79 { one => 1, two => 2, three => 3 },
80 '... got the right hash');
81 is($coerced->array(), undef, '... nothing assigned to the array');
85 my $scalar_ref = \(my $var);
86 my $coerced = $coercion->coerce($scalar_ref);
87 is($coerced, $scalar_ref, '... got back what we put in');
91 my $coerced = $coercion->coerce("Foo");
92 is($coerced, "Foo", '... got back what we put in');
98 subtype 'StrWithTrailingX'
102 coerce 'StrWithTrailingX'
106 my $tc = find_type_constraint('StrWithTrailingX');
107 is($tc->coerce("foo"), "fooX", "coerce when needed");
108 is($tc->coerce("fooX"), "fooX", "do not coerce when unneeded");