in reply to Types::DateTime, DateTimeUTC->plus_coercions( Format['ISO8601'] ), output format override question
As per ikegami's answer (Re: Types::DateTime, DateTimeUTC->plus_coercions( Format['ISO8601'] ), output format override question), you want to set a formatter on the DateTime object.
$cowtime->timestamp->set_formatter($formatter);
But you probably want your CowTime class to be doing that automatically. You can do that with triggers:
use 5.12.0; package CowTime { use Moo; use Types::DateTime -all; has timestamp => is => "ro", isa => DateTimeUTC->plus_coercions( Format['ISO8601'] ), coerce => 1, trigger => sub { my ($self, $value) = @_; state $formatter = DateTime::Format::MyFormatter->new; $value->set_formatter($formatter); }; 1; };
The trigger is a coderef which gets called any time you set the value of an attribute. (Though it's not set if the attribute is set by a default/builder.)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Types::DateTime, DateTimeUTC->plus_coercions( Format['ISO8601'] ), output format override question
by ikegami (Patriarch) on Dec 26, 2019 at 09:04 UTC | |
by tobyink (Canon) on Dec 26, 2019 at 09:26 UTC | |
by ikegami (Patriarch) on Dec 27, 2019 at 05:54 UTC | |
by tobyink (Canon) on Dec 27, 2019 at 16:40 UTC | |
by ikegami (Patriarch) on Dec 28, 2019 at 13:54 UTC |