6 use Test::More tests => 14;
10 use_ok('Moose::Util::TypeConstraints');
19 has 'array' => (is => 'ro');
20 has 'hash' => (is => 'ro');
25 => where { $_->isa('HTTPHeader') };
29 => via { HTTPHeader->new(array => $_[0]) }
31 => via { HTTPHeader->new(hash => $_[0]) };
35 package Math::BigFloat;
36 sub new { bless { }, shift }; # not a moose class ;-)
39 subtype "Math::BigFloat"
40 => as "Math::BigFloat"
43 coerce "Math::BigFloat"
45 => via { Math::BigFloat->new( $_ ) };
48 Moose::Util::TypeConstraints->export_type_contstraints_as_functions();
50 my $header = HTTPHeader->new();
51 isa_ok($header, 'HTTPHeader');
53 ok(Header($header), '... this passed the type test');
54 ok(!Header([]), '... this did not pass the type test');
55 ok(!Header({}), '... this did not pass the type test');
57 my $coercion = find_type_constraint('Header')->coercion;
58 isa_ok($coercion, 'Moose::Meta::TypeCoercion');
61 my $coerced = $coercion->coerce([ 1, 2, 3 ]);
62 isa_ok($coerced, 'HTTPHeader');
67 '... got the right array');
68 is($coerced->hash(), undef, '... nothing assigned to the hash');
72 my $coerced = $coercion->coerce({ one => 1, two => 2, three => 3 });
73 isa_ok($coerced, 'HTTPHeader');
77 { one => 1, two => 2, three => 3 },
78 '... got the right hash');
79 is($coerced->array(), undef, '... nothing assigned to the array');
83 my $scalar_ref = \(my $var);
84 my $coerced = $coercion->coerce($scalar_ref);
85 is($coerced, $scalar_ref, '... got back what we put in');
89 my $coerced = $coercion->coerce("Foo");
90 is($coerced, "Foo", '... got back what we put in');