From: Matt S Trout Date: Wed, 26 Apr 2006 03:19:25 +0000 (+0000) Subject: Added InflateColumn::DateTime component X-Git-Tag: v0.07002~75^2~182^2~5 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f86fcf0d9c7c73578fe3e6e677d537abb19769e4;p=dbsrgits%2FDBIx-Class.git Added InflateColumn::DateTime component --- diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index 78d7321..7eab86f 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -738,6 +738,21 @@ sub deploy { } } +sub datetime_parser { + my $self = shift; + return $self->{datetime_parser} ||= $self->build_datetime_parser(@_); +} + +sub datetime_parser_type { "DateTime::Format::MySQL"; } + +sub build_datetime_parser { + my $self = shift; + my $type = $self->datetime_parser_type(@_); + eval "use ${type}"; + $self->throw_exception("Couldn't load ${type}: $@") if $@; + return $type; +} + sub DESTROY { shift->disconnect } 1; diff --git a/t/basicrels/27ordered.t b/t/basicrels/27ordered.t new file mode 100644 index 0000000..dc7c61e --- /dev/null +++ b/t/basicrels/27ordered.t @@ -0,0 +1,7 @@ +use Test::More; +use lib qw(t/lib); +use DBICTest; +use DBICTest::BasicRels; + +require "t/run/27ordered.tl"; +run_tests(DBICTest->schema); diff --git a/t/basicrels/29inflate_datetime.t b/t/basicrels/29inflate_datetime.t new file mode 100644 index 0000000..62fa6f5 --- /dev/null +++ b/t/basicrels/29inflate_datetime.t @@ -0,0 +1,7 @@ +use Test::More; +use lib qw(t/lib); +use DBICTest; +use DBICTest::BasicRels; + +require "t/run/29inflate_datetime.tl"; +run_tests(DBICTest->schema); diff --git a/t/helperrels/29inflate_datetime.t b/t/helperrels/29inflate_datetime.t new file mode 100644 index 0000000..aacf84a --- /dev/null +++ b/t/helperrels/29inflate_datetime.t @@ -0,0 +1,7 @@ +use Test::More; +use lib qw(t/lib); +use DBICTest; +use DBICTest::HelperRels; + +require "t/run/29inflate_datetime.tl"; +run_tests(DBICTest->schema); diff --git a/t/lib/DBICTest/Schema.pm b/t/lib/DBICTest/Schema.pm index e882ee7..f51a145 100644 --- a/t/lib/DBICTest/Schema.pm +++ b/t/lib/DBICTest/Schema.pm @@ -29,7 +29,7 @@ __PACKAGE__->load_classes(qw/ 'Producer', 'CD_to_Producer', ), - qw/SelfRefAlias TreeLike TwoKeyTreeLike/ + qw/SelfRefAlias TreeLike TwoKeyTreeLike Event/ ); 1; diff --git a/t/lib/DBICTest/Setup.pm b/t/lib/DBICTest/Setup.pm index fb08fce..7f57408 100755 --- a/t/lib/DBICTest/Setup.pm +++ b/t/lib/DBICTest/Setup.pm @@ -137,4 +137,9 @@ $schema->populate('Track', [ [ 18, 1, 3, "Beehind You"], ]); +$schema->populate('Event', [ + [ qw/id starts_at/ ], + [ 1, '2006-04-25 22:24:33' ], +]); + 1; diff --git a/t/lib/sqlite.sql b/t/lib/sqlite.sql index 826805a..c3270e3 100644 --- a/t/lib/sqlite.sql +++ b/t/lib/sqlite.sql @@ -1,6 +1,6 @@ -- -- Created by SQL::Translator::Producer::SQLite --- Created on Wed Apr 19 18:32:39 2006 +-- Created on Wed Apr 26 03:18:22 2006 -- BEGIN TRANSACTION; @@ -115,6 +115,14 @@ CREATE TABLE tags ( ); -- +-- Table: event +-- +CREATE TABLE event ( + id INTEGER PRIMARY KEY NOT NULL, + starts_at datetime NOT NULL +); + +-- -- Table: twokeys -- CREATE TABLE twokeys ( diff --git a/t/run/29inflate_datetime.tl b/t/run/29inflate_datetime.tl new file mode 100644 index 0000000..0efc45a --- /dev/null +++ b/t/run/29inflate_datetime.tl @@ -0,0 +1,18 @@ +sub run_tests { +my $schema = shift; + +eval { require DateTime::Format::MySQL }; +plan skip_all => "Need DateTime::Format::MySQL for inflation tests" if $@; + +plan tests => 2; + +# inflation test +my $event = $schema->resultset("Event")->find(1); + +isa_ok($event->starts_at, 'DateTime', 'DateTime returned'); + +is($event->starts_at, '2006-04-25T22:24:33', 'Correct date/time'); + +} + +1;