Created
February 28, 2014 21:30
-
-
Save tobyink/9280334 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
use strict; | |
use warnings; | |
{ | |
package Event; | |
use Moose; | |
use Types::Standard qw( Str ); | |
use Types::XSD qw( Date ); | |
has start_date => ( | |
is => 'ro', | |
isa => Date->plus_coercions(Str, \&_format_as_iso8601), | |
coerce => 1, | |
required => 1, | |
); | |
sub _format_as_iso8601 | |
{ | |
my $date = @_ ? shift : $_; | |
my ($d, $m, $y) = split m{/}, $date; | |
sprintf('%04d-%02d-%02d', $y, $m, $d); | |
} | |
} | |
print Event->new(start_date => '1/6/1980')->dump; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment