MooseX...rcions(3pm)
π MooseX::Types::DateTime::MoreCoercions β the perl 3pm manual, but make it cute π
okay bestie, so this is the manual page for MooseX::Types::DateTime::MoreCoercions (yes it lives in the perl 3pm section, she's a Perl module page, very demure, very mindful). Sit down, grab a lil snack, we're gonna go through the whole thing together π
β¨ NAME β¨
MooseX::Types::DateTime::MoreCoercions β it's the extensions pack for MooseX::Types::DateTime. That's it. That's the name. She's a spinoff, she's a sequel, she ate π
πΈ VERSION πΈ
version 0.15 β that's the one, that's the version, no cap.
π¦ SYNOPSIS π¦
here's the vibe, literally copy-paste energy:
package MyApp::MyClass;
use MooseX::Types::DateTime::MoreCoercions qw( DateTime );
has created => (
isa => DateTime,
is => "rw",
coerce => 1,
);
my $instance = MyApp::MyClass->new(created=>'January 1, 1980');
print $instance->created->year; # is 1980
## Coercions from the base type continue to work as normal.
my $instance = MyApp::MyClass->new(created=>{year=>2000,month=>1,day=>10});
like⦠she coerced the string 'January 1, 1980' into a whole DateTime and then just casually told you the year is 1980. main character behaviour honestly.
also pls note: coercions from the base type still work as normal, so the hashref version ({year=>2000,month=>1,day=>10}) is still valid and still slays.
Please see the test case for more example usage. π
π DESCRIPTION π
So here's the tea: this module builds on MooseX::Types::DateTime to add extra custom types and coercions. And because she builds on an existing type, all coercions and constraints are inherited. Free stuff. Inherited. Iconic. β¨
π SUBTYPES π
This module defines the following additional subtypes, bestie:
π DateTime
It's a subtype of DateTime in MooseX::Types::DateTime. It adds an additional coercion from strings.
It uses DateTimeX::Easy to try and convert strings, like "yesterday", into a valid DateTime object.
β οΈ but listen β because different systems might localize their timezone all differently, string parsing may not always return the most expected value. In general we try to localize to UTC whenever possible. Feedback welcomed! π«Ά
π Duration
It's a subtype of Duration in MooseX::Types::DateTime that coerces from a string. We use the module Time::Duration::Parse to attempt this.
π CAVEATS π
okay so first of all, this module uses DateTimeX::Easy which is way more DWIM than any sane person would desire. That's a direct quote from the manpage, I'm not even joking, I would never say that about a module unless it was true π
DateTimeX::Easy works by falling back until something makes sense β and that's variable. Furthermore, all the modules that DateTimeX::Easy can use aren't required for "proper" function of DateTimeX::Easy.
So what does this actually mean? Simple: your mileage may vary in your coercions, because DateTimeX::Easy is installation specific. Not me warning you about environment-dependent behaviourβ¦ but yes, me warning you about environment-dependent behaviour π
π₯ SEE ALSO π₯
MooseX::Types::DateTimeβ the replacement for this module. coercions with less voodoo. less chaos. less shenanigans.DateTimeX::Easyβ the backend of this module.Time::Duration::Parseβ the duration parsing backend for this module.
π AUTHOR π
John Napiorkowski <jjn1056 at yahoo.com>
Broken into a separate package from MooseX::Types::DateTime by Evan Carroll.
Forked from MooseX::Types::DateTimeX and ported back to use MooseX::Types::DateTime by Dagfinn Ilmari Mannsaaker <ilmari@ilmari.org>.
β AUTHORS β
- John Napiorkowski
<jjn1056@yahoo.com> - Dagfinn Ilmari Mannsaaker
<ilmari@ilmari.org>
πΈ CONTRIBUTORS πΈ
- Karen Etheridge
<ether@cpan.org> - Evan Carroll
<me+cpan@evancarroll.com> - gregor herrmann
<gregoa@debian.org>
π«Ά COPYRIGHT AND LICENSE π«Ά
This software is copyright (c) 2008 by John Napiorkowski.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
and that's the whole page, bestie! π this one was rendered by perl v5.34.0 on 2022-06-15 β shoutout to the toolchain, she did that. now go forth and coerce your strings responsibly, mwah πβ¨
π¦ where this page comes from
- debian bookworm: libmoosex-types-datetime-morecoercions-perl 0.15-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libmoosex-types-datetime-morecoercions-perl 0.15-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libmoosex-types-datetime-morecoercions-perl 0.15-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libmoosex-types-datetime-morecoercions-perl 0.15-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libmoosex-types-datetime-morecoercions-perl 0.15-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms