Author: timbo
Date: Fri Sep 28 10:27:48 2007
New Revision: 10020
Modified:
dbi/trunk/lib/DBD/Gofer.pm
dbi/trunk/lib/DBI/Gofer/Execute.pm
dbi/trunk/t/87gofer_cache.t
Log:
Fix $h->can() returning () on some installations.
Allow go_cache=1 as short-cut for object;
Modified: dbi/trunk/lib/DBD/Gofer.pm
==============================================================================
--- dbi/trunk/lib/DBD/Gofer.pm (original)
+++ dbi/trunk/lib/DBD/Gofer.pm Fri Sep 28 10:27:48 2007
@@ -167,6 +167,10 @@
# policy object is left in $go_attr{go_policy} so transport can see it
my $go_policy = $go_attr{go_policy};
+ if ($go_attr{go_cache} and not ref $go_attr{go_cache}) { # if not a
cache object already
+ $go_attr{go_cache} = eval { require DBI::Util::Cache;
DBI::Util::Cache->new() };
+ }
+
# but delete any other attributes that don't appy to transport
my $go_connect_method = delete $go_attr{go_connect_method};
Modified: dbi/trunk/lib/DBI/Gofer/Execute.pm
==============================================================================
--- dbi/trunk/lib/DBI/Gofer/Execute.pm (original)
+++ dbi/trunk/lib/DBI/Gofer/Execute.pm Fri Sep 28 10:27:48 2007
@@ -19,7 +19,7 @@
our $VERSION = sprintf("0.%06d", q$Revision$ =~ /(\d+)/o);
our @all_dbh_methods = sort map { keys %$_ } $DBI::DBI_methods{db},
$DBI::DBI_methods{common};
-our %all_dbh_methods = map { $_ => DBD::_::db->can($_) } @all_dbh_methods;
+our %all_dbh_methods = map { $_ => (DBD::_::db->can($_)||undef) }
@all_dbh_methods;
our $local_log = $ENV{DBI_GOFER_LOCAL_LOG}; # do extra logging to stderr
Modified: dbi/trunk/t/87gofer_cache.t
==============================================================================
--- dbi/trunk/t/87gofer_cache.t (original)
+++ dbi/trunk/t/87gofer_cache.t Fri Sep 28 10:27:48 2007
@@ -14,9 +14,10 @@
my @cache_classes = qw(DBI::Util::Cache);
push @cache_classes, "Cache::Memory" if eval { require Cache::Memory };
+push @cache_classes, "1";
for my $cache_class (@cache_classes) {
- my $cache_obj = $cache_class->new();
+ my $cache_obj = ($cache_class eq "1") ? $cache_class : $cache_class->new();
run_tests($cache_obj);
}
@@ -27,17 +28,16 @@
my $dsn = "dbi:Gofer:transport=null;policy=classic;dsn=dbi:ExampleP:";
print " using $cache_obj for $dsn\n";
- is $cache_obj->count, 0, 'cache should be empty to start';
-
my $dbh = DBI->connect($dsn, undef, undef, {
go_cache => $cache_obj,
RaiseError => 1, PrintError => 0, ShowErrorStatement => 1,
} );
ok my $go_transport = $dbh->{go_transport};
+ ok my $go_cache = $go_transport->go_cache;
# setup
- $cache_obj->clear;
- is $cache_obj->count, 0, 'cache should be empty after clear';
+ $go_cache->clear;
+ is $go_cache->count, 0, 'cache should be empty after clear';
$go_transport->transmit_count(0);
is $go_transport->transmit_count, 0, 'transmit_count should be 0';
@@ -48,7 +48,7 @@
# request 1
ok my $rows1 = $dbh->selectall_arrayref("select name from ?", {}, ".");
- cmp_ok $cache_obj->count, '>', 0, 'cache should not be empty after select';
+ cmp_ok $go_cache->count, '>', 0, 'cache should not be empty after select';
my $expected = ($ENV{DBI_AUTOPROXY}) ? 2 : 1;
is $go_transport->cache_hit, 0;