« blib/lib/Lemonldap/NG/Common/Combination/Parser.pm
↑ Summary
blib/lib/Lemonldap/NG/Common/PSGI/Cli/Lib.pm »
| 1 | package Lemonldap::NG::Common::Conf::Backends::_DBI; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 4 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use DBI; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use Lemonldap::NG::Common::Conf::Constants; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 4 | ▶ | use Lemonldap::NG::Common::Lib::DBI qw(check_dbh); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 4 | our $VERSION = '2.22.2'; | |||||||||||||||||||||||||||||||||||||||||
| 11 | 4 | our @ISA = qw(Lemonldap::NG::Common::Conf::Constants); | |||||||||||||||||||||||||||||||||||||||||
| 12 | 4 | our ( @EXPORT, %EXPORT_TAGS ); | |||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 4 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 4 | *Lemonldap::NG::Common::Conf::_dbh = \&_dbh; | |||||||||||||||||||||||||||||||||||||||||
| 16 | 4 | *Lemonldap::NG::Common::Conf::_execute = \&_execute; | |||||||||||||||||||||||||||||||||||||||||
| 17 | 4 | push @EXPORT, @Lemonldap::NG::Common::Conf::Constants::EXPORT; | |||||||||||||||||||||||||||||||||||||||||
| 18 | 4 | %EXPORT_TAGS = %Lemonldap::NG::Common::Conf::Constants::EXPORT_TAGS; | |||||||||||||||||||||||||||||||||||||||||
| 19 | 4 | push @EXPORT, | |||||||||||||||||||||||||||||||||||||||||
| 20 | qw(prereq available lastCfg _dbh lock isLocked unlock delete logError); | ||||||||||||||||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 11 | ▶ | sub prereq { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
prereq: called CC=4 SCAR=15.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 11 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 25 | 11 | ▶ | unless ( $self->{dbiChain} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | $Lemonldap::NG::Common::Conf::msg = | |||||||||||||||||||||||||||||||||||||||||
| 27 | '"dbiChain" is required in *DBI configuration type'; | ||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||||
| 30 | $Lemonldap::NG::Common::Conf::msg .= | ||||||||||||||||||||||||||||||||||||||||||
| 31 | 'Warning: "dbiUser" parameter is not set' | ||||||||||||||||||||||||||||||||||||||||||
| 32 | 11 | ▶ | unless ( $self->{dbiUser} ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 11 | ▶ | $self->{dbiTable} ||= "lmConfig"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{"dbiTable"} ||= "lmConfig"
MC/DC0%0/1
$self->{"dbiTable"} ||= "lmConfig"
$self->{"dbiTable"}
Truth table50%1/2
A
A= $self->{"dbiTable"}
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | 11 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | sub available { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
available: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 39 | my $sth = | ||||||||||||||||||||||||||||||||||||||||||
| 40 | $self->_execute( "SELECT DISTINCT cfgNum from " | ||||||||||||||||||||||||||||||||||||||||||
| 41 | . $self->{dbiTable} | ||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | . " order by cfgNum" ); | |||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | my @conf; | |||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | ▶ | while ( my @row = $sth->fetchrow_array ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | push @conf, $row[0]; | |||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | return @conf; | |||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | 18 | ▶ | sub lastCfg { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
lastCfg: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 18 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 52 | 18 | my $sth = $self->_execute( "SELECT max(cfgNum) from " . $self->{dbiTable} ); | |||||||||||||||||||||||||||||||||||||||||
| 53 | 11 | my @row = $sth->fetchrow_array(); | |||||||||||||||||||||||||||||||||||||||||
| 54 | 11 | return $row[0]; | |||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | 60 | ▶ | sub _dbh { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dbh: called CC=11 SCAR=26.3
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 60 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 59 | 60 | ▶ | $self->{dbiTable} ||= "lmConfig"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{"dbiTable"} ||= "lmConfig"
MC/DC0%0/1
$self->{"dbiTable"} ||= "lmConfig"
$self->{"dbiTable"}
Truth table50%1/2
A
A= $self->{"dbiTable"}
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | 60 | my $dbh = check_dbh( $self->{_dbh} ); | |||||||||||||||||||||||||||||||||||||||||
| 61 | 60 | ▶ | return $dbh if $dbh; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 21 | delete $self->{_dbh}; | |||||||||||||||||||||||||||||||||||||||||
| 63 | 21 | eval { | |||||||||||||||||||||||||||||||||||||||||
| 64 | $self->{_dbh} = | ||||||||||||||||||||||||||||||||||||||||||
| 65 | DBI->connect_cached( $self->{dbiChain}, $self->{dbiUser}, | ||||||||||||||||||||||||||||||||||||||||||
| 66 | 21 | $self->{dbiPassword}, { RaiseError => 1, AutoCommit => 1, } ); | |||||||||||||||||||||||||||||||||||||||||
| 67 | 7 | ▶ | die unless $self->{_dbh}->ping; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 69 | 21 | ▶ | if ( $@ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$@ and $self->{"type"}->can("beforeRetry") and $self->{"type"}->can("beforeRetry")->($self)
$@ and $self->{"type"}->can("beforeRetry")
MC/DC66%2/3
$@ and $self->{"type"}->can("beforeRetry") and $self->{"type"}->can("beforeRetry")->($self)
$@
$self->{"type"}->can("beforeRetry")
$self->{"type"}->can("beforeRetry")->($self)
Truth table75%3/4
A and B and C
A= $@B= $self->{"type"}->can("beforeRetry")C= $self->{"type"}->can("beforeRetry")->($self)
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | and $self->{type}->can('beforeRetry') | ||||||||||||||||||||||||||||||||||||||||||
| 71 | and $self->{type}->can('beforeRetry')->($self) ) | ||||||||||||||||||||||||||||||||||||||||||
| 72 | { | ||||||||||||||||||||||||||||||||||||||||||
| 73 | 10 | eval { | |||||||||||||||||||||||||||||||||||||||||
| 74 | $self->{_dbh} = | ||||||||||||||||||||||||||||||||||||||||||
| 75 | DBI->connect_cached( $self->{dbiChain}, $self->{dbiUser}, | ||||||||||||||||||||||||||||||||||||||||||
| 76 | 10 | $self->{dbiPassword}, { RaiseError => 1, AutoCommit => 1, } ); | |||||||||||||||||||||||||||||||||||||||||
| 77 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||
| 79 | 21 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 12 | die $@; | |||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||
| 82 | 9 | ▶ | if ( $self->{dbiChain} =~ /^dbi:sqlite/i ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | 9 | $self->{_dbh}->{sqlite_unicode} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||
| 85 | elsif ( $self->{dbiChain} =~ /^dbi:mysql/i ) { | ||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | eval { | |||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | $self->{_dbh}->{mysql_enable_utf8} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | $self->{_dbh}->do("set names 'utf8'"); | |||||||||||||||||||||||||||||||||||||||||
| 89 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||
| 91 | elsif ( $self->{dbiChain} =~ /^dbi:pg/i ) { | ||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | $self->{_dbh}->{pg_enable_utf8} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | # DBD::MariaDB should have o problem here | ||||||||||||||||||||||||||||||||||||||||||
| 96 | 9 | return $self->{_dbh}; | |||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | ▶ | sub lock { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
lock: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | sub isLocked { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
isLocked: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | ▶ | sub unlock { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unlock: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | ▶ | sub delete { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
delete: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | my ( $self, $cfgNum ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | my $res = $self->_execute( "DELETE FROM $self->{dbiTable} WHERE cfgNum=?", | |||||||||||||||||||||||||||||||||||||||||
| 117 | $cfgNum ); | ||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | return ( $res > 0 ); | |||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | ▶ | sub logError { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
logError: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | $Lemonldap::NG::Common::Conf::msg .= | |||||||||||||||||||||||||||||||||||||||||
| 124 | "Database error: " . $DBI::errstr . "\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||
| 127 | 42 | ▶ | sub _execute { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_execute: called CC=6 SCAR=24.0
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | 42 | my ( $self, $query, @prms ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 129 | 42 | my $req = $self->_dbh->prepare($query); | |||||||||||||||||||||||||||||||||||||||||
| 130 | 28 | ▶ | unless ($req) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | $self->logError; | |||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | return UNKNOWN_ERROR; | |||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||
| 134 | 28 | my $execute = eval { $req->execute(@prms) }; | |||||||||||||||||||||||||||||||||||||||||
| 135 | 28 | ▶ | if ( !$execute | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
not $execute and $self->{"type"}->can("beforeRetry") and $self->{"type"}->can("beforeRetry")->($self)
not $execute and $self->{"type"}->can("beforeRetry")
MC/DC0%0/3
not $execute and $self->{"type"}->can("beforeRetry") and $self->{"type"}->can("beforeRetry")->($self)
not $execute
$self->{"type"}->can("beforeRetry")
$self->{"type"}->can("beforeRetry")->($self)
Truth table25%1/4
not(A) and B and C
A= not $executeB= $self->{"type"}->can("beforeRetry")C= $self->{"type"}->can("beforeRetry")->($self)
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | and $self->{type}->can('beforeRetry') | ||||||||||||||||||||||||||||||||||||||||||
| 137 | and $self->{type}->can('beforeRetry')->($self) ) | ||||||||||||||||||||||||||||||||||||||||||
| 138 | { | ||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | $req = $self->_dbh->prepare($query); | |||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | $execute = eval { $req->execute(@prms) }; | |||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||
| 142 | 28 | ▶ | unless ($execute) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | $self->logError; | |||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | return UNKNOWN_ERROR; | |||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||
| 146 | 28 | return ( 1, $req ); | |||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | ▶ | sub beforeRetry { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
beforeRetry: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | return !$_[0]->{noRetry}; | |||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||