6 use Test::More 'no_plan';
9 use ok 'MooseX::Types::DateTime';
11 use Moose::Util::TypeConstraints;
13 isa_ok( find_type_constraint($_), "Moose::Meta::TypeConstraint" ) for qw(DateTime DateTime::TimeZone DateTime::Locale);
29 my $coerced = Foo->new( date => $epoch )->date;
31 isa_ok( $coerced, "DateTime", "coerced epoch into datetime" );
33 is( $coerced->epoch, $epoch, "epoch is correct" );
35 isa_ok( Foo->new( date => { year => 2000, month => 1, day => 1 } )->date, "DateTime" );
37 isa_ok( Foo->new( date => 'now' )->date, "DateTime" );
39 throws_ok { Foo->new( date => "junk1!!" ) } qr/DateTime/, "constraint";
48 isa => "DateTime::Duration",
54 my $coerced = Quxx->new( duration => 10 )->duration;
56 isa_ok( $coerced, "DateTime::Duration", "coerced from seconds" );
60 my $now = DateTime->from_epoch( epoch => $time );
62 my $future = $now + $coerced;
64 is( $future->epoch, ( $time + 10 ), "coerced value" );
66 isa_ok( Quxx->new( duration => { minutes => 2 } )->duration, "DateTime::Duration", "coerced from hash" );
68 throws_ok { Quxx->new( duration => "ahdstkljhat" ) } qr/DateTime/, "constraint";
77 isa => "DateTime::TimeZone",
83 my $tz = Bar->new( time_zone => "Africa/Timbuktu" )->time_zone;
85 isa_ok( $tz, "DateTime::TimeZone", "coerced string into time zone object" );
87 like( $tz->name, qr/^Africa/, "correct time zone" );
89 dies_ok { Bar->new( time_zone => "Space/TheMoon" ) } "bad time zone";
98 isa => "DateTime::Locale",
104 my $loc = Gorch->new( loc => "he_IL" )->loc;
106 isa_ok( $loc, "DateTime::Locale::he", "coerced from string" );
108 dies_ok { Gorch->new( loc => "not_a_place_or_a_locale" ) } "bad locale name";
111 skip "No Locale::Maketext", 2 unless eval { require Locale::Maketext };
115 our @ISA = qw(Locale::Maketext);
117 package Some::L10N::ja;
118 our @ISA = qw(Some::L10N);
121 goodbye => "sayonara",
125 my $handle = Some::L10N->get_handle("ja");
127 isa_ok( $handle, "Some::L10N", "maketext handle" );
129 isa_ok( Gorch->new( loc => $handle )->loc, "DateTime::Locale::ja", "coerced from maketext" );;
138 use MooseX::Types::DateTime qw(DateTime Duration);
140 has 'date' => (is=>'rw', isa=>DateTime, coerce=>1);
141 has 'duration' => (is=>'rw', isa=>Duration, coerce=>1);
147 ok my $gondor = Gondor->new(date=>$epoch, duration=>10)
148 => 'Instantiated object using export types';