Skip to content

Instantly share code, notes, and snippets.

@tobyink
Created February 28, 2014 21:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tobyink/9280334 to your computer and use it in GitHub Desktop.
Save tobyink/9280334 to your computer and use it in GitHub Desktop.
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