DB.pm

filter: Statementstmt 74.3% 55 / 74 Branchbran 55.5% 20 / 36 Conditioncond 100% 5 / 5 MC/DCmcdc 100% 3 / 3 Subroutinesub 83.3% 10 / 12 Podpod 75.0% 3 / 4 totaltotal 71.6% 96 / 134 CC 23 SCAR 28.0
CC
23
Cov
70%
get
50.1
new
10.0
read
6.5
CRAP 16.5
↑ Summary DB/Table.pm »
1 package Config::DB;
2  
3 3 $Config::DB::VERSION = '0.2';
4  
5 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use Config::DB::Record;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use Config::DB::Table;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use DBI;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 13 ▶sub new {
Subroutine new: called CC=10 SCAR=23.0
Pod documented
14 13 my ( $class, %pars ) = @_;
15 13 my $self = { %pars, read => 0, values => {} };
16  
17 13 ▶ croak __PACKAGE__ . "::new: wrong call" if !defined $class || $class eq '';
Branch: 1 branch
BranchTrueFalseTotal
if not defined $class or $class eq "" 2 11 13
Condition100%3/3
not defined $class or $class eq ""
l!l&&r!l&&!r
1111
MC/DC100%2/2
not defined $class or $class eq ""
not defined $class $class eq ""
Truth table100%3/3
not(A) or B
A= not defined $classB= $class eq ""
ABresult
1X1
011
000
18  
19 11 eval {
20 11 ▶ die
Branch: 1 branch
BranchTrueFalseTotal
if $class->check_Config_DB_hineritance ne "check_Config_DB_hineritance" 1 9 10
21 if $class->check_Config_DB_hineritance ne
22 'check_Config_DB_hineritance';
23 };
24 11 ▶ croak __PACKAGE__ . "::new: '$class' does not hinerit 'Config::DB'"
Branch: 1 branch
BranchTrueFalseTotal
if $@ ne "" 2 9 11
25 if $@ ne '';
26  
27 croak __PACKAGE__ . "::new: missing 'connect' paramenter"
28 9 ▶ if !defined $self->{connect};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"connect"} 1 8 9
29 croak __PACKAGE__
30 . "::new: 'connect' paramenter is not a reference to ARRAY"
31 8 ▶ if ref $self->{connect} ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $self->{"connect"} ne "ARRAY" 1 7 8
32 croak __PACKAGE__ . "::new: missing 'tables' paramenter"
33 7 ▶ if !defined $self->{tables};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"tables"} 1 6 7
34 croak __PACKAGE__ . "::new: 'tables' paramenter is not a reference to HASH"
35 6 ▶ if ref $self->{tables} ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $self->{"tables"} ne "HASH" 1 5 6
36 croak __PACKAGE__ . "::new: no tables defined"
37 5 ▶ if 0 == scalar keys %{ $self->{tables} };
Branch: 1 branch
BranchTrueFalseTotal
if 0 == scalar keys %{$$self{"tables"};} 1 4 5
38  
39 4 return bless $self, $class;
40 }
41  
42 3 our $AUTOLOAD;
43  
44 0 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: not called CC=2 SCAR=17.9
45 0 my ( $self, @pars ) = @_;
46 0 my $name = $AUTOLOAD;
47  
48 0 $name =~ s/.*://;
49  
50 0 ▶ croak "Can't locate object method \"$name\" via package \""
Branch: 1 branch
BranchTrueFalseTotal
unless $name =~ /^_/ 0 0 0
51 . __PACKAGE__ . '"'
52 unless $name =~ /^_/;
53  
54 0 $name =~ s/^_//;
55  
56 0 return $self->get( $name, @pars );
57 }
58  
59 0 ▶sub DESTROY {
Subroutine DESTROY: not called CC=1 SCAR=0.0
60 }
61  
62 9 ▶sub check_Config_DB_hineritance {
Subroutine check_Config_DB_hineritance: called CC=1 SCAR=0.0
Pod undocumented
63 9 return 'check_Config_DB_hineritance';
64 }
65  
66 2 ▶sub get {
Subroutine get: called CC=8 SCAR=39.1
Pod documented
67 2 my ( $self, $table, $key, $field ) = @_;
68  
69 2 ▶ $self->read unless $self->{read};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"read"} 2 0 2
70  
71 0 ▶ croak __PACKAGE__ . "::get: missing table parameter" unless defined $table;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $table 0 0 0
72 croak __PACKAGE__ . "::get: unknown configuration table '$table'"
73 0 ▶ unless exists $self->{values}->{$table};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"values"}{$table} 0 0 0
74  
75 0 ▶ return $self->{values}->{$table} unless defined $key;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $key 0 0 0
76  
77 croak __PACKAGE__
78 . "::get: missing key '$key' in configuration table '$table'"
79 0 ▶ unless exists $self->{values}->{$table}->{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"values"}{$table}{$key} 0 0 0
80  
81 0 ▶ return $self->{values}->{$table}->{$key} unless defined $field;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $field 0 0 0
82  
83 croak __PACKAGE__
84 . "::get: unknown field '$field' for configuration table '$table'"
85 0 ▶ unless exists $self->{values}->{$table}->{$key}->{$field};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"values"}{$table}{$key}{$field} 0 0 0
86  
87 0 return $self->{values}->{$table}->{$key}->{$field};
88 }
89  
90 7 ▶sub read {
Subroutine read: called CC=6 SCAR=18.7
Pod documented
91 7 my ($self) = @_;
92 7 my @connect = @{ $self->{connect} };
93 7 ▶ my %attr = %{ $connect[3] || {} };
Condition100%2/2
$connect[3] || {}
l!l
34
MC/DC100%1/1
$connect[3] || {}
$connect[3]
Truth table100%2/2
A
A= $connect[3]
Aresult
11
00
94 7 my $dbh;
95  
96 7 $attr{PrintError} = 0;
97 7 $attr{RaiseError} = 1;
98 7 $connect[3] = \%attr;
99  
100 7 eval { $dbh = DBI->connect(@connect); };
101 7 ▶ croak "$@\n" . __PACKAGE__ . "::read: can't connect" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 1 6 7
102  
103 6 foreach my $table ( keys %{ $self->{tables} } ) {
104 6 my $t;
105  
106 6 eval {
107 6 $t = $dbh->selectall_hashref(
108 "SELECT $self->{tables}->{$table} AS dbcfg_key, $table.* FROM $table",
109 'dbcfg_key'
110 );
111 };
112 6 ▶ croak "$@\n" . __PACKAGE__ . "::read: reading '$table' table" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 6 0 6
113 0 $self->{values}->{$table} = $t;
114  
115 0 foreach my $key ( keys %$t ) {
116 0 delete $t->{$key}->{dbcfg_key};
117 0 bless $t->{$key}, 'Config::DB::Record';
118 }
119  
120 0 bless $t, 'Config::DB::Table';
121 }
122  
123 0 $self->{read} = 1;
124 }
125  
126 3 1;
127  
128 __END__
↑ Summary DB/Table.pm »