| 1 | package DBIx::dbMan::Config; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use locale; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use vars qw/$AUTOLOAD/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use POSIX; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 3 | our $VERSION = '0.04'; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 3 | 1; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 13 | 0 | my $class = shift; | |||||||||||||||||||||||||||
| 14 | 0 | my $obj = bless { @_ }, $class; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 0 | $obj->{config} = {}; | |||||||||||||||||||||||||||
| 17 | 0 | ▶ | $obj->{configfile} = $obj->{-file} || $obj->_configfile(); | ||||||||||||||||||||||||||
|
Condition0%0/3
$obj->{'-file'} || $obj->_configfile
MC/DC0%0/2
$obj->{'-file'} || $obj->_configfile
$obj->{'-file'}
$obj->_configfile
Truth table0%0/3
A || B
A= $obj->{'-file'}B= $obj->_configfile
| |||||||||||||||||||||||||||||
| 18 | 0 | ▶ | $obj->_load if $obj->{configfile}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 0 | return $obj; | |||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 0 | ▶ | sub _bhashes { | ||||||||||||||||||||||||||
|
Subroutine
_bhashes: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 24 | 0 | my $line = shift; | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 0 | $line =~ s/#/\\#/g; | |||||||||||||||||||||||||||
| 27 | 0 | return $line; | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 0 | ▶ | sub _load { | ||||||||||||||||||||||||||
|
Subroutine
_load: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||
| 31 | 0 | my $obj = shift; | |||||||||||||||||||||||||||
| 32 | 0 | ▶ | if (open F,$obj->{configfile}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | 0 | ▶ | while (<F>) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | 0 | my $key; my $value; | |||||||||||||||||||||||||||
| 35 | 0 | chomp; | |||||||||||||||||||||||||||
| 36 | 0 | s/\\/\\\\/g; # double backslashes | |||||||||||||||||||||||||||
| 37 | 0 | s/^(['"])(.*?)([^\\])\1/$1.(_bhashes($2.$3)).$1/eg; | |||||||||||||||||||||||||||
| 38 | 0 | s/([^\\])(['"])(.*?)([^\\])\2/$1.$2.(_bhashes($3.$4)).$2/eg; | |||||||||||||||||||||||||||
| 39 | # backslash # in '' | ||||||||||||||||||||||||||||
| 40 | 0 | s/^#.*$//; # whole-line comment | |||||||||||||||||||||||||||
| 41 | 0 | s/([^\\])#.*$/$1/; # other comment | |||||||||||||||||||||||||||
| 42 | 0 | s/\\#/#/g; # unbackslash # | |||||||||||||||||||||||||||
| 43 | 0 | s/\\\\/\\/g; # single backslashes | |||||||||||||||||||||||||||
| 44 | 0 | s/^\s+//; # starting whitespaces | |||||||||||||||||||||||||||
| 45 | 0 | s/\s+$//; # ending whitespaces | |||||||||||||||||||||||||||
| 46 | 0 | ▶ | next unless $_; # empty line | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 0 | ▶ | if (/^(\S+)\s+(.*)$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | 0 | ($key,$value) = ($1,$2); | |||||||||||||||||||||||||||
| 49 | } else { | ||||||||||||||||||||||||||||
| 50 | 0 | ($key,$value) = ($_,''); | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | 0 | $value =~ s/^(['"])(.*)\1$/$2/; # quoted line | |||||||||||||||||||||||||||
| 53 | 0 | push @{$obj->{config}->{$key}},$value; | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | 0 | close F; | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 0 | ▶ | sub merge { | ||||||||||||||||||||||||||
|
Subroutine
merge: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 60 | 0 | my ($obj,$config) = @_; | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 0 | ▶ | return 0 unless $config; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 0 | for my $tag ($config->all_tags) { | |||||||||||||||||||||||||||
| 65 | 0 | ▶ | if ( ref $config->$tag eq "ARRAY" ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | 0 | push @{$obj->{config}->{$tag}}, @{$config->$tag}; | |||||||||||||||||||||||||||
| 67 | } else { | ||||||||||||||||||||||||||||
| 68 | 0 | push @{$obj->{config}->{$tag}}, $config->$tag; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | 0 | return 1; | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 0 | ▶ | sub _configfile { | ||||||||||||||||||||||||||
|
Subroutine
_configfile: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 75 | 0 | my $obj = shift; | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 0 | my $res = $ENV{DBMAN_CONFIG}; | |||||||||||||||||||||||||||
| 78 | 0 | ▶ | return $res if $res and -e $res; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$res and -e $res
MC/DC0%0/2
$res and -e $res
$res
-e $res
Truth table0%0/3
A and B
A= $resB= -e $res
| |||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 0 | $res = $ENV{HOME}.'/.dbman/config'; | |||||||||||||||||||||||||||
| 81 | 0 | ▶ | return $res if -e $res; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 0 | return '/etc/dbman.conf'; | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 0 | ▶ | sub all_tags { | ||||||||||||||||||||||||||
|
Subroutine
all_tags: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 87 | 0 | my $obj = shift; | |||||||||||||||||||||||||||
| 88 | 0 | return keys %{$obj->{config}}; | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 0 | ▶ | sub AUTOLOAD { | ||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||
| 92 | 0 | my $obj = shift; | |||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 0 | $AUTOLOAD =~ s/^DBIx::dbMan::Config:://; | |||||||||||||||||||||||||||
| 95 | 0 | my $res = $obj->{config}->{$AUTOLOAD}; | |||||||||||||||||||||||||||
| 96 | 0 | ▶ | if (defined $res) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | 0 | ▶ | if (ref $res and scalar @$res > 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $res and scalar @$res > 1
MC/DC0%0/2
ref $res and scalar @$res > 1
ref $res
scalar @$res > 1
Truth table0%0/3
A and B
A= ref $resB= scalar @$res > 1
| |||||||||||||||||||||||||||||
| 98 | 0 | ▶ | return wantarray ? @$res : $res; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | } else { | ||||||||||||||||||||||||||||
| 100 | 0 | ▶ | return wantarray ? @$res : $res->[0]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | } else { | ||||||||||||||||||||||||||||
| 103 | 0 | return undef; | |||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||