MooseX-Types-DateTime-0.08/0000755000175000017500000000000012061623520014760 5ustar ilmariilmariMooseX-Types-DateTime-0.08/Changes0000644000175000017500000000173012061622266016262 0ustar ilmariilmari0.08 2012-12-11 12:18:56 Europe/London - Require perl 5.8.3, as Moose does 0.07 2011-12-12 12:58:19 Europe/London - Provide optimize_as for pre-2.0100 Moose versions - Bump MooseX::Types version requirement (RT#73188) - Add missing dependencies - Enforce version dependencies at runtime (RT#73189) 0.06 - Use inline_as instead of the deprecated optimize_as 0.05 - Merged the two 0.04 releases 0.04 (NUFFIN) - Remove DateTimeX::Easy support, this is in its own distribution now 0.04 (FLORA) - Depend on DateTime::TimeZone 0.95 to avoid test failures due to broken, older versions. 0.03 - more explicit versions for dependencies - removed a test that doesn't seem to cleanly pass in all timezones 0.02 - Use namespace::clean in some places - Try to skip out of the test suite gracefully when bad crap happens (too much DWIM--) 0.01 - Initial version MooseX-Types-DateTime-0.08/META.yml0000664000175000017500000000140012061623520016226 0ustar ilmariilmari--- abstract: unknown author: - unknown build_requires: ExtUtils::MakeMaker: 0 configure_requires: ExtUtils::MakeMaker: 0 dynamic_config: 1 generated_by: 'ExtUtils::MakeMaker version 6.6302, CPAN::Meta::Converter version 2.120630' license: unknown meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 name: MooseX-Types-DateTime no_index: directory: - t - inc requires: DateTime: 0.4302 DateTime::Duration: 0.4302 DateTime::Locale: 0.4001 DateTime::TimeZone: 0.95 Moose: 0.41 MooseX::Types: 0.30 MooseX::Types::Moose: 0.30 Test::Exception: 0.27 Test::use::ok: 0.02 namespace::clean: 0.08 perl: 5.0008003 resources: repository: git://git.moose.perl.org/MooseX-Types-DateTime.git version: 0.08 MooseX-Types-DateTime-0.08/MANIFEST0000644000175000017500000000043512061623520016113 0ustar ilmariilmari.gitignore Changes lib/MooseX/Types/DateTime.pm Makefile.PL MANIFEST This list of files MANIFEST.SKIP t/01_basic.t META.yml Module YAML meta-data (added by MakeMaker) META.json Module JSON meta-data (added by MakeMaker) MooseX-Types-DateTime-0.08/lib/0000755000175000017500000000000012061623520015526 5ustar ilmariilmariMooseX-Types-DateTime-0.08/lib/MooseX/0000755000175000017500000000000012061623520016740 5ustar ilmariilmariMooseX-Types-DateTime-0.08/lib/MooseX/Types/0000755000175000017500000000000012061623520020044 5ustar ilmariilmariMooseX-Types-DateTime-0.08/lib/MooseX/Types/DateTime.pm0000644000175000017500000001162412061622204022100 0ustar ilmariilmari#!/usr/bin/perl package MooseX::Types::DateTime; use strict; use warnings; our $VERSION = "0.08"; use Moose 0.41 (); use DateTime 0.4302 (); use DateTime::Duration 0.4302 (); use DateTime::Locale 0.4001 (); use DateTime::TimeZone 0.95 (); use MooseX::Types::Moose 0.30 qw/Num HashRef Str/; use namespace::clean 0.08; use MooseX::Types 0.30 -declare => [qw( DateTime Duration TimeZone Locale Now )]; class_type "DateTime"; class_type "DateTime::Duration"; class_type "DateTime::TimeZone"; class_type "DateTime::Locale::root" => { name => "DateTime::Locale" }; subtype DateTime, as 'DateTime'; subtype Duration, as 'DateTime::Duration'; subtype TimeZone, as 'DateTime::TimeZone'; subtype Locale, as 'DateTime::Locale'; subtype( Now, as Str, where { $_ eq 'now' }, ($Moose::VERSION >= 2.0100 ? Moose::Util::TypeConstraints::inline_as { 'no warnings "uninitialized";'. '!ref(' . $_[1] . ') and '. $_[1] .' eq "now"'; } : Moose::Util::TypeConstraints::optimize_as { no warnings 'uninitialized'; !ref($_[0]) and $_[0] eq 'now'; } ), ); our %coercions = ( DateTime => [ from Num, via { 'DateTime'->from_epoch( epoch => $_ ) }, from HashRef, via { 'DateTime'->new( %$_ ) }, from Now, via { 'DateTime'->now }, ], "DateTime::Duration" => [ from Num, via { DateTime::Duration->new( seconds => $_ ) }, from HashRef, via { DateTime::Duration->new( %$_ ) }, ], "DateTime::TimeZone" => [ from Str, via { DateTime::TimeZone->new( name => $_ ) }, ], "DateTime::Locale" => [ from Moose::Util::TypeConstraints::find_or_create_isa_type_constraint("Locale::Maketext"), via { DateTime::Locale->load($_->language_tag) }, from Str, via { DateTime::Locale->load($_) }, ], ); for my $type ( "DateTime", DateTime ) { coerce $type => @{ $coercions{DateTime} }; } for my $type ( "DateTime::Duration", Duration ) { coerce $type => @{ $coercions{"DateTime::Duration"} }; } for my $type ( "DateTime::TimeZone", TimeZone ) { coerce $type => @{ $coercions{"DateTime::TimeZone"} }; } for my $type ( "DateTime::Locale", Locale ) { coerce $type => @{ $coercions{"DateTime::Locale"} }; } __PACKAGE__ __END__ =pod =head1 NAME MooseX::Types::DateTime - L related constraints and coercions for Moose =head1 SYNOPSIS Export Example: use MooseX::Types::DateTime qw(TimeZone); has time_zone => ( isa => TimeZone, is => "rw", coerce => 1, ); Class->new( time_zone => "Africa/Timbuktu" ); Namespaced Example: use MooseX::Types::DateTime; has time_zone => ( isa => 'DateTime::TimeZone', is => "rw", coerce => 1, ); Class->new( time_zone => "Africa/Timbuktu" ); =head1 DESCRIPTION This module packages several L with coercions, designed to work with the L suite of objects. =head1 CONSTRAINTS =over 4 =item L A class type for L. =over 4 =item from C Uses L. Floating values will be used for subsecond percision, see L for details. =item from C Calls L with the hash entries as arguments. =back =item L A class type for L =over 4 =item from C Uses L and passes the number as the C argument. Note that due to leap seconds, DST changes etc this may not do what you expect. For instance passing in C<86400> is not always equivalent to one day, although there are that many seconds in a day. See L for more details. =item from C Calls L with the hash entries as arguments. =back =item L A class type for L with the name L. =over 4 =item from C The string is treated as a language tag (e.g. C or C) and given to L. =item from L The C attribute will be used with L. =item L A class type for L. =over 4 =item from C Treated as a time zone name or offset. See L for more details on the allowed values. Delegates to L with the string as the C argument. =back =back =back =head1 SEE ALSO L L, L =head1 VERSION CONTROL This module is maintained using git. You can get the latest version from L. =head1 AUTHOR Yuval Kogman Enothingmuch@woobling.orgE John Napiorkowski Ejjn1056 at yahoo.comE =head1 COPYRIGHT Copyright (c) 2008 Yuval Kogman. All rights reserved This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut MooseX-Types-DateTime-0.08/Makefile.PL0000644000175000017500000000152712061623330016736 0ustar ilmariilmari#!/usr/bin/perl -w use strict; use ExtUtils::MakeMaker; WriteMakefile( NAME => 'MooseX::Types::DateTime', VERSION_FROM => 'lib/MooseX/Types/DateTime.pm', INSTALLDIRS => 'site', PL_FILES => { }, MIN_PERL_VERSION => 5.0008003, PREREQ_PM => { 'Moose' => '0.41', # class_type 'DateTime' => '0.4302', 'DateTime::Duration' => '0.4302', 'DateTime::Locale' => '0.4001', 'DateTime::TimeZone' => '0.95', 'Test::use::ok' => '0.02', 'Test::Exception' => '0.27', 'namespace::clean' => '0.08', 'MooseX::Types' => '0.30', 'MooseX::Types::Moose' => '0.30', }, META_MERGE => { resources => { repository => 'git://git.moose.perl.org/MooseX-Types-DateTime.git', }, }, ); MooseX-Types-DateTime-0.08/META.json0000664000175000017500000000253012061623520016403 0ustar ilmariilmari{ "abstract" : "unknown", "author" : [ "unknown" ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 6.6302, CPAN::Meta::Converter version 2.120630", "license" : [ "unknown" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "MooseX-Types-DateTime", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "runtime" : { "requires" : { "DateTime" : "0.4302", "DateTime::Duration" : "0.4302", "DateTime::Locale" : "0.4001", "DateTime::TimeZone" : "0.95", "Moose" : "0.41", "MooseX::Types" : "0.30", "MooseX::Types::Moose" : "0.30", "Test::Exception" : "0.27", "Test::use::ok" : "0.02", "namespace::clean" : "0.08", "perl" : "5.0008003" } } }, "release_status" : "stable", "resources" : { "repository" : { "url" : "git://git.moose.perl.org/MooseX-Types-DateTime.git" } }, "version" : "0.08" } MooseX-Types-DateTime-0.08/t/0000755000175000017500000000000012061623520015223 5ustar ilmariilmariMooseX-Types-DateTime-0.08/t/01_basic.t0000644000175000017500000000646111671370205017005 0ustar ilmariilmari#!/usr/bin/perl use strict; use warnings; use Test::More 'no_plan'; use Test::Exception; use ok 'MooseX::Types::DateTime'; use Moose::Util::TypeConstraints; isa_ok( find_type_constraint($_), "Moose::Meta::TypeConstraint" ) for qw(DateTime DateTime::TimeZone DateTime::Locale); { { package Foo; use Moose; has date => ( isa => "DateTime", is => "rw", coerce => 1, ); } my $epoch = time; my $coerced = Foo->new( date => $epoch )->date; isa_ok( $coerced, "DateTime", "coerced epoch into datetime" ); is( $coerced->epoch, $epoch, "epoch is correct" ); isa_ok( Foo->new( date => { year => 2000, month => 1, day => 1 } )->date, "DateTime" ); isa_ok( Foo->new( date => 'now' )->date, "DateTime" ); throws_ok { Foo->new( date => "junk1!!" ) } qr/DateTime/, "constraint"; } { { package Quxx; use Moose; has duration => ( isa => "DateTime::Duration", is => "rw", coerce => 1, ); } my $coerced = Quxx->new( duration => 10 )->duration; isa_ok( $coerced, "DateTime::Duration", "coerced from seconds" ); my $time = time; my $now = DateTime->from_epoch( epoch => $time ); my $future = $now + $coerced; is( $future->epoch, ( $time + 10 ), "coerced value" ); isa_ok( Quxx->new( duration => { minutes => 2 } )->duration, "DateTime::Duration", "coerced from hash" ); throws_ok { Quxx->new( duration => "ahdstkljhat" ) } qr/DateTime/, "constraint"; } { { package Bar; use Moose; has time_zone => ( isa => "DateTime::TimeZone", is => "rw", coerce => 1, ); } my $tz = Bar->new( time_zone => "Africa/Timbuktu" )->time_zone; isa_ok( $tz, "DateTime::TimeZone", "coerced string into time zone object" ); like( $tz->name, qr/^Africa/, "correct time zone" ); dies_ok { Bar->new( time_zone => "Space/TheMoon" ) } "bad time zone"; } { { package Gorch; use Moose; has loc => ( isa => "DateTime::Locale", is => "rw", coerce => 1, ); } my $loc = Gorch->new( loc => "he_IL" )->loc; isa_ok( $loc, "DateTime::Locale::he", "coerced from string" ); dies_ok { Gorch->new( loc => "not_a_place_or_a_locale" ) } "bad locale name"; SKIP: { skip "No Locale::Maketext", 2 unless eval { require Locale::Maketext }; { package Some::L10N; our @ISA = qw(Locale::Maketext); package Some::L10N::ja; our @ISA = qw(Some::L10N); our %Lexicon = ( goodbye => "sayonara", ); } my $handle = Some::L10N->get_handle("ja"); isa_ok( $handle, "Some::L10N", "maketext handle" ); isa_ok( Gorch->new( loc => $handle )->loc, "DateTime::Locale::ja", "coerced from maketext" );; } } { { package Gondor; use Moose; use MooseX::Types::DateTime qw(DateTime Duration); has 'date' => (is=>'rw', isa=>DateTime, coerce=>1); has 'duration' => (is=>'rw', isa=>Duration, coerce=>1); } my $epoch = time; ok my $gondor = Gondor->new(date=>$epoch, duration=>10) => 'Instantiated object using export types'; } MooseX-Types-DateTime-0.08/.gitignore0000644000175000017500000000022511662740750016762 0ustar ilmariilmari.* !.gitignore Makefile* !Makefile.PL META.* blib build inc pm_to_blib MANIFEST* !MANIFEST.SKIP Debian* README MooseX-Types-DateTime-* *.bs MYMETA.* MooseX-Types-DateTime-0.08/MANIFEST.SKIP0000644000175000017500000000107611662743316016676 0ustar ilmariilmari# Avoid version control files. \bRCS\b \bCVS\b \bSCCS\b ,v$ \B\.svn\b \B\.git\b \b_darcs\b # Avoid Makemaker generated and utility files. \bMANIFEST\.bak \bMakefile$ \bblib/ \bMakeMaker-\d \bpm_to_blib\.ts$ \bpm_to_blib$ \bblibdirs\.ts$ # 6.18 through 6.25 generated this # Avoid Module::Build generated and utility files. \bBuild$ \b_build/ # Avoid temp and backup files. ~$ \.old$ \#$ \b\.# \.bak$ # Avoid Devel::Cover files. \bcover_db\b ### DEFAULT MANIFEST.SKIP ENDS HERE #### \.DS_Store$ \.sw.$ (\w+-)*(\w+)-\d\.\d+(?:\.tar\.gz)?\b \.t\.log$ ^MYMETA\.