line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: /mirror/coderepos/lang/perl/Class-DBI-Plugin-DateTime/trunk/lib/Class/DBI/Plugin/DateTime/Pg.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::Pg; |
7
|
1
|
|
|
1
|
|
27672
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
44
|
|
8
|
1
|
|
|
1
|
|
6
|
use base qw(Class::DBI::Plugin::DateTime::Base); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
736
|
|
9
|
|
|
|
|
|
|
use DateTime::Format::Pg; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
BEGIN |
12
|
|
|
|
|
|
|
{ |
13
|
|
|
|
|
|
|
# Look ma, I can auto-generate all these :) |
14
|
|
|
|
|
|
|
my @types = qw(datetime timestamp timestamptz time timetz date duration); |
15
|
|
|
|
|
|
|
foreach my $type (@types) { |
16
|
|
|
|
|
|
|
my @args = ($type) x 3; |
17
|
|
|
|
|
|
|
push @args, $type eq 'duration' ? ", 'DateTime::Duration'" : ''; |
18
|
|
|
|
|
|
|
eval sprintf(<<' EOM', @args); |
19
|
|
|
|
|
|
|
sub has_%s |
20
|
|
|
|
|
|
|
{ |
21
|
|
|
|
|
|
|
my $class = shift; |
22
|
|
|
|
|
|
|
my $column = shift; |
23
|
|
|
|
|
|
|
my $opts = shift || {}; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my @args = exists $opts->{constructor_args} ? |
26
|
|
|
|
|
|
|
@{$opts->{constructor_args}} : (); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
my $fmt = DateTime::Format::Pg->new(@args); |
29
|
|
|
|
|
|
|
my $inflate = sub { $fmt->parse_%s(shift) }; |
30
|
|
|
|
|
|
|
my $deflate = sub { $fmt->format_%s(shift) }; |
31
|
|
|
|
|
|
|
__PACKAGE__->_setup_column($class, $column, $inflate, $deflate%s); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
EOM |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
{ |
37
|
|
|
|
|
|
|
no strict 'refs'; |
38
|
|
|
|
|
|
|
*has_interval = \&has_duration; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
my @methods = map { ("has_$_") } @types; |
41
|
|
|
|
|
|
|
*_export_methods = sub { @methods }; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
1; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
__END__ |