blib/lib/MooseX/Types/DateTime/MySQL.pm

filter: Statementstmt 100% 45 / 45 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 17 / 17 Podpod n/a totaltotal 100% 62 / 62 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
↑ Summary
1 package MooseX::Types::DateTime::MySQL;
2 2 ▶use MooseX::Types -declare => [qw/
Subroutine BEGIN: called CC=1 SCAR=0.0
3 MySQLDateTime
4 MySQLDate
5 MySQLTime
6 2 /];
7 2 ▶use MooseX::Types::DateTime qw/ DateTime Duration /;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use MooseX::Types::Moose qw/ Str Int /;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use DateTime::Format::MySQL;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use DateTime::Duration;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use DateTime::Format::Duration;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 2 our $VERSION = '0.003';
15  
16 subtype MySQLDateTime,
17 as Str,
18 6 ▶ where { /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/ };
Subroutine __ANON__: called CC=1 SCAR=0.0
19  
20 subtype MySQLDate,
21 as Str,
22 4 ▶ where { /^\d{4}-\d{2}-\d{2}$/ };
Subroutine __ANON__: called CC=1 SCAR=0.0
23  
24 subtype MySQLTime,
25 as Str,
26 7 ▶ where { /^-?\d?\d{2}:\d{2}:\d{2}$/ };
Subroutine __ANON__: called CC=1 SCAR=0.0
27  
28 coerce MySQLDateTime,
29 from DateTime,
30 1 ▶ via { DateTime::Format::MySQL->format_datetime($_) };
Subroutine __ANON__: called CC=1 SCAR=0.0
31  
32 coerce MySQLDate,
33 from DateTime,
34 1 ▶ via { DateTime::Format::MySQL->format_date($_) };
Subroutine __ANON__: called CC=1 SCAR=0.0
35  
36 coerce MySQLTime,
37 from DateTime,
38 1 ▶ via { DateTime::Format::MySQL->format_time($_) };
Subroutine __ANON__: called CC=1 SCAR=0.0
39  
40 {
41 2 my $formatter = DateTime::Format::Duration->new(pattern => "%H:%M:%S", normalize => 1);
42 coerce MySQLTime,
43 from Int,
44 3 ▶ via { $formatter->format_duration(DateTime::Duration->new(seconds => $_)) };
Subroutine __ANON__: called CC=1 SCAR=0.0
45 }
46  
47 coerce DateTime,
48 from MySQLDateTime,
49 1 ▶ via { DateTime::Format::MySQL->parse_datetime($_) };
Subroutine __ANON__: called CC=1 SCAR=0.0
50  
51 coerce DateTime,
52 from MySQLDate,
53 1 ▶ via { DateTime::Format::MySQL->parse_date($_) };
Subroutine __ANON__: called CC=1 SCAR=0.0
54  
55 coerce MySQLDateTime,
56 from MySQLDate,
57 1 ▶ via { $_ . " 00:00:00" };
Subroutine __ANON__: called CC=1 SCAR=0.0
58  
59 2 1;
60  
61 =head1 NAME
62  
63 MooseX::Types::DateTime::MySQL - Joins MooseX::Types::DateTime and DateTime::Format::MySQL
64  
65 =head1 DESCRIPTION
66  
67 Defines a C<MySQLDateTime> type which will round-trip coerce to the C<DateTime> type
68 from L<MooseX::Types::DateTime>.
69  
70 =head1 TYPES
71  
72 =head2 MySQLDateTime
73  
74 Coerces to and from C<DateTime>.
75  
76 =head2 MySQLDate
77  
78 Coerces to and from C<DateTime> and will coerce to C<MySQLDateTime>.
79  
80 =head2 MySQLTime
81  
82 Coerces from C<Int> (duration) and C<DateTime> (by extracting only the time part).
83  
84 =head1 BUGS
85  
86 =over
87  
88 =item The MySQL datetime detection regex is imperfect as it just looks for C< \d >s, rather than things which are known valid months.
89  
90 =item Probably more
91  
92 =back
93  
94 =head1 AUTHOR
95  
96 Tomas Doran (t0m) C<<bobtfish@bobtfish.net>>
97  
98 =head1 COPYRIGHT
99  
100 Copyright state51.
101  
102 =head1 LICENSE
103  
104 Copyright 2009 the above author(s).
105  
106 This sofware is free software, and is licensed under the same terms as perl itself.
107  
108 =cut
109  
↑ Summary