Persistent/Types/MySQL.pm untested

filter: Statementstmt 0.0% 0 / 31 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 5 Podpod n/a totaltotal 0.0% 0 / 36 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 package Coat::Persistent::Types::MySQL;
2  
3 # MySQL types usable in has_p definitions
4 # (either for isa or for store_as)
5  
6 use strict;
7 use warnings;
8  
9 use Coat::Types;
10 use Coat::Persistent::Types;
11 use Class::Date;
12  
13 # datetime'
14  
15 subtype 'MySQL:DateTime'
16 => as 'Str'
17 => where { /^\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d$/ };
18  
19 coerce 'MySQL:DateTime'
20 => from 'UnixTimestamp'
21 => via { Class::Date->new($_)->string };
22  
23 coerce 'UnixTimestamp'
24 => from 'MySQL:DateTime'
25 => via { $_->epoch };
26  
27 # date
28  
29 subtype 'MySQL:Date'
30 => as 'Str'
31 => where { /^\d{4}-\d\d-\d\d$/ };
32  
33 coerce 'MySQL:Date'
34 => from 'UnixTimestamp'
35 => via {
36 my $date = Class::Date->new($_);
37 my $str = $date->ymd;
38 $str =~ s/\//-/g;
39 return $str;
40 };
41  
42 coerce 'UnixTimestamp'
43 => from 'MySQL:Date'
44 => via { Class::Date->new($_)->epoch };
45  
46 1;
47 __END__