From: Matt S Trout Date: Mon, 16 Jul 2007 14:46:38 +0000 (+0000) Subject: fixup for datetime parser from Matt Lawrence (mattlaw) X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=114780eed5de9d3cae0aa88f26064abf3a7eb88b;p=dbsrgits%2FDBIx-Class-Historic.git fixup for datetime parser from Matt Lawrence (mattlaw) --- diff --git a/Changes b/Changes index 5e4e886..da22d82 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,8 @@ Revision history for DBIx::Class + - rebless before building datetime_parser + (patch from mattlaw / Matt Lawrence) + 0.08003 2007-07-14 18:01:00 - improved populate bulk_insert mode - fixed up multi_create to be more intelligent about PK<->PK rels diff --git a/lib/DBIx/Class.pm b/lib/DBIx/Class.pm index cf82380..934e9d6 100644 --- a/lib/DBIx/Class.pm +++ b/lib/DBIx/Class.pm @@ -233,6 +233,8 @@ konobi: Scott McWhirter LTJake: Brian Cassidy +mattlaw: Matt Lawrence + ned: Neil de Carteret nigel: Nigel Metheringham diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index 5f71f02..cde6ac5 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -1428,7 +1428,10 @@ Returns the datetime parser class sub datetime_parser { my $self = shift; - return $self->{datetime_parser} ||= $self->build_datetime_parser(@_); + return $self->{datetime_parser} ||= do { + $self->ensure_connected; + $self->build_datetime_parser(@_); + }; } =head2 datetime_parser_type diff --git a/t/72pg.t b/t/72pg.t index f05229b..277248e 100644 --- a/t/72pg.t +++ b/t/72pg.t @@ -27,11 +27,23 @@ my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_PG_${_}" } qw/DSN USER PASS/}; plan skip_all => 'Set $ENV{DBICTEST_PG_DSN}, _USER and _PASS to run this test' . ' (note: creates and drops tables named artist and casecheck!)' unless ($dsn && $user); -plan tests => 8; +plan tests => 10; DBICTest::Schema->load_classes( 'Casecheck' ); my $schema = DBICTest::Schema->connect($dsn, $user, $pass); +# Check that datetime_parser returns correctly before we explicitly connect. +SKIP: { + eval { require DateTime::Format::Pg }; + skip "DateTime::Format::Pg required", 2 if $@; + + my $store = ref $schema->storage; + is($store, 'DBIx::Class::Storage::DBI', 'Started with generic storage'); + + my $parser = $schema->storage->datetime_parser; + is( $parser, 'DateTime::Format::Pg', 'datetime_parser is as expected'); +} + my $dbh = $schema->storage->dbh; $schema->source("Artist")->name("testschema.artist"); $dbh->do("CREATE SCHEMA testschema;");