File Coverage

blib/lib/ResourcePool/Resource/DBI.pm
Criterion Covered Total %
statement 24 44 54.5
branch 1 6 16.6
condition 1 3 33.3
subroutine 5 10 50.0
pod 4 5 80.0
total 35 68 51.4


line stmt bran cond sub pod time code
1             #*********************************************************************
2             #*** ResourcePool::Resource::DBI
3             #*** Copyright (c) 2002 by Markus Winand
4             #*** $Id: DBI.pm,v 1.3 2004/05/02 07:20:09 mws Exp $
5             #*********************************************************************
6              
7             package ResourcePool::Resource::DBI;
8              
9 4     4   30 use vars qw($VERSION @ISA);
  4         7  
  4         209  
10 4     4   22 use strict;
  4         7  
  4         116  
11 4     4   2410 use DBI;
  4         19988  
  4         196  
12 4     4   3398 use ResourcePool::Resource;
  4         1437  
  4         1603  
13              
14             $VERSION = "1.0101";
15             push @ISA, "ResourcePool::Resource";
16              
17             sub new($$$$$) {
18 2     2 0 4 my $proto = shift;
19 2   33     11 my $class = ref($proto) || $proto;
20 2         13 my $self = $class->SUPER::new();
21 2         21 my $ds = shift;
22 2         3 my $user = shift;
23 2         3 my $auth = shift;
24 2         6 my $attr = shift;
25              
26 2         3 eval {
27 2         11 $self->{dbh} = DBI->connect($ds, $user, $auth, $attr);
28             };
29 2 50       528 if (! defined $self->{dbh}) {
30 2         34 warn "ResourcePool::Resource::DBI: Connect to '$ds' failed: $DBI::errstr\n";
31 2         18 return undef;
32             }
33 0           bless($self, $class);
34              
35 0           return $self;
36             }
37              
38             sub close($) {
39 0     0 1   my ($self) = @_;
40 0           eval {
41 0           $self->{dbh}->disconnect();
42             };
43             }
44              
45             sub precheck($) {
46 0     0 1   my ($self) = @_;
47 0           my $rc = $self->{dbh}->ping();
48              
49 0 0         if (!$rc) {
50 0           eval {
51 0           $self->close();
52             };
53             }
54 0           return $rc;
55             }
56              
57             sub postcheck($) {
58 0     0 1   my ($self) = @_;
59              
60 0 0         if (! $self->{dbh}->{AutoCommit}) {
61 0           eval {
62 0           $self->{dbh}->rollback();
63             };
64             }
65 0           return 1;
66             }
67              
68             sub get_plain_resource($) {
69 0     0 1   my ($self) = @_;
70 0           return $self->{dbh};
71             }
72              
73             sub DESTROY($) {
74 0     0     my ($self) = @_;
75 0           $self->close();
76             }
77              
78             1;