6 use Test::More tests => 14;
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]) };
33 package Math::BigFloat;
34 sub new { bless { }, shift }; # not a moose class ;-)
37 subtype "Math::BigFloat"
38 => as "Math::BigFloat"
41 coerce "Math::BigFloat"
43 => via { Math::BigFloat->new( $_ ) };
46 Moose::Util::TypeConstraints->export_type_contstraints_as_functions();
48 my $header = HTTPHeader->new();
49 isa_ok($header, 'HTTPHeader');
51 ok(Header($header), '... this passed the type test');
52 ok(!Header([]), '... this did not pass the type test');
53 ok(!Header({}), '... this did not pass the type test');
55 my $coercion = find_type_constraint('Header')->coercion;
56 isa_ok($coercion, 'Moose::Meta::TypeCoercion');
59 my $coerced = $coercion->coerce([ 1, 2, 3 ]);
60 isa_ok($coerced, 'HTTPHeader');
65 '... got the right array');
66 is($coerced->hash(), undef, '... nothing assigned to the hash');
70 my $coerced = $coercion->coerce({ one => 1, two => 2, three => 3 });
71 isa_ok($coerced, 'HTTPHeader');
75 { one => 1, two => 2, three => 3 },
76 '... got the right hash');
77 is($coerced->array(), undef, '... nothing assigned to the array');
81 my $scalar_ref = \(my $var);
82 my $coerced = $coercion->coerce($scalar_ref);
83 is($coerced, $scalar_ref, '... got back what we put in');
87 my $coerced = $coercion->coerce("Foo");
88 is($coerced, "Foo", '... got back what we put in');