File: Types.pm

package info (click to toggle)
libperlanet-perl 2.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 444 kB
  • sloc: xml: 1,177; perl: 757; sh: 6; makefile: 5
file content (78 lines) | stat: -rw-r--r-- 1,385 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
=head1 NAME

Perlanet::Types - Various types for the Perlanet system.

=head1 SYNOPSIS

    # n/a

=head1 DESCRIPTION

This class acts as a repository of types used at various places in
Perlanet.

=cut

package Perlanet::Types;

use 5.10.0;
use strict;
use warnings;

use Moose::Util::TypeConstraints;

use DateTime;
use DateTime::Duration;
use DateTime::Format::Strptime;

=head1 TYPES

=head2 Perlanet::DateTime

Our subclass of DateTime (along with a coercion to automatically create
it from a string).

=cut

subtype 'Perlanet::DateTime',
  as 'DateTime';

coerce 'Perlanet::DateTime',
  from 'Str',
  via {
    DateTime::Format::Strptime->new(
      pattern => '%Y-%m-%dT%H:%M%S',
    )->parse_datetime($_);
  };

=head2 Perlanet::DateTime::Duration

Our subtype of DateTime::Duration (along with a coercion to automatically
create it from a hash reference).

=cut

subtype 'Perlanet::DateTime::Duration',
  as 'DateTime::Duration';

coerce 'Perlanet::DateTime::Duration',
  from 'HashRef',
  via {
    DateTime::Duration->new($_);
  };

=head1 AUTHOR

Dave Cross, <dave@perlhacks.com>

=head1 COPYRIGHT AND LICENSE

Copyright (c) 2020 by Magnum Solutions Ltd.

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.10.0 or,
at your option, any later version of Perl 5 you may have available.

=cut

1;