File Coverage

blib/lib/DBIx/Foo.pm
Criterion Covered Total %
statement 42 47 89.3
branch 4 10 40.0
condition 3 9 33.3
subroutine 14 15 93.3
pod 0 8 0.0
total 63 89 70.7


line stmt bran cond sub pod time code
1             package DBIx::Foo;
2              
3 4     4   8660013 use strict;
  4         11  
  4         150  
4              
5 4     4   30450 use DBI;
  4         33462  
  4         202  
6 4     4   2556 use DBIx::Foo::SearchQuery;
  4         17  
  4         141  
7 4     4   4432 use DBIx::Foo::SimpleQuery;
  4         13  
  4         354  
8 4     4   5280 use DBIx::Foo::UpdateQuery;
  4         16  
  4         159  
9              
10 4     4   33 use Log::Any qw($log);
  4         7  
  4         20  
11              
12 4     4   249 use Exporter;
  4         8  
  4         4958  
13              
14             our @ISA = qw(Exporter);
15             our @EXPORT_OK = qw(selectrow selectrow_array selectrow_hashref selectall selectall_arrayref selectall_hashref dbh_do do err last_insert_id);
16             our %EXPORT_TAGS = (all => [@EXPORT_OK]);
17              
18             our $VERSION = '0.03_1';
19              
20             sub new {
21 0     0 0 0 my ($class) = shift;
22 0         0 $class->connect(@_);
23             }
24              
25             sub connect {
26 3     3 0 848 my ($class, @arguments) = @_;
27              
28 3         10 my $self = {};
29              
30 3 50 33     125 if (defined $arguments[0] and UNIVERSAL::isa($arguments[0], 'DBI::db')) {
31 0         0 $self->{dont_disconnect} = 1;
32 0         0 $self->{dbh} = shift @arguments;
33 0 0       0 Carp::carp("Additional arguments for $class->connect are ignored") if @arguments;
34             } else {
35 3 50 33     29 $arguments[3]->{PrintError} = 0
36             unless defined $arguments[3] and exists $arguments[3]{PrintError};
37 3 50 33     29 $arguments[3]->{RaiseError} = 1
38             unless defined $arguments[3] and exists $arguments[3]{RaiseError};
39 3         40 $self->{dbh} = DBI->connect(@arguments);
40             }
41              
42 3 50       4514 return undef unless $self->{dbh};
43              
44 3         136 $self->{dbd} = $self->{dbh}->{Driver}->{Name};
45 3         14 bless $self, $class;
46              
47 3         15 return $self;
48             }
49              
50             sub disconnect {
51 2     2 0 1889 my $self = shift;
52 2         62 $self->{dbh}->disconnect();
53             }
54              
55             sub dbh {
56 100     100 0 183 my $self = shift;
57 100         1064 return $self->{dbh};
58             }
59              
60             sub do {
61 24     24 0 26387 return shift->dbh_do(@_); # just an alias
62             }
63              
64             sub err {
65 6     6 0 10 my $self = shift;
66 6         35 return $self->{dbh}->err;
67             }
68              
69             sub last_insert_id {
70 2     2 0 6 my ($self, @args) = @_;
71 2         10 return $self->{dbh}->last_insert_id(@args);
72             }
73              
74             sub update_query {
75 1     1 0 3 my ($self, $table) = @_;
76 1         12 return DBIx::Foo::UpdateQuery->new($table, $self);
77             }
78              
79             1;
80              
81             __END__