| 1 | =head1 NAME | ||
| 2 | |||
| 3 | Perlanet::Types - Various types for the Perlanet system. | ||
| 4 | |||
| 5 | =head1 SYNOPSIS | ||
| 6 | |||
| 7 | # n/a | ||
| 8 | |||
| 9 | =head1 DESCRIPTION | ||
| 10 | |||
| 11 | This class acts as a repository of types used at various places in | ||
| 12 | Perlanet. | ||
| 13 | |||
| 14 | =cut | ||
| 15 | |||
| 16 | package Perlanet::Types; | ||
| 17 | |||
| 18 | 12 | ▶ | use 5.10.0; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 19 | 12 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 20 | 12 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 21 | |||
| 22 | 12 | ▶ | use Moose::Util::TypeConstraints; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 23 | |||
| 24 | 12 | ▶ | use DateTime; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 25 | 12 | ▶ | use DateTime::Duration; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 26 | 12 | ▶ | use DateTime::Format::Strptime; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 27 | |||
| 28 | =head1 TYPES | ||
| 29 | |||
| 30 | =head2 Perlanet::DateTime | ||
| 31 | |||
| 32 | Our subclass of DateTime (along with a coercion to automatically create | ||
| 33 | it from a string). | ||
| 34 | |||
| 35 | =cut | ||
| 36 | |||
| 37 | 12 | subtype 'Perlanet::DateTime', | |
| 38 | as 'DateTime'; | ||
| 39 | |||
| 40 | coerce 'Perlanet::DateTime', | ||
| 41 | from 'Str', | ||
| 42 | 0 | ▶ | via { |
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||
| 43 | 0 | DateTime::Format::Strptime->new( | |
| 44 | pattern => '%Y-%m-%dT%H:%M%S', | ||
| 45 | )->parse_datetime($_); | ||
| 46 | 12 | }; | |
| 47 | |||
| 48 | =head2 Perlanet::DateTime::Duration | ||
| 49 | |||
| 50 | Our subtype of DateTime::Duration (along with a coercion to automatically | ||
| 51 | create it from a hash reference). | ||
| 52 | |||
| 53 | =cut | ||
| 54 | |||
| 55 | 12 | subtype 'Perlanet::DateTime::Duration', | |
| 56 | as 'DateTime::Duration'; | ||
| 57 | |||
| 58 | coerce 'Perlanet::DateTime::Duration', | ||
| 59 | from 'HashRef', | ||
| 60 | 10 | ▶ | via { |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 61 | 10 | DateTime::Duration->new($_); | |
| 62 | 12 | }; | |
| 63 | |||
| 64 | =head1 AUTHOR | ||
| 65 | |||
| 66 | Dave Cross, <dave@perlhacks.com> | ||
| 67 | |||
| 68 | =head1 COPYRIGHT AND LICENSE | ||
| 69 | |||
| 70 | Copyright (c) 2020 by Magnum Solutions Ltd. | ||
| 71 | |||
| 72 | This library is free software; you can redistribute it and/or modify | ||
| 73 | it under the same terms as Perl itself, either Perl version 5.10.0 or, | ||
| 74 | at your option, any later version of Perl 5 you may have available. | ||
| 75 | |||
| 76 | =cut | ||
| 77 | |||
| 78 | 12 | 1; | |