6 eval "use MooseX::Types::DateTime";
8 ? ( skip_all => "Tests require MooseX::Types::DateTime" )
13 ## Normalize a HashRef
14 package Test::MooseX::Meta::TypeConstraint::Structured::Examples::Normalize;
18 use MooseX::Types::Structured qw(Dict Tuple);
19 use MooseX::Types::DateTime qw(DateTime);
20 use MooseX::Types::Moose qw(Int Str Object ArrayRef HashRef);
21 use MooseX::Types -declare => [qw(
22 Name Age Person FullName
26 ## So that our test works, we'll set Now to 2008.
28 return 'DateTime'->new(year=>2008);
32 as Dict[last=>Str, first=>Str];
35 as Dict[name=>Str, age=>Int];
38 from Dict[first=>Str, last=>Str, years=>Int],
40 name => "$_->{first} $_->{last}",
43 from Dict[fullname=>FullName, dob=>DateTime],
45 name => "$_->{fullname}{first} $_->{fullname}{last}",
46 age => ($_->{dob} - Now)->years,
49 has person => (is=>'rw', isa=>Person, coerce=>1);
53 ok my $normalize = Test::MooseX::Meta::TypeConstraint::Structured::Examples::Normalize->new();
54 isa_ok $normalize, 'Test::MooseX::Meta::TypeConstraint::Structured::Examples::Normalize';
56 ok $normalize->person({name=>'John', age=>25})
59 is_deeply $normalize->person, {name=>'John', age=>25}
60 => 'Value is correct';
62 ok $normalize->person({first=>'John', last=>'Napiorkowski', years=>35})
65 is_deeply $normalize->person, {name=>'John Napiorkowski', age=>35}
66 => 'Value is correct';
68 ok $normalize->person({years=>36, last=>'Napiorkowski', first=>'John'})
71 is_deeply $normalize->person, {name=>'John Napiorkowski', age=>36}
72 => 'Value is correct';
74 ok $normalize->person({fullname=>{first=>'Vanessa', last=>'Li'}, dob=>DateTime->new(year=>1974)})
77 is_deeply $normalize->person, {name=>'Vanessa Li', age=>34}
78 => 'Value is correct';