Created
January 26, 2012 00:26
-
-
Save jleader/1679986 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package MyObject; | |
use Moose; | |
use Moose::Util::TypeConstraints; | |
use MooseX::Types::DateTime; | |
use DateTime::Format::ISO8601; | |
use namespace::autoclean; | |
subtype 'DateTime8601', | |
as 'MooseX::Types::DateTime'; | |
use Data::Dumper; | |
coerce 'DateTime8601', | |
from 'Str', | |
via { | |
$_ = DateTime::Format::ISO8601->parse_datetime($_); | |
}; | |
has 'CreationDate' => ( is => 'ro', isa => 'DateTime8601', coerce => 1 ); | |
__PACKAGE__->meta->make_immutable; | |
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use MyObject; | |
use Data::Dumper; | |
my $x = MyObject->new(CreationDate => '2011-09-02T18:22:05.526Z'); | |
print Dumper($x); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Attribute (CreationDate) does not pass the type constraint because: Validation failed for 'DateTime8601' with value DateTime=HASH(0x25cc9f0) at constructor MyObject::new (defined at MyObject.pm line 20) line 35 | |
MyObject::new('MyObject', 'CreationDate', '2011-09-02T18:22:05.526Z') called at ./myscript.pl line 9 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment