| 1 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | =encoding utf8 | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | =head1 NAME | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | Quiq::Database::Config - Datenbank-Konfiguration | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | =head1 BASE CLASS | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | L<Quiq::Config> | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | Die Klasse kapselt den Zugriff auf eine Konfigurationsdatei, in | ||||||||||||||||||||||||||||
| 16 | der Eingenschaften von einer oder mehrerer Datenbanken hinterlegt sind. | ||||||||||||||||||||||||||||
| 17 | Es können beliebige Eigenschaften spezifiziert werden. | ||||||||||||||||||||||||||||
| 18 | Speziell wird die Abfrage des Universal Database Locators (UDL) | ||||||||||||||||||||||||||||
| 19 | unterstützt. Die Datei darf wegen etwaig enthaltener Passwörter | ||||||||||||||||||||||||||||
| 20 | nur für den Owner lesbar/schreibbar sein. Ist sie es nicht, wird | ||||||||||||||||||||||||||||
| 21 | eine Exception geworfen. | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | =head2 Aufbau der Konfigurationsdatei | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | '<database>' => { | ||||||||||||||||||||||||||||
| 26 | udl => '<udl>', | ||||||||||||||||||||||||||||
| 27 | ... | ||||||||||||||||||||||||||||
| 28 | }, | ||||||||||||||||||||||||||||
| 29 | ... | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | =over 2 | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | =item * | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | <database> ist ein beliebger Bezeichner. | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | =item * | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | <udl> ist der UDL der Datenbank. | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | =item * | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | Der Konfigurationshash {...} wird im Konstruktor zu einem | ||||||||||||||||||||||||||||
| 44 | ungelockten Quiq::Hash instantiiert. Entsprechend können die | ||||||||||||||||||||||||||||
| 45 | Methoden der Klasse Quiq::Hash zum Lesen der | ||||||||||||||||||||||||||||
| 46 | Konfigurationseinträge genutzt werden. | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | =back | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | =head1 EXAMPLE | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | use Quiq::Database::Config; | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | $cfg = Quiq::Database::Config->new('~/project/test/db.conf'); | ||||||||||||||||||||||||||||
| 55 | $udl = $cfg->udl('test_db'); | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | =cut | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | package Quiq::Database::Config; | ||||||||||||||||||||||||||||
| 62 | 9 | ▶ | use base qw/Quiq::Config/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 9 | ▶ | use v5.10; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 65 | 9 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 66 | 9 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 9 | our $VERSION = '1.240'; | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 9 | ▶ | use Quiq::Path; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 71 | 9 | ▶ | use Quiq::Hash; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | =head1 METHODS | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | =head2 Klassenmethoden | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | =head3 new() - Konstruktor | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | =head4 Synopsis | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | $cfg = $class->new; | ||||||||||||||||||||||||||||
| 84 | $cfg = $class->new($file); | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | =head4 Arguments | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | =over 4 | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | =item $file (Default: '~/.db.conf') | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | Konfigurationsdatei | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | =back | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | =head4 Options | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | =over 4 | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | =item -sloppy => $bool (Default: 0) | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | Liefere C<undef>, wenn Datei C<$file> nicht existiert. | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | =back | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | =head4 Returns | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | Objekt | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | =head4 Description | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | Instantiiere ein Objekt der Klasse und liefere eine Referenz auf dieses | ||||||||||||||||||||||||||||
| 113 | Objekt zurück. | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | =cut | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=17.1
Pod
documented
| |||||||||||||||||||||||||||||
| 120 | 1 | my $class = shift; | |||||||||||||||||||||||||||
| 121 | # @_: $file,@opt | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | # Optionen | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 1 | my $sloppy = 0; | |||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 1 | my $argA = $class->parameters(0,1,\@_, | |||||||||||||||||||||||||||
| 128 | -sloppy => \$sloppy, | ||||||||||||||||||||||||||||
| 129 | ); | ||||||||||||||||||||||||||||
| 130 | 1 | ▶ | my $file = shift @$argA // '~/.db.conf'; | ||||||||||||||||||||||||||
|
Condition50%1/2
shift @$argA // "~/.db.conf"
MC/DC0%0/1
shift @$argA // "~/.db.conf"
shift @$argA
Truth table50%1/2
A
A= shift @$argA
| |||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 1 | ▶ | if (!Quiq::Path->exists($file) && $sloppy) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not "Quiq::Path"->exists($file) and $sloppy
MC/DC0%0/2
not "Quiq::Path"->exists($file) and $sloppy
not "Quiq::Path"->exists($file)
$sloppy
Truth table33%1/3
not(A) and B
A= not "Quiq::Path"->exists($file)B= $sloppy
| |||||||||||||||||||||||||||||
| 133 | 0 | return undef; | |||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | # Objekt instantiieren | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | 1 | my $self = $class->SUPER::new($file, | |||||||||||||||||||||||||||
| 139 | -secure => 1, | ||||||||||||||||||||||||||||
| 140 | ); | ||||||||||||||||||||||||||||
| 141 | 1 | for (keys %$self) { | |||||||||||||||||||||||||||
| 142 | 2 | $self->{$_} = Quiq::Hash->new($self->{$_})->unlockKeys; | |||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||
| 144 | 1 | $self->set(configFile=>$file); | |||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | 1 | return $self; | |||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | =head2 Objektmethoden | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | =head3 udl() - Universal Database Locator | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | =head4 Synopsis | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | $udl = $cfg->udl($database); | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | =head4 Arguments | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | =over 4 | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | =item $database | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | Name der Datenbank (String). | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | =back | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | =head4 Returns | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | Universal Database Locator (String). | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | =head4 Description | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | Ermittele den Universal Database Locator (UDL) der Datenbank $database | ||||||||||||||||||||||||||||
| 176 | und liefere diesen zurück. | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | =cut | ||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | 3 | ▶ | sub udl { | ||||||||||||||||||||||||||
|
Subroutine
udl: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||||||||||
| 183 | 3 | my ($self,$database) = @_; | |||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | 3 | ▶ | my $h = $self->try($database) // $self->throw( | ||||||||||||||||||||||||||
|
Condition66%2/3
$self->try($database) // $self->throw("CONFIG-00001: Database not defined", "Database", $database, "ConfigFile", $self->configFile)
MC/DC0%0/2
$self->try($database) // $self->throw("CONFIG-00001: Database not defined", "Database", $database, "ConfigFile", $self->configFile)
$self->try($database)
$self->throw("CONFIG-00001: Database not defined", "Database", $database, "ConfigFile", $self->configFile)
Truth table33%1/3
A // B
A= $self->try($database)B= $self->throw("CONFIG-00001: Database not defined", "Database", $database, "ConfigFile", $self->configFile)
| |||||||||||||||||||||||||||||
| 186 | 'CONFIG-00001: Database not defined', | ||||||||||||||||||||||||||||
| 187 | Database => $database, | ||||||||||||||||||||||||||||
| 188 | ConfigFile => $self->configFile, | ||||||||||||||||||||||||||||
| 189 | ); | ||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | 2 | ▶ | my $udl = $h->try('udl') // $self->throw( | ||||||||||||||||||||||||||
|
Condition66%2/3
$h->try("udl") // $self->throw("CONFIG-00002: No UDL", "Database", $database, "ConfigFile", $self->configFile)
MC/DC0%0/2
$h->try("udl") // $self->throw("CONFIG-00002: No UDL", "Database", $database, "ConfigFile", $self->configFile)
$h->try("udl")
$self->throw("CONFIG-00002: No UDL", "Database", $database, "ConfigFile", $self->configFile)
Truth table33%1/3
A // B
A= $h->try("udl")B= $self->throw("CONFIG-00002: No UDL", "Database", $database, "ConfigFile", $self->configFile)
| |||||||||||||||||||||||||||||
| 192 | 'CONFIG-00002: No UDL', | ||||||||||||||||||||||||||||
| 193 | Database => $database, | ||||||||||||||||||||||||||||
| 194 | ConfigFile => $self->configFile, | ||||||||||||||||||||||||||||
| 195 | ); | ||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | 1 | return $udl; | |||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | =head1 VERSION | ||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | 1.240 | ||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | Frank Seitz, L<http://fseitz.de/> | ||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | Copyright (C) 2026 Frank Seitz | ||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | =head1 LICENSE | ||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||
| 216 | This code is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||
| 217 | it under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||
| 219 | =cut | ||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | 9 | 1; | |||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||
| 225 | # eof | ||||||||||||||||||||||||||||