6 use Test::More tests => 24;
10 use_ok('Moose::Util::TypeConstraints');
17 has 'array' => (is => 'ro');
18 has 'hash' => (is => 'ro');
23 => where { $_->isa('HTTPHeader') };
27 => via { HTTPHeader->new(array => $_[0]) }
29 => via { HTTPHeader->new(hash => $_[0]) };
32 Moose::Util::TypeConstraints->export_type_constraints_as_functions();
34 my $header = HTTPHeader->new();
35 isa_ok($header, 'HTTPHeader');
37 ok(Header($header), '... this passed the type test');
38 ok(!Header([]), '... this did not pass the type test');
39 ok(!Header({}), '... this did not pass the type test');
41 my $anon_type = subtype Object => where { $_->isa('HTTPHeader') };
46 => via { HTTPHeader->new(array => $_[0]) }
48 => via { HTTPHeader->new(hash => $_[0]) };
49 } 'coercion of anonymous subtype succeeds';
51 foreach my $coercion (
52 find_type_constraint('Header')->coercion,
56 my $coercion = find_type_constraint('Header')->coercion;
57 isa_ok($coercion, 'Moose::Meta::TypeCoercion');
60 my $coerced = $coercion->coerce([ 1, 2, 3 ]);
61 isa_ok($coerced, 'HTTPHeader');
66 '... got the right array');
67 is($coerced->hash(), undef, '... nothing assigned to the hash');
71 my $coerced = $coercion->coerce({ one => 1, two => 2, three => 3 });
72 isa_ok($coerced, 'HTTPHeader');
76 { one => 1, two => 2, three => 3 },
77 '... got the right hash');
78 is($coerced->array(), undef, '... nothing assigned to the array');
82 my $scalar_ref = \(my $var);
83 my $coerced = $coercion->coerce($scalar_ref);
84 is($coerced, $scalar_ref, '... got back what we put in');
88 my $coerced = $coercion->coerce("Foo");
89 is($coerced, "Foo", '... got back what we put in');