File Coverage

blib/lib/Class/DBI/Plugin/DateTime/MySQL.pm
Criterion Covered Total %
statement 6 6 100.0
branch n/a
condition n/a
subroutine 2 2 100.0
pod n/a
total 8 8 100.0


line stmt bran cond sub pod time code
1             # $Id: /mirror/coderepos/lang/perl/Class-DBI-Plugin-DateTime/trunk/lib/Class/DBI/Plugin/DateTime/MySQL.pm 101061 2009-02-20T09:44:03.572989Z daisuke $
2             #
3             # Copyright (c) 2005 Daisuke Maki
4             # All rights reserved.
5              
6             package Class::DBI::Plugin::DateTime::MySQL;
7 1     1   6383 use strict;
  1         2  
  1         41  
8 1     1   5 use base qw(Class::DBI::Plugin::DateTime::Base);
  1         3  
  1         101  
9             use DateTime::Format::MySQL;
10              
11             BEGIN
12             {
13             my @types = qw(datetime date timestamp);
14             foreach my $type (@types) {
15             # DT::F::MySQL doesn't have a format_timestamp method, so change
16             # the deflator method accordingly
17             my($inflator, $deflator);
18             if ($type eq 'timestamp') {
19             $inflator = 'timestamp';
20             $deflator = 'datetime';
21             } else {
22             $inflator = $type;
23             $deflator = $type;
24             }
25              
26             eval sprintf(<<' EOM', $type, $inflator, $deflator);
27             sub has_%s
28             {
29             my $class = shift;
30             my $column = shift;
31              
32             my $inflate = sub { DateTime::Format::MySQL->parse_%s(shift) };
33             my $deflate = sub { DateTime::Format::MySQL->format_%s(shift) };
34             __PACKAGE__->_setup_column($class, $column, $inflate, $deflate);
35             }
36             EOM
37             }
38              
39             {
40             my @methods = map { ("has_$_") } @types;
41             *_export_methods = sub { @methods };
42             }
43             }
44              
45             1;
46              
47             __END__