| Class-DBI-Plugin-DateTime documentation | Contained in the Class-DBI-Plugin-DateTime distribution. |
Class::DBI::Plugin::DateTime::Pg - Use DateTime With PostgreSQL
package MyCDBI;
use base qw(Class::DBI);
use Class::DBI::Plugin::DateTime::Pg;
__PACKAGE__->set_db(...);
__PACKAGE__->table(...);
__PACKAGE__->has_timestamp('a_timestamp');
__PACKAGE__->has_date('a_date');
__PACKAGE__->has_time('a_time');
Class::DBI::Plugin::DateTime::Pg provides methods to work with DateTime objects in a Class::DBI + PostgreSQL environment.
All methods take the target column name. You may optionally specify a hashref as the second argument. For this module, you may specify the following:
An arrayref of arguments to be passed to the DateTime::Format::Pg object that is used to parse/format the field.
Copyright (c) 2005 Daisuke Maki <dmaki@cpan.org>. All rights reserved.
Development funded by Brazil Ltd <http://b.razil.jp>
| Class-DBI-Plugin-DateTime documentation | Contained in the Class-DBI-Plugin-DateTime distribution. |
# $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 $ # # Copyright (c) 2005 Daisuke Maki <dmaki@cpan.org> # All rights reserved. package Class::DBI::Plugin::DateTime::Pg; use strict; use base qw(Class::DBI::Plugin::DateTime::Base); use DateTime::Format::Pg; BEGIN { # Look ma, I can auto-generate all these :) my @types = qw(datetime timestamp timestamptz time timetz date duration); foreach my $type (@types) { my @args = ($type) x 3; push @args, $type eq 'duration' ? ", 'DateTime::Duration'" : ''; eval sprintf(<<' EOM', @args); sub has_%s { my $class = shift; my $column = shift; my $opts = shift || {}; my @args = exists $opts->{constructor_args} ? @{$opts->{constructor_args}} : (); my $fmt = DateTime::Format::Pg->new(@args); my $inflate = sub { $fmt->parse_%s(shift) }; my $deflate = sub { $fmt->format_%s(shift) }; __PACKAGE__->_setup_column($class, $column, $inflate, $deflate%s); } EOM } { no strict 'refs'; *has_interval = \&has_duration; my @methods = map { ("has_$_") } @types; *_export_methods = sub { @methods }; } } 1; __END__