MooseX...rcions(3pm)

πŸ“¦
version 0.15 Β· 5 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– 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>

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