DateTimeX::Role::Immutable - A role that can be composed into a DateTime subclass to make it immutable
package Your::DateTime; use base 'DateTime'; use Role::Tiny::With; with 'DateTimeX::Role::Immutable';
This is role that can be composed into a DateTime subclass to make those objects immutable. The
set methods are replaced with new methods that leave the original object untouched, and return a new DateTime object with the expected changes.
The following methods now thrown an exception:
$dt->add_duration() $dt->subtract_duration() $dt->add() $dt->subtract() $dt->set() $dt->set_year() $dt->set_month() $dt->set_day() $dt->set_hour() $dt->set_minute() $dt->set_second() $dt->set_nanosecond() $dt->truncate()
and are replaced by these methods which return the changed value:
$dt->plus_duration() $dt->minus_duration() $dt->plus() $dt->minus() $dt->with_component() $dt->with_year() $dt->with_month() $dt->with_day() $dt->with_hour() $dt->with_minute() $dt->with_second() $dt->with_nanosecond() $dt->trunc()
At the moment,
set_formatter continue to act as mutators. DateTime uses these internally and changing them creates unexpected behavior. These methods also do not really change the time value.
See DateTime for the rest of the documentation.
Mark Grimes, <email@example.com>
This software is copyright (c) 2015 by Mark Grimes, <firstname.lastname@example.org>.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.