Moose Moose - It's the new camel #18

What if you want to change the date

package Time;

use Moose;
use Moose::Util::TypeConstraints;

use DateTime;

subtype 'DateTime'
    => as Object
    => where { $_->isa('DateTime') };

coerce 'DateTime'
    => from 'HashRef'
        => via { DateTime->new( %{ $_ } ) }
    => from Int
        => via { DateTime->from_epoch(epoch => $_) };

has 'time' => (
    is      => 'rw',
    isa     => 'DateTime',
    coerce  => 1,
    default => sub {
        DateTime->now();
    }
);
continued...
Copyright © 2007 Robert Boone