blib/lib/DBIx/Wrapper/VerySimple.pm

filter: Statementstmt 100% 53 / 53 Branchbran 93.7% 15 / 16 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 12 / 12 Podpod 100% 6 / 6 totaltotal 96.6% 87 / 90 CC 10 SCAR 8.5
CC
10
Cov
97%
FetchAll
4.0
FetchHash
3.0
Do
3.0
CRAP 2.3
↑ Summary
1 # $Header: /usr/local/CVS/perl-modules/DBIx-Wrapper-VerySimple/lib/DBIx/Wrapper/VerySimple.pm,v 1.5 2006/11/02 04:10:39 matisse Exp $
2 ###############################################################################
3  
4 package DBIx::Wrapper::VerySimple;
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Carp qw(cluck confess);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use DBI;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 our $VERSION = 0.051;
10  
11 # private instance variables
12 1 my %DB_HANDLES = ();
13 1 my %ARGS = ();
14  
15 7 ▶sub new {
Subroutine new: called CC=2 SCAR=7.0
Pod documented
16 7 my $class = shift;
17 7 my $self = {};
18 7 bless $self, $class;
19 7 $ARGS{$self} = \@_; # So we can use them to reconnect if needed
20 7 ▶ $DB_HANDLES{$self} = DBI->connect(@_)
Condition50%1/2
'DBI'->connect(@_) || confess("Could not connect using DSN: '@{_}'")
l!l
70
MC/DC0%0/1
'DBI'->connect(@_) || confess("Could not connect using DSN: '@{_}'")
'DBI'->connect(@_)
Truth table50%1/2
A
A= 'DBI'->connect(@_)
Aresult
11
00
21 || confess("Could not connect using DSN: '@_'");
22  
23 7 return $self;
24 }
25  
26 1 ▶sub dbh {
Subroutine dbh: called CC=1 SCAR=0.0
Pod documented
27 1 my ($self) = @_;
28 1 return $DB_HANDLES{$self};
29 }
30  
31 1 ▶sub get_args {
Subroutine get_args: called CC=1 SCAR=0.0
Pod documented
32 1 my ($self) = @_;
33 1 return $ARGS{$self};
34 }
35  
36 3 ▶sub FetchHash { ## no critic ProhibitMixedCaseVars
Subroutine FetchHash: called CC=3 SCAR=11.0
Pod documented
37 3 my ( $self, $sql, @bind_values ) = @_;
38 my $sth = $DB_HANDLES{$self}->prepare_cached($sql)
39 3 ▶ or confess( $DB_HANDLES{$self}->errstr, "SQL: {$sql}" );
Branch: 1 branch
BranchTrueFalseTotal
my $sth = $DB_HANDLES{$self}->prepare_cached($sql) or confess($DB_HANDLES{$self}->errstr, "SQL: {$sql}") 2 1 3
40 2 ▶ $sth->execute(@bind_values) or confess("SQL: {$sql}");
Branch: 1 branch
BranchTrueFalseTotal
$sth->execute(@bind_values) or confess("SQL: {$sql}") 1 1 2
41 1 my $row = $sth->fetchrow_hashref;
42 1 $sth->finish;
43 1 return $row;
44 }
45  
46 3 ▶sub FetchAll { ## no critic ProhibitMixedCaseVars
Subroutine FetchAll: called CC=4 SCAR=13.9
Pod documented
47 3 my ( $self, $sql, @bind_values ) = @_;
48 3 my @rows;
49 my $sth = $DB_HANDLES{$self}->prepare_cached($sql)
50 3 ▶ or confess( $DB_HANDLES{$self}->errstr, "SQL: {$sql}" );
Branch: 1 branch
BranchTrueFalseTotal
my $sth = $DB_HANDLES{$self}->prepare_cached($sql) or confess($DB_HANDLES{$self}->errstr, "SQL: {$sql}") 2 1 3
51 2 ▶ $sth->execute(@bind_values) or confess("SQL: {$sql}");
Branch: 1 branch
BranchTrueFalseTotal
$sth->execute(@bind_values) or confess("SQL: {$sql}") 1 1 2
52 1 ▶ while ( my $row = $sth->fetchrow_hashref ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $sth->fetchrow_hashref) 2 1 3
53 2 push @rows, $row;
54 }
55 1 $sth->finish;
56 1 return \@rows;
57 }
58  
59 {
60 1 ▶ no warnings qw(once);
Subroutine BEGIN: called CC=1 SCAR=0.0
61 1 *fetch_hash = \&FetchHash;
62 1 *fetch_all = \&FetchAll;
63 }
64  
65 3 ▶sub Do { ## no critic ProhibitMixedCaseVars
Subroutine Do: called CC=3 SCAR=11.0
Pod documented
66 3 my ( $self, $sql, @bind_values ) = @_;
67 my $sth = $DB_HANDLES{$self}->prepare_cached($sql)
68 3 ▶ or confess( $DB_HANDLES{$self}->errstr, "SQL: {$sql}" );
Branch: 1 branch
BranchTrueFalseTotal
my $sth = $DB_HANDLES{$self}->prepare_cached($sql) or confess($DB_HANDLES{$self}->errstr, "SQL: {$sql}") 2 1 3
69 my $result_code = $sth->execute(@bind_values)
70 2 ▶ or confess( $DB_HANDLES{$self}->errstr, "SQL: {$sql}" );
Branch: 1 branch
BranchTrueFalseTotal
my $result_code = $sth->execute(@bind_values) or confess($DB_HANDLES{$self}->errstr, "SQL: {$sql}") 1 1 2
71 1 $sth->finish;
72 1 return $result_code;
73 }
74  
75 7 ▶sub DESTROY {
Subroutine DESTROY: called CC=2 SCAR=7.2
76 7 my ($self) = @_;
77  
78 # warn ref $self, " executing DESTROY method. Disconnecting from database";
79 7 ▶ return $DB_HANDLES{$self}->disconnect if $DB_HANDLES{$self};
Branch: 1 branch
BranchTrueFalseTotal
if $DB_HANDLES{$self} 7 0 7
80 }
81  
82 ###########################################################################
83 1 1;
84  
85 __END__
↑ Summary