Added InflateColumn::DateTime component
Matt S Trout [Wed, 26 Apr 2006 03:19:25 +0000 (03:19 +0000)]
lib/DBIx/Class/Storage/DBI.pm
t/basicrels/27ordered.t [new file with mode: 0644]
t/basicrels/29inflate_datetime.t [new file with mode: 0644]
t/helperrels/29inflate_datetime.t [new file with mode: 0644]
t/lib/DBICTest/Schema.pm
t/lib/DBICTest/Setup.pm
t/lib/sqlite.sql
t/run/29inflate_datetime.tl [new file with mode: 0644]

index 78d7321..7eab86f 100644 (file)
@@ -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 (file)
index 0000000..dc7c61e
--- /dev/null
@@ -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 (file)
index 0000000..62fa6f5
--- /dev/null
@@ -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 (file)
index 0000000..aacf84a
--- /dev/null
@@ -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);
index e882ee7..f51a145 100644 (file)
@@ -29,7 +29,7 @@ __PACKAGE__->load_classes(qw/
     'Producer',
     'CD_to_Producer',
   ),
-  qw/SelfRefAlias TreeLike TwoKeyTreeLike/
+  qw/SelfRefAlias TreeLike TwoKeyTreeLike Event/
 );
 
 1;
index fb08fce..7f57408 100755 (executable)
@@ -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;
index 826805a..c3270e3 100644 (file)
@@ -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 (file)
index 0000000..0efc45a
--- /dev/null
@@ -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;