r35922 - in /branches/upstream/libmoosex-types-datetime-perl: ./ current/ current/lib/ current/lib/MooseX/ current/lib/MooseX/Types/ current/t/

ryan52-guest at users.alioth.debian.org ryan52-guest at users.alioth.debian.org
Wed May 20 01:13:07 UTC 2009


Author: ryan52-guest
Date: Wed May 20 01:13:02 2009
New Revision: 35922

URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=35922
Log:
[svn-inject] Installing original source of libmoosex-types-datetime-perl

Added:
    branches/upstream/libmoosex-types-datetime-perl/
    branches/upstream/libmoosex-types-datetime-perl/current/
    branches/upstream/libmoosex-types-datetime-perl/current/Changes   (with props)
    branches/upstream/libmoosex-types-datetime-perl/current/MANIFEST
    branches/upstream/libmoosex-types-datetime-perl/current/MANIFEST.SKIP
    branches/upstream/libmoosex-types-datetime-perl/current/META.yml
    branches/upstream/libmoosex-types-datetime-perl/current/Makefile.PL
    branches/upstream/libmoosex-types-datetime-perl/current/SIGNATURE
    branches/upstream/libmoosex-types-datetime-perl/current/lib/
    branches/upstream/libmoosex-types-datetime-perl/current/lib/MooseX/
    branches/upstream/libmoosex-types-datetime-perl/current/lib/MooseX/Types/
    branches/upstream/libmoosex-types-datetime-perl/current/lib/MooseX/Types/DateTime.pm
    branches/upstream/libmoosex-types-datetime-perl/current/lib/MooseX/Types/DateTimeX.pm   (with props)
    branches/upstream/libmoosex-types-datetime-perl/current/t/
    branches/upstream/libmoosex-types-datetime-perl/current/t/01_basic.t
    branches/upstream/libmoosex-types-datetime-perl/current/t/02_datetimex.t   (with props)

Added: branches/upstream/libmoosex-types-datetime-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmoosex-types-datetime-perl/current/Changes?rev=35922&op=file
==============================================================================
--- branches/upstream/libmoosex-types-datetime-perl/current/Changes (added)
+++ branches/upstream/libmoosex-types-datetime-perl/current/Changes Wed May 20 01:13:02 2009
@@ -1,0 +1,10 @@
+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

Propchange: branches/upstream/libmoosex-types-datetime-perl/current/Changes
------------------------------------------------------------------------------
    svn:executable = 

Added: branches/upstream/libmoosex-types-datetime-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmoosex-types-datetime-perl/current/MANIFEST?rev=35922&op=file
==============================================================================
--- branches/upstream/libmoosex-types-datetime-perl/current/MANIFEST (added)
+++ branches/upstream/libmoosex-types-datetime-perl/current/MANIFEST Wed May 20 01:13:02 2009
@@ -1,0 +1,10 @@
+Changes
+lib/MooseX/Types/DateTime.pm
+lib/MooseX/Types/DateTimeX.pm
+Makefile.PL
+MANIFEST			This list of files
+MANIFEST.SKIP
+t/01_basic.t
+t/02_datetimex.t
+META.yml                                 Module meta-data (added by MakeMaker)
+SIGNATURE                                Public-key signature (added by MakeMaker)

Added: branches/upstream/libmoosex-types-datetime-perl/current/MANIFEST.SKIP
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmoosex-types-datetime-perl/current/MANIFEST.SKIP?rev=35922&op=file
==============================================================================
--- branches/upstream/libmoosex-types-datetime-perl/current/MANIFEST.SKIP (added)
+++ branches/upstream/libmoosex-types-datetime-perl/current/MANIFEST.SKIP Wed May 20 01:13:02 2009
@@ -1,0 +1,39 @@
+# 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)?$
+
+\.t\.log$

Added: branches/upstream/libmoosex-types-datetime-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmoosex-types-datetime-perl/current/META.yml?rev=35922&op=file
==============================================================================
--- branches/upstream/libmoosex-types-datetime-perl/current/META.yml (added)
+++ branches/upstream/libmoosex-types-datetime-perl/current/META.yml Wed May 20 01:13:02 2009
@@ -1,0 +1,25 @@
+--- #YAML:1.0
+name:                MooseX-Types-DateTime
+version:             0.03
+abstract:            ~
+license:             ~
+author:              ~
+generated_by:        ExtUtils::MakeMaker version 6.44
+distribution_type:   module
+requires:     
+    DateTime:                      0.4302
+    DateTime::Format::DateParse:   0.04
+    DateTime::Format::Flexible:    0.05
+    DateTime::Format::Natural:     0.71
+    DateTime::Locale:              0.4001
+    DateTime::TimeZone:            0.7701
+    DateTimeX::Easy:               0.082
+    Moose:                         0.41
+    MooseX::Types:                 0.04
+    namespace::clean:              0.08
+    Test::Exception:               0.27
+    Test::use::ok:                 0.02
+    Time::Duration::Parse:         0.06
+meta-spec:
+    url:     http://module-build.sourceforge.net/META-spec-v1.3.html
+    version: 1.3

Added: branches/upstream/libmoosex-types-datetime-perl/current/Makefile.PL
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmoosex-types-datetime-perl/current/Makefile.PL?rev=35922&op=file
==============================================================================
--- branches/upstream/libmoosex-types-datetime-perl/current/Makefile.PL (added)
+++ branches/upstream/libmoosex-types-datetime-perl/current/Makefile.PL Wed May 20 01:13:02 2009
@@ -1,0 +1,29 @@
+#!/usr/bin/perl -w
+
+use strict;
+
+use ExtUtils::MakeMaker;
+
+WriteMakefile(
+    NAME         => 'MooseX::Types::DateTime',
+    VERSION_FROM => 'lib/MooseX/Types/DateTime.pm',
+    INSTALLDIRS  => 'site',
+    SIGN         => 1,
+    PL_FILES     => { },
+    PREREQ_PM => {
+        'Moose'              => '0.41', # class_type
+        'DateTime'           => '0.4302',
+        'DateTime::Locale'   => '0.4001',
+        'DateTime::TimeZone' => '0.7701',
+        'Test::use::ok'      => '0.02',
+        'Test::Exception'    => '0.27',
+        'MooseX::Types'      => '0.04',
+		'DateTime::Format::DateParse' => '0.04',
+		'DateTime::Format::Natural' => '0.71',
+		'DateTime::Format::Flexible' => '0.05',
+        'DateTimeX::Easy'    => '0.082',
+        'Time::Duration::Parse' => '0.06',
+        'namespace::clean'   => '0.08',
+    },
+);
+

Added: branches/upstream/libmoosex-types-datetime-perl/current/SIGNATURE
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmoosex-types-datetime-perl/current/SIGNATURE?rev=35922&op=file
==============================================================================
--- branches/upstream/libmoosex-types-datetime-perl/current/SIGNATURE (added)
+++ branches/upstream/libmoosex-types-datetime-perl/current/SIGNATURE Wed May 20 01:13:02 2009
@@ -1,0 +1,32 @@
+This file contains message digests of all files listed in MANIFEST,
+signed via the Module::Signature module, version 0.55.
+
+To verify the content in this distribution, first make sure you have
+Module::Signature installed, then type:
+
+    % cpansign -v
+
+It will check each file's integrity, as well as the signature's
+validity.  If "==> Signature verified OK! <==" is not displayed,
+the distribution may already have been compromised, and you should
+not run its Makefile.PL or Build.PL.
+
+-----BEGIN PGP SIGNED MESSAGE-----
+Hash: SHA1
+
+SHA1 612ab25a806207a4d622792b4a9e12ff3260e6f7 Changes
+SHA1 cd833e1b49f4ae224b7b79eb09ceca2311e8ca7a MANIFEST
+SHA1 8c7f99eee1e7fdfb18c75ee7d6c1a8cefae61831 MANIFEST.SKIP
+SHA1 b0f4b25e39143e625013b4e57f3525ab1a651ec3 META.yml
+SHA1 5475dc8449e67295eb359f6bd5fd332c0c678c3e Makefile.PL
+SHA1 866c97202c127a00d73b081b7a6534da67dcfbb3 lib/MooseX/Types/DateTime.pm
+SHA1 d357782ff876cd6c277a5a19a16e34a29076a3f4 lib/MooseX/Types/DateTimeX.pm
+SHA1 5dc5b4e09efcee42e2a0ed87fe184e79a069caf1 t/01_basic.t
+SHA1 e0fb2d6f9b5a4c96f13909c8b4fa802cd159cb54 t/02_datetimex.t
+-----BEGIN PGP SIGNATURE-----
+Version: GnuPG v1.4.7 (Darwin)
+
+iD8DBQFIdsTCVCwRwOvSdBgRAp01AJ4jlNZupWrzGYlE0OjcXwdVg4IlXgCeLGkH
+8FGkNV8zYKX4aDIVdaBBJrk=
+=H15z
+-----END PGP SIGNATURE-----

Added: branches/upstream/libmoosex-types-datetime-perl/current/lib/MooseX/Types/DateTime.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmoosex-types-datetime-perl/current/lib/MooseX/Types/DateTime.pm?rev=35922&op=file
==============================================================================
--- branches/upstream/libmoosex-types-datetime-perl/current/lib/MooseX/Types/DateTime.pm (added)
+++ branches/upstream/libmoosex-types-datetime-perl/current/lib/MooseX/Types/DateTime.pm Wed May 20 01:13:02 2009
@@ -1,0 +1,212 @@
+#!/usr/bin/perl
+
+package MooseX::Types::DateTime;
+
+use strict;
+use warnings;
+
+our $VERSION = "0.03";
+
+use DateTime ();
+use DateTime::Locale ();
+use DateTime::TimeZone ();
+
+use MooseX::Types::Moose qw/Num HashRef Str/;
+
+use namespace::clean;
+
+use MooseX::Types -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::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<DateTime> 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<Moose::Util::TypeConstraints> with coercions,
+designed to work with the L<DateTime> suite of objects.
+
+=head1 CONSTRAINTS
+
+=over 4
+
+=item L<DateTime>
+
+A class type for L<DateTime>.
+
+=over 4
+
+=item from C<Num>
+
+Uses L<DateTime/from_epoch>. Floating values will be used for subsecond
+percision, see L<DateTime> for details.
+
+=item from C<HashRef>
+
+Calls L<DateTime/new> with the hash entries as arguments.
+
+=back
+
+=item L<Duration>
+
+A class type for L<DateTime::Duration>
+
+=over 4
+
+=item from C<Num>
+
+Uses L<DateTime::Duration/new> and passes the number as the C<seconds> 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<DateTime/"How Date Math is Done">
+for more details.
+
+=item from C<HashRef>
+
+Calls L<DateTime::Duration/new> with the hash entries as arguments.
+
+=back
+
+=item L<DateTime::Locale>
+
+A class type for L<DateTime::Locale::root> with the name L<DateTime::Locale>.
+
+=over 4
+
+=item from C<Str>
+
+The string is treated as a language tag (e.g. C<en> or C<he_IL>) and given to
+L<DateTime::Locale/load>.
+
+=item from L<Locale::Maktext>
+
+The C<Locale::Maketext/language_tag> attribute will be used with L<DateTime::Locale/load>.
+
+=item L<DateTime::TimeZone>
+
+A class type for L<DateTime::TimeZone>.
+
+=over 4
+
+=item from C<Str>
+
+Treated as a time zone name or offset. See L<DateTime::TimeZone/USAGE> for more
+details on the allowed values.
+
+Delegates to L<DateTime::TimeZone/new> with the string as the C<name> argument.
+
+=back
+
+=head1 SEE ALSO
+
+L<MooseX::Types::DateTimeX>
+
+L<DateTime>, L<DateTimeX::Easy>
+
+=head1 VERSION CONTROL
+
+L<http://code2.0beta.co.uk/moose/svn/MooseX-Types-DateTime/trunk>. Ask on
+#moose for commit bits.
+
+=head1 AUTHOR
+
+Yuval Kogman E<lt>nothingmuch at woobling.orgE<gt>
+
+John Napiorkowski E<lt>jjn1056 at yahoo.comE<gt>
+
+=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

Added: branches/upstream/libmoosex-types-datetime-perl/current/lib/MooseX/Types/DateTimeX.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmoosex-types-datetime-perl/current/lib/MooseX/Types/DateTimeX.pm?rev=35922&op=file
==============================================================================
--- branches/upstream/libmoosex-types-datetime-perl/current/lib/MooseX/Types/DateTimeX.pm (added)
+++ branches/upstream/libmoosex-types-datetime-perl/current/lib/MooseX/Types/DateTimeX.pm Wed May 20 01:13:02 2009
@@ -1,0 +1,102 @@
+package MooseX::Types::DateTimeX;
+
+use strict;
+use warnings;
+
+use DateTime;
+use DateTime::Duration;
+use DateTimeX::Easy; 
+use Time::Duration::Parse qw(parse_duration);
+use MooseX::Types::DateTime ();
+use MooseX::Types::Moose qw/Num HashRef Str/;
+
+use namespace::clean;
+
+use MooseX::Types -declare => [qw( DateTime Duration)];
+
+=head1 NAME
+
+MooseX::Types::DateTimeX - Extensions to L<MooseX::Types::DateTime>
+
+=head1 SYNOPSIS
+
+    package MyApp::MyClass;
+
+    use MooseX::Types::DateTimeX qw( DateTime );
+
+    has created => (
+        isa => DateTime,
+        is => "rw",
+        coerce => 1,
+    );
+
+    my $instance = MyApp::MyClass->new(created=>'January 1, 1980');
+    print $instance->created->year; # is 1980
+
+    ## Coercions from the base type continue to work as normal.
+    my $instance = MyApp::MyClass->new(created=>{year=>2000,month=>1,day=>10});
+
+Please see the test case for more example usage.
+
+=head1 DESCRIPTION
+
+This module builds on L<MooseX::Types::DateTime> to add additional custom
+types and coercions.  Since it builds on an existing type, all coercions and
+constraints are inherited.
+
+=head1 SUBTYPES
+
+This module defines the following additional subtypes.
+
+=head2 DateTime
+
+Subtype of 'DateTime'.  Adds an additional coercion from strings.
+
+Uses L<DateTimeX::Easy> to try and convert strings, like "yesterday" into a 
+valid L<DateTime> object.  Please note that due to ambiguity with how different
+systems might localize their timezone, string parsing may not always return 
+the most expected value.  IN general we try to localize to UTC whenever
+possible.  Feedback welcomed!
+
+=cut
+
+subtype DateTime, as MooseX::Types::DateTime::DateTime;
+
+coerce( DateTime,
+    @{ $MooseX::Types::DateTime::coercions{DateTime} },
+    from Str, via { DateTimeX::Easy->new($_) },
+);
+
+
+=head2 Duration
+
+Subtype of 'DateTime::Duration' that coerces from a string.  We use the module
+L<Time::Duration::Parse> to attempt this.
+
+=cut
+
+subtype Duration, as MooseX::Types::DateTime::Duration;
+
+coerce( Duration,
+    @{ $MooseX::Types::DateTime::coercions{"DateTime::Duration"} },
+    from Str, via { 
+        DateTime::Duration->new( 
+            seconds => parse_duration($_)
+        );
+    },
+);
+
+=head1 AUTHOR
+
+John Napiorkowski E<lt>jjn1056 at yahoo.comE<gt>
+
+=head1 LICENSE
+
+    Copyright (c) 2008 John Napiorkowski.
+
+    This program is free software; you can redistribute
+    it and/or modify it under the same terms as Perl itself.
+
+=cut
+
+1;

Propchange: branches/upstream/libmoosex-types-datetime-perl/current/lib/MooseX/Types/DateTimeX.pm
------------------------------------------------------------------------------
    svn:executable = 

Added: branches/upstream/libmoosex-types-datetime-perl/current/t/01_basic.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmoosex-types-datetime-perl/current/t/01_basic.t?rev=35922&op=file
==============================================================================
--- branches/upstream/libmoosex-types-datetime-perl/current/t/01_basic.t (added)
+++ branches/upstream/libmoosex-types-datetime-perl/current/t/01_basic.t Wed May 20 01:13:02 2009
@@ -1,0 +1,150 @@
+#!/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';
+
+}

Added: branches/upstream/libmoosex-types-datetime-perl/current/t/02_datetimex.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmoosex-types-datetime-perl/current/t/02_datetimex.t?rev=35922&op=file
==============================================================================
--- branches/upstream/libmoosex-types-datetime-perl/current/t/02_datetimex.t (added)
+++ branches/upstream/libmoosex-types-datetime-perl/current/t/02_datetimex.t Wed May 20 01:13:02 2009
@@ -1,0 +1,171 @@
+use strict;
+use warnings;
+
+use Test::More;
+
+BEGIN {
+    plan skip_all => "DateTime::Format::DateManip required" unless eval { require DateTime::Format::DateManip };
+    plan tests => 28;
+}
+
+use Test::Exception;
+use DateTime;
+
+use ok 'MooseX::Types::DateTimeX';
+
+=head1 NAME
+
+t/02_datetimex.t - Check that we can properly coerce a string.
+
+=head1 DESCRIPTION
+
+Run some tests to make sure the the Duration and DateTime types continue to
+work exactly as from the L<MooseX::Types::DateTime> class, as well as perform
+the correct string to object coercions.
+
+=head1 TESTS
+
+This module defines the following tests.
+
+=head2 Test Class
+
+Create a L<Moose> class that is using the L<MooseX::Types::DateTimeX> types.
+
+=cut
+
+{
+	package MooseX::Types::DateTimeX::CoercionTest;
+	
+	use Moose;
+	use MooseX::Types::DateTimeX qw(DateTime Duration);
+	
+	has 'date' => (is=>'rw', isa=>DateTime, coerce=>1);
+	has 'duration' => (is=>'rw', isa=>Duration, coerce=>1);	
+}
+
+ok my $class = MooseX::Types::DateTimeX::CoercionTest->new
+=> 'Created a good class';
+
+
+=head2 ParseDateTime Capabilities
+
+parse some dates and make sure the system can actually find something.
+
+=cut
+
+sub coerce_ok ($;$) {
+    my ( $date, $canon ) = @_;
+    local $Test::Builder::Level = $Test::Builder::Level + 1;
+
+    SKIP: {
+        skip "DateTimeX::Easy couldn't parse '$date'", $canon ? 2 : 1 unless DateTimeX::Easy->new($date);
+        ok( $class->date($date), "coerced a DateTime from '$date'" );
+        is( $class->date, $canon, 'got correct date' ) if $canon;
+    }
+}
+
+## Skip this test until I can figure out better timezone handling
+#coerce_ok ('2/13/1969 noon', '1969-02-13T11:00:00' );
+
+
+coerce_ok( '2/13/1969', '1969-02-13T00:00:00' );
+
+coerce_ok( '2/13/1969 America/New_York', '1969-02-13T00:00:00' );
+
+SKIP: {
+    skip "couldn't parse", 1 unless $class->date;
+    isa_ok $class->date->time_zone => 'DateTime::TimeZone::America::New_York'
+	=> 'Got Correct America/New_York TimeZone';
+}
+
+coerce_ok( 'jan 1 2006', '2006-01-01T00:00:00' );
+
+=head2 relative dates
+
+Stuff like "yesterday".  We can make sure they returned something but we have
+no way to make sure the values are really correct.  Manual testing suggests
+they work well enough, given the inherent ambiguity we are dealing with.
+
+=cut
+
+coerce_ok("now");
+
+coerce_ok("yesterday");
+
+coerce_ok("tomorrow");
+
+coerce_ok("last week");
+
+=head2 check inherited constraints
+
+Just a few tests to make sure the object, hash, etc coercions and type checks 
+still work.
+
+=cut
+
+ok my $datetime = DateTime->now()
+=> 'Create a datetime object for testing';
+
+ok my $anyobject = bless({}, 'Bogus::Does::Not::Exist')
+=> 'Created a random object for proving the object constraint';
+
+ok $class->date($datetime)
+=> 'Passed Object type constraint test.';
+
+	isa_ok $class->date => 'DateTime'
+	=> 'Got a good DateTime Object';
+
+dies_ok { $class->date($anyobject) } 'Does not allow the bad object';
+
+ok $class->date(1000)
+=> 'Passed Num coercion test.';
+
+	isa_ok $class->date => 'DateTime'
+	=> 'Got a good DateTime Object';
+	
+	is $class->date => '1970-01-01T00:16:40'
+	=> 'Got correct DateTime';
+
+ok $class->date({year=>2000,month=>1,day=>10})
+=> 'Passed HashRef coercion test.';
+
+	isa_ok $class->date => 'DateTime'
+	=> 'Got a good DateTime Object';
+	
+	is $class->date => '2000-01-10T00:00:00'
+	=> 'Got correct DateTime';
+	
+=head2 check duration
+
+make sure the Duration type constraint works as expected
+
+=cut
+
+ok $class->duration(100)
+=> 'got duration from integer';
+
+	is $class->duration->seconds, 100
+	=> 'got correct duration from integer';
+	
+
+ok $class->duration('1 minute')
+=> 'got duration from string';
+
+	is $class->duration->seconds, 60
+	=> 'got correct duration string';
+	
+	
+=head1 AUTHOR
+
+John Napiorkowski E<lt>jjn1056 at yahoo.comE<gt>
+
+=head1 COPYRIGHT
+
+	Copyright (c) 2008 John Napiorkowski. All rights reserved
+	This program is free software; you can redistribute
+	it and/or modify it under the same terms as Perl itself.
+
+=cut
+
+1;
+

Propchange: branches/upstream/libmoosex-types-datetime-perl/current/t/02_datetimex.t
------------------------------------------------------------------------------
    svn:executable = 




More information about the Pkg-perl-cvs-commits mailing list