[Bast-commits] r6853 - in DBIx-Class/0.08/branches/on_connect_call:
lib/DBIx/Class/Storage t t/inflate
ribasushi at dev.catalyst.perl.org
ribasushi at dev.catalyst.perl.org
Mon Jun 29 21:38:31 GMT 2009
Author: ribasushi
Date: 2009-06-29 21:38:30 +0000 (Mon, 29 Jun 2009)
New Revision: 6853
Added:
DBIx-Class/0.08/branches/on_connect_call/t/inflate/datetime_oracle.t
Removed:
DBIx-Class/0.08/branches/on_connect_call/t/73oracle_inflate.t
Modified:
DBIx-Class/0.08/branches/on_connect_call/lib/DBIx/Class/Storage/DBI.pm
Log:
Some beautification
Modified: DBIx-Class/0.08/branches/on_connect_call/lib/DBIx/Class/Storage/DBI.pm
===================================================================
--- DBIx-Class/0.08/branches/on_connect_call/lib/DBIx/Class/Storage/DBI.pm 2009-06-29 21:13:48 UTC (rev 6852)
+++ DBIx-Class/0.08/branches/on_connect_call/lib/DBIx/Class/Storage/DBI.pm 2009-06-29 21:38:30 UTC (rev 6853)
@@ -433,11 +433,6 @@
$self->_sql_maker_opts->{$sql_maker_opt} = $opt_val;
}
}
- for my $connect_do_opt (qw/on_connect_do on_disconnect_do/) {
- if(my $opt_val = delete $attrs{$connect_do_opt}) {
- $self->$connect_do_opt($opt_val);
- }
- }
}
%attrs = () if (ref $args[0] eq 'CODE'); # _connect() never looks past $args[0] in this case
@@ -459,8 +454,11 @@
=cut
sub _parse_connect_do {
- my ($self, $type, $val) = @_;
+ my ($self, $type) = @_;
+ my $val = $self->$type;
+ return () if not defined $val;
+
my @res;
if (not ref($val)) {
@@ -468,7 +466,7 @@
} elsif (ref($val) eq 'CODE') {
push @res, $val;
} elsif (ref($val) eq 'ARRAY') {
- push @res, map [ 'do_sql', $_ ], @$val;
+ push @res, map { [ 'do_sql', $_ ] } @$val;
} else {
$self->throw_exception("Invalid type for $type: ".ref($val));
}
@@ -622,17 +620,13 @@
my ($self) = @_;
if( $self->connected ) {
- if (my $connection_call = $self->on_disconnect_call) {
- $self->_do_connection_actions(disconnect_call_ => $connection_call)
- }
- if (my $connection_do = $self->on_disconnect_do) {
- $self->_do_connection_actions(
- disconnect_call_ => $self->_parse_connect_do(
- on_disconnect_do => $connection_do
- )
- )
- }
+ my @actions;
+ push @actions, ( $self->on_disconnect_call || () );
+ push @actions, $self->_parse_connect_do ('on_disconnect_do');
+
+ $self->_do_connection_actions(disconnect_call_ => $_) for @actions;
+
$self->_dbh->rollback unless $self->_dbh_autocommit;
$self->_dbh->disconnect;
$self->_dbh(undef);
@@ -718,7 +712,7 @@
sub _sql_maker_args {
my ($self) = @_;
-
+
return ( bindtype=>'columns', array_datatypes => 1, limit_dialect => $self->dbh, %{$self->_sql_maker_opts} );
}
@@ -748,14 +742,12 @@
# there is no transaction in progress by definition
$self->{transaction_depth} = $self->_dbh_autocommit ? 0 : 1;
- if (my $connection_call = $self->on_connect_call) {
- $self->_do_connection_actions(connect_call_ => $connection_call)
- }
- if (my $connection_do = $self->on_connect_do) {
- $self->_do_connection_actions(
- connect_call_ => $self->_parse_connect_do(on_connect_do => $connection_do)
- )
- }
+ my @actions;
+
+ push @actions, ( $self->on_connect_call || () );
+ push @actions, $self->_parse_connect_do ('on_connect_do');
+
+ $self->_do_connection_actions(connect_call_ => $_) for @actions;
}
sub _determine_driver {
Deleted: DBIx-Class/0.08/branches/on_connect_call/t/73oracle_inflate.t
===================================================================
--- DBIx-Class/0.08/branches/on_connect_call/t/73oracle_inflate.t 2009-06-29 21:13:48 UTC (rev 6852)
+++ DBIx-Class/0.08/branches/on_connect_call/t/73oracle_inflate.t 2009-06-29 21:38:30 UTC (rev 6853)
@@ -1,103 +0,0 @@
-use strict;
-use warnings;
-
-use Test::More;
-use lib qw(t/lib);
-use DBICTest;
-
-my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_ORA_${_}" } qw/DSN USER PASS/};
-
-if (not ($dsn && $user && $pass)) {
- plan skip_all => 'Set $ENV{DBICTEST_ORA_DSN}, _USER and _PASS to run this test. ' .
- 'Warning: This test drops and creates a table called \'track\'';
-}
-else {
- eval "use DateTime; use DateTime::Format::Oracle;";
- if ($@) {
- plan skip_all => 'needs DateTime and DateTime::Format::Oracle for testing';
- }
- else {
- plan tests => 10;
- }
-}
-
-# DateTime::Format::Oracle needs this set
-$ENV{NLS_DATE_FORMAT} = 'DD-MON-YY';
-$ENV{NLS_TIMESTAMP_FORMAT} = 'YYYY-MM-DD HH24:MI:SSXFF';
-$ENV{NLS_LANG} = 'AMERICAN_AMERICA.WE8ISO8859P1';
-
-my $schema = DBICTest::Schema->connect($dsn, $user, $pass);
-
-# Need to redefine the last_updated_on column
-my $col_metadata = $schema->class('Track')->column_info('last_updated_on');
-$schema->class('Track')->add_column( 'last_updated_on' => {
- data_type => 'date' });
-$schema->class('Track')->add_column( 'last_updated_at' => {
- data_type => 'timestamp' });
-
-my $dbh = $schema->storage->dbh;
-
-#$dbh->do("alter session set nls_timestamp_format = 'YYYY-MM-DD HH24:MI:SSXFF'");
-
-eval {
- $dbh->do("DROP TABLE track");
-};
-$dbh->do("CREATE TABLE track (trackid NUMBER(12), cd NUMBER(12), position NUMBER(12), title VARCHAR(255), last_updated_on DATE, last_updated_at TIMESTAMP)");
-
-# insert a row to play with
-my $new = $schema->resultset('Track')->create({ trackid => 1, cd => 1, position => 1, title => 'Track1', last_updated_on => '06-MAY-07', last_updated_at => '2009-05-03 21:17:18.5' });
-is($new->trackid, 1, "insert sucessful");
-
-my $track = $schema->resultset('Track')->find( 1 );
-
-is( ref($track->last_updated_on), 'DateTime', "last_updated_on inflated ok");
-
-is( $track->last_updated_on->month, 5, "DateTime methods work on inflated column");
-
-#note '$track->last_updated_at => ', $track->last_updated_at;
-is( ref($track->last_updated_at), 'DateTime', "last_updated_at inflated ok");
-
-is( $track->last_updated_at->nanosecond, 500_000_000, "DateTime methods work with nanosecond precision");
-
-my $dt = DateTime->now();
-$track->last_updated_on($dt);
-$track->last_updated_at($dt);
-$track->update;
-
-is( $track->last_updated_on->month, $dt->month, "deflate ok");
-is( int $track->last_updated_at->nanosecond, int $dt->nanosecond, "deflate ok with nanosecond precision");
-
-# test datetime_setup
-
-$schema->storage->disconnect;
-
-delete $ENV{NLS_DATE_FORMAT};
-delete $ENV{NLS_TIMESTAMP_FORMAT};
-
-$schema->connection($dsn, $user, $pass, {
- on_connect_call => 'datetime_setup'
-});
-
-$dt = DateTime->now();
-
-my $timestamp = $dt->clone;
-$timestamp->set_nanosecond( int 500_000_000 );
-
-$track = $schema->resultset('Track')->find( 1 );
-$track->update({ last_updated_on => $dt, last_updated_at => $timestamp });
-
-$track = $schema->resultset('Track')->find(1);
-
-is( $track->last_updated_on, $dt, 'DateTime round-trip as DATE' );
-is( $track->last_updated_at, $timestamp, 'DateTime round-trip as TIMESTAMP' );
-
-is( int $track->last_updated_at->nanosecond, int 500_000_000,
- 'TIMESTAMP nanoseconds survived' );
-
-# clean up our mess
-END {
- if($schema && ($dbh = $schema->storage->dbh)) {
- $dbh->do("DROP TABLE track");
- }
-}
-
Copied: DBIx-Class/0.08/branches/on_connect_call/t/inflate/datetime_oracle.t (from rev 6777, DBIx-Class/0.08/branches/on_connect_call/t/73oracle_inflate.t)
===================================================================
--- DBIx-Class/0.08/branches/on_connect_call/t/inflate/datetime_oracle.t (rev 0)
+++ DBIx-Class/0.08/branches/on_connect_call/t/inflate/datetime_oracle.t 2009-06-29 21:38:30 UTC (rev 6853)
@@ -0,0 +1,103 @@
+use strict;
+use warnings;
+
+use Test::More;
+use lib qw(t/lib);
+use DBICTest;
+
+my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_ORA_${_}" } qw/DSN USER PASS/};
+
+if (not ($dsn && $user && $pass)) {
+ plan skip_all => 'Set $ENV{DBICTEST_ORA_DSN}, _USER and _PASS to run this test. ' .
+ 'Warning: This test drops and creates a table called \'track\'';
+}
+else {
+ eval "use DateTime; use DateTime::Format::Oracle;";
+ if ($@) {
+ plan skip_all => 'needs DateTime and DateTime::Format::Oracle for testing';
+ }
+ else {
+ plan tests => 10;
+ }
+}
+
+# DateTime::Format::Oracle needs this set
+$ENV{NLS_DATE_FORMAT} = 'DD-MON-YY';
+$ENV{NLS_TIMESTAMP_FORMAT} = 'YYYY-MM-DD HH24:MI:SSXFF';
+$ENV{NLS_LANG} = 'AMERICAN_AMERICA.WE8ISO8859P1';
+
+my $schema = DBICTest::Schema->connect($dsn, $user, $pass);
+
+# Need to redefine the last_updated_on column
+my $col_metadata = $schema->class('Track')->column_info('last_updated_on');
+$schema->class('Track')->add_column( 'last_updated_on' => {
+ data_type => 'date' });
+$schema->class('Track')->add_column( 'last_updated_at' => {
+ data_type => 'timestamp' });
+
+my $dbh = $schema->storage->dbh;
+
+#$dbh->do("alter session set nls_timestamp_format = 'YYYY-MM-DD HH24:MI:SSXFF'");
+
+eval {
+ $dbh->do("DROP TABLE track");
+};
+$dbh->do("CREATE TABLE track (trackid NUMBER(12), cd NUMBER(12), position NUMBER(12), title VARCHAR(255), last_updated_on DATE, last_updated_at TIMESTAMP)");
+
+# insert a row to play with
+my $new = $schema->resultset('Track')->create({ trackid => 1, cd => 1, position => 1, title => 'Track1', last_updated_on => '06-MAY-07', last_updated_at => '2009-05-03 21:17:18.5' });
+is($new->trackid, 1, "insert sucessful");
+
+my $track = $schema->resultset('Track')->find( 1 );
+
+is( ref($track->last_updated_on), 'DateTime', "last_updated_on inflated ok");
+
+is( $track->last_updated_on->month, 5, "DateTime methods work on inflated column");
+
+#note '$track->last_updated_at => ', $track->last_updated_at;
+is( ref($track->last_updated_at), 'DateTime', "last_updated_at inflated ok");
+
+is( $track->last_updated_at->nanosecond, 500_000_000, "DateTime methods work with nanosecond precision");
+
+my $dt = DateTime->now();
+$track->last_updated_on($dt);
+$track->last_updated_at($dt);
+$track->update;
+
+is( $track->last_updated_on->month, $dt->month, "deflate ok");
+is( int $track->last_updated_at->nanosecond, int $dt->nanosecond, "deflate ok with nanosecond precision");
+
+# test datetime_setup
+
+$schema->storage->disconnect;
+
+delete $ENV{NLS_DATE_FORMAT};
+delete $ENV{NLS_TIMESTAMP_FORMAT};
+
+$schema->connection($dsn, $user, $pass, {
+ on_connect_call => 'datetime_setup'
+});
+
+$dt = DateTime->now();
+
+my $timestamp = $dt->clone;
+$timestamp->set_nanosecond( int 500_000_000 );
+
+$track = $schema->resultset('Track')->find( 1 );
+$track->update({ last_updated_on => $dt, last_updated_at => $timestamp });
+
+$track = $schema->resultset('Track')->find(1);
+
+is( $track->last_updated_on, $dt, 'DateTime round-trip as DATE' );
+is( $track->last_updated_at, $timestamp, 'DateTime round-trip as TIMESTAMP' );
+
+is( int $track->last_updated_at->nanosecond, int 500_000_000,
+ 'TIMESTAMP nanoseconds survived' );
+
+# clean up our mess
+END {
+ if($schema && ($dbh = $schema->storage->dbh)) {
+ $dbh->do("DROP TABLE track");
+ }
+}
+
More information about the Bast-commits
mailing list