view release on metacpan or search on metacpan
CHANGES.txt view on Meta::CPAN
Version history:
----------------
Version 1.7 13.07.2003
+ Added SPECIAL configuration constants HOUR, MIN, SEC and WDAY
+ Added mention of showchain.pl to the Config::Manager manpage
+ Corrected the description of "MakeDir()" in File.pm
+ Script showchain.pl doesn't pipe output via "more" anymore
+ Removed excessive indentation from the output of showconf.pl
+ Now 'source' and 'line' attributes for $[SPECIAL]{HOME} and
$[SPECIAL]{WHOAMI} are properly set
Version 1.6 28.06.2003
Config::Manager::Report:
+ The name and path of the default logfile can now be influenced
(the "singleton()" class method now passes arguments to "new()")
+ Changed the default path and filename of logfile objects
(now uses the user login to discriminate further)
+ Adapted the test suite accordingly
CHANGES.txt view on Meta::CPAN
scripts:
+ Added the script "showchain.pl" to show the chain of
configuration files which are read in for a given
scope and user
+ Changed the script "showconf.pl" to also show the file
of origin and line number of each configuration constant
Version 1.5 09.06.2003
+ Added constant $[SPECIAL]{PERL} which contains $^X
Version 1.4 18.05.2003
+ Changed some wordings in Config::Manager::Report
+ Fixed syntax error in Config::Manager::SendMail
+ Improved the overview manual page "Config::Manager"
+ Added "Normalize()" and "MakeDir()" to Config::Manager::File
+ Added missing documentation parts to Config::Manager::File
+ Config::Manager::File now localizes all global Perl variables
+ Config::Manager::File now uses file locking (flock)
tatsächlich angefordert wird (dies wird als "Lazy Evaluation"
bezeichnet), d.h. Konfigurationskonstanten, die vom Programm nicht
benötigt werden, müssen auch nicht ausgewertet werden, was zu
einer deutlichen Performance-Steigerung führt.
Diese String-Interpolation benutzt dabei eine Syntax, die stark an
Shell- und Perl-Programme angelehnt ist (während der Aufbau der
Dateien selbst von Windows inspiriert ist):
[DEFAULT]
# $[SPECIAL]{OS} enthält den Namen des aktuellen Betriebssystems:
Home-Dir = $[$[SPECIAL]{OS}]{Home-Dir}
Group-Dir = $[$[SPECIAL]{OS}]{Group-Dir}
Group-User = $[$[SPECIAL]{OS}]{Group-User}
TEMPDIRPATH = $[$[SPECIAL]{OS}]{TEMPDIRPATH}
LOGFILEPATH = ${Group-Dir}/Tools/Logfiles
CONFIGPATH = ${Group-Dir}/Tools/Config
GLOBALCONF = ${CONFIGPATH}/Global/DEFAULT.ini
[MSWin32]
Home-Dir = U:
Group-Dir = G:
Group-User = Administrator
TEMPDIRPATH = C:/Temp
[freebsd]
Base-Dir = /u
Home-Dir = $[UNIX]{Home-Dir}
Group-Dir = $[UNIX]{Group-Dir}
Group-User = projadmin
TEMPDIRPATH = /tmp
[UNIX]
# Die folgende Zeile holt das Home-Dir des aktuellen Benutzers aus /etc/passwd:
Home-Dir = $[SPECIAL]{HOME}
Group-Dir = $[$[SPECIAL]{OS}]{Base-Dir}/$[$[SPECIAL]{OS}]{Group-User}
[Manager]
GROUPCONF = $[DEFAULT]{CONFIGPATH}/Group/GROUP.ini
NEXTCONF = $[DEFAULT]{Home-Dir}/Config/USER.ini
Zusätzlich zur String-Interpolation besteht ausserdem die
Möglichkeit zur sogenannten "Indirektion", d.h. eine
Konfigurationskonstante kann ihrerseits den symbolischen Namen
einer anderen Konfigurationskonstanten (oder einer
"Section"-Überschrift) enthalten, deren Inhalt dann (per
String-Interpolation) eingefügt werden soll.
Hinweis: Der Inhalt der Konfigurationsdateien lässt sich ganz
wie bei "INI"-Dateien unter Windows mit Hilfe von "Section"-
What's new in version 1.7:
--------------------------
+ Added SPECIAL configuration constants HOUR, MIN, SEC and WDAY
+ Added mention of showchain.pl to the Config::Manager manpage
+ Corrected the description of "MakeDir()" in File.pm
+ Script showchain.pl doesn't pipe output via "more" anymore
+ Removed excessive indentation from the output of showconf.pl
+ Now 'source' and 'line' attributes for $[SPECIAL]{HOME} and
$[SPECIAL]{WHOAMI} are properly set
Legal issues:
-------------
This package with all its parts is
Copyright (c) 2003 by Steffen Beyer & Gerhard Albers.
All rights reserved.
lib/Config/Manager/Conf.ini view on Meta::CPAN
# ist! (Statt dessen die \xFF-Schreibweise benutzen!) #
# (Gilt nur bei parallelem Einsatz auf DOS/Unix) #
# #
###############################################################
[DEFAULT]
CONFIGPATH = t
LOGFILEPATH = .
[Manager]
NEXTCONF = $[DEFAULT]{CONFIGPATH}/hard_defaults.ini
[TEST]
NEXTCONF = t/TEST.ini
lib/Config/Manager/Conf.pm view on Meta::CPAN
return 1;
}
################################################################################
# Private Funktionen
################################################################################
sub _name_ {
my $key = pop;
my $sec = pop || $DEFAULT;
return "\$[$sec]{$key}";
}
sub _not_found_ {
return "Configuration constant " . _name_(@_) . " not found";
}
sub _read_only_ {
return "Configuration constant " . _name_(@_) . " is read-only";
}
lib/Config/Manager/Conf.pm view on Meta::CPAN
$@ = $self->error();
return ();
}
else {
if ($section eq '') { return( "[$section]$variable", $rest ); }
else { return( $variable, $rest ); }
}
}
else {
if ($section eq '') { $@ = "found '\$' followed by '$first', expecting '{' or [A-Za-z]"; }
else { $@ = "found '\$[$section]' followed by '$first', expecting '{' or [A-Za-z]"; }
return ();
}
}
1;
__END__
=head1 NAME
lib/Config/Manager/Conf.pm view on Meta::CPAN
# ... beginnt hier der erste Abschnitt:
[DIRECTORIES]
# Innerhalb des Abschnitts folgen Schluessel-Wert-Paare:
ROOT = D:\work
# Die Variable $ROOT wird durch den oben definierten Wert substituiert:
TMP = $ROOT\tmp
# Ein neuer Abschnitt:
[FILES]
# Auch Variablen eines anderen Abschnitts sind verfuegbar:
TMPFILE1 = $[DIRECTORIES]{TMP}\tempfile1.txt
# Wer unbedingt Anfuehrungszeichen verwenden moechte, bitteschoen:
TMPFILE2 = "$[DIRECTORIES]{TMP}\tempfile2.txt"
# Noch ein Abschnitt
[DIVERSES]
# Wenn ich ein Dollarzeichen '$' brauche:
MS = "Micro$$oft"
# Backslash '\' hat keine Sonderbedeutung:
SW = Sun\$MS\IBM
# Wenn ich ein '$' vor einem '$' von einer Substitution brauche:
BD = $$$[SO]{WHAT}
# Variablennamen koennen in geschweifte Klammern gesetzt werden,
# muessen aber (ausser bei Indirektion) nicht:
MESSAGE1 = Schreibe alles nach $[FILES]TMPFILE1
MESSAGE2 = Schreibe alles nach $[FILES]{TMPFILE2}
# Ein Schluessel-Wert-Paar kann durch einen Dollar eingeleitet werden, um
# sowohl Shell- als auch Perl-Programmierer zufriedenzustellen :-). Der
# Dollar ist aber ohne Bedeutung, d.h. folgende Zeilen sind gleichwertig:
$KEY = Value
KEY = Value
Tritt in mehreren Dateien ein Schluessel im gleichen Abschnitt auf, so gilt der
zuerst eingelesene Wert. Anders formuliert, man muss die massgeblichen Dateien
zuerst, Dateien mit Default-Einstellungen zuletzt einlesen. Die Methode set()
lib/Config/Manager/Conf.pm view on Meta::CPAN
doppelt geschrieben werden: "$$".
2) Variablen werden durch einen vorangestellten einfachen Dollar "$"
gekennzeichnet. Der Variablenname ist der Name des Schluessels, dem
der Abschnittsname vorangestellt werden kann. Der Abschnittsname
wird dabei in eckige Klammern ("[]") eingefasst. Der Variablen-
name kann zur Vermeidung von Mehrdeutigkeiten in geschweifte
Klammern ("{}") eingefasst werden. Zwischen Abschnittsnamen und
Variablennamen darf kein Leerraum stehen. Beispiele:
$Var, $[Sec]Var, ${Var}, $[Sec]{Var}, Text${Var}Text
Der Name eines Abschnitts oder einer Variablen muss mit einem
Buchstaben beginnen, gefolgt von beliebig vielen Zeichen (auch
null) aus a-z, A-Z, 0-9, Unterstrich "_" und Bindestrich "-". Der
Name darf nicht mit einem Bindestrich enden.
Gross- und Kleinschreibung wird unterschieden. (!)
3) Die Indirektion ist grundsaetzlich nur zwischen Klammern
moeglich, da zwei aufeinanderfolgende Dollarzeichen ("$")
fuer ein literales Dollarzeichen stehen ("$$var" steht
fuer den literalen String "$var"). Beispiele:
$VAR, ${VAR}, ${$var}, $[SEC]VAR, $[SEC]{VAR},
$[SEC]{$var}, $[$sec]VAR, $[$sec]{VAR}, $[$sec]{$var}
4) Bei einer Indirektion kann eine Variable den Namen eines Abschnitts
ODER den Namen einer Variablen enthalten, aber nicht beides; z.B.:
$Section = Person
$Variable = Name
$Fullname = $[$Section]{$Variable}
Dagegen geht folgendes NICHT:
$Variable = Person::Name
$Fullname = ${$Variable}
Mit anderen Worten: Eine Variable, deren Wert zur Indirektion
eingesetzt wird, darf nur einen String enthalten, der dem
regulaeren Ausdruck ^[a-zA-Z][a-zA-Z0-9_-]*$ genuegt und
nicht mit einem Bindestrich endet.
lib/Config/Manager/Conf.pm view on Meta::CPAN
ganz normale Literale.
GRAMMATIK:
S = @ |
A S |
V S
V = $X |
${X} |
$[X]X | (Interpolation)
$[X]{X} |
---------------------------------
${V} |
$[V]X | (Indirektion)
$[V]{X} |
$[X]{V} |
$[V]{V}
X = (A-Za-z)(A-Za-z0-9_-)*
Erlaeuterungen:
"@" steht hier fuer den leeren String.
"A" steht fuer beliebige ASCII-Zeichen;
allerdings muss fuer jedes Dollarzeichen
("$") ein doppeltes Dollarzeichen ("$$")
lib/Config/Manager/Conf.pm view on Meta::CPAN
Der erste Wert gibt an, ob es sich bei dem dritten Wert um den Inhalt
der betreffenden Konfigurationskonstanten handelt, oder um eine Fehlermeldung
(weil der Wert nicht erfolgreich bestimmt werden konnte, z.B. aufgrund
nicht aufloesbarer eingebetteter Konfigurationskonstanten).
Der Wert "1" bedeutet "alles in Ordnung", der Wert "0" bedeutet, dass
es sich um eine Fehlermeldung handelt.
Der zweite Wert gibt den Namen der Konfigurationskonstanten in der Form
"C<$[SECTION]{VARIABLE}>" an.
Der dritte Wert enthaelt entweder den Wert der Konfigurationskonstanten
oder eine Fehlermeldung.
Der vierte Wert des Tupels gibt die Quelle an, aus dem die betreffende
Konfigurationskonstante stammt.
Der fuenfte Wert gibt die Zeilennummer in der Quelle an. Dieser kann
den Wert Null haben, falls es sich bei der Quelle nicht um eine Datei
gehandelt hat (sondern zum Beispiel um einen expliziten Aufruf der
lib/Config/Manager/Conf.pm view on Meta::CPAN
=back
=head1 PRIVATE FUNKTIONEN
=over 4
=item *
C<_name_([section,] key)>
Ich gebe den Namen in der Form C<$[section]{key}> zurueck. Ist
keine Section oder die DEFAULT-Section angegeben, dann wird als
Section C<[DEFAULT]> geschrieben.
=item *
C<_not_found_([section,] key)>
Ich gebe den String "C<Configuration constant $[section]{key} not found>"
zurueck. Ist keine Section oder die DEFAULT-Section angegeben,
dann wird als Section C<[DEFAULT]> geschrieben.
=item *
C<_read_only_([section,] key)>
Ich gebe den String "C<Configuration constant $[section]{key} is read-only>"
zurueck. Ist keine Section oder die DEFAULT-Section angegeben,
dann wird als Section C<[DEFAULT]> geschrieben.
=back
=head1 SEE ALSO
Config::Manager(3),
Config::Manager::Base(3),
Config::Manager::File(3),
t/01_____config.t view on Meta::CPAN
$conf->get('HELLO') eq 'hello' ? ok() : nok();
############################################################
# Doppelte Schluessel
############################################################
# Doppelter Schluessel in Default-Section
$conf = Config::Manager::Conf->new();
defined $conf->add('t/conf_err_dk01.ini') ? nok() : ok();
# Fehlermeldung?
$conf->error() eq "Double entry in file 't/conf_err_dk01.ini' for configuration constant \$[DEFAULT]{A} in line #6 and #8" ? ok() : nok();
# Voriger Wert trotzdem eingelesen?
$conf->get('HELLO') eq 'hello' ? ok() : nok();
# Doppelter Schluessel in einer Section
$conf = Config::Manager::Conf->new();
defined $conf->add('t/conf_err_dk02.ini') ? nok() : ok();
# Fehlermeldung?
$conf->error() eq "Double entry in file 't/conf_err_dk02.ini' for configuration constant \$[ONE]{A} in line #8 and #10" ? ok() : nok();
# Voriger Wert trotzdem eingelesen?
$conf->get('HELLO') eq 'hello' ? ok() : nok();
# Doppelter Schluessel in einer zweigeteilten Section
$conf = Config::Manager::Conf->new();
defined $conf->add('t/conf_err_dk03.ini') ? nok() : ok();
# Fehlermeldung?
$conf->error() eq "Double entry in file 't/conf_err_dk03.ini' for configuration constant \$[ONE]{A} in line #8 and #14" ? ok() : nok();
# Voriger Wert trotzdem eingelesen?
$conf->get('HELLO') eq 'hello' ? ok() : nok();
# Doppelter nextconf-Eintrag
$conf = Config::Manager::Conf->new();
defined $conf->add('t/conf_err_dk04.ini') ? nok() : ok();
# Fehlermeldung?
$conf->error() eq "Double entry in file 't/conf_err_dk04.ini' for configuration constant \$[NONE]{NEXTCONF} in line #8 and #9" ? ok() : nok();
# Voriger Wert trotzdem eingelesen?
$conf->get('HELLO') eq 'hello' ? ok() : nok();
############################################################
# Fehlerhafte Werte
############################################################
# Kein Wert angegeben
$conf = Config::Manager::Conf->new();
defined $conf->add('t/conf_err_val01.ini') ? nok() : ok();
t/01_____config.t view on Meta::CPAN
$conf->error() eq "Syntax error in file 't/conf_err_val06.ini' line #6 [DEFAULT]: missing key name after section name 'A', unexpected end of string" ? ok() : nok();
# Verunglueckte qualifizierte Substition: Nur oeffnende Klammer und Section
$conf = Config::Manager::Conf->new();
defined $conf->add('t/conf_err_val07.ini') ? nok() : ok();
$conf->error() eq "Syntax error in file 't/conf_err_val07.ini' line #6 [DEFAULT]: expecting identifier or variable, unexpected end of string" ? ok() : nok();
# Verunglueckte qualifizierte Substition: Nur Section und schliessende Klammer
$conf = Config::Manager::Conf->new();
defined $conf->add('t/conf_err_val08.ini') ? nok() : ok();
$conf->error() eq "Syntax error in file 't/conf_err_val08.ini' line #6 [DEFAULT]: found '\$[A]' followed by '}', expecting '{' or [A-Za-z]" ? ok() : nok();
# Verunglueckte Substition: Dollar am Zeilenende
$conf = Config::Manager::Conf->new();
defined $conf->add('t/conf_err_val09.ini') ? nok() : ok();
$conf->error() eq "Syntax error in file 't/conf_err_val09.ini' line #6 [DEFAULT]: illegal '\$' at end of string" ? ok() : nok();
# Verunglueckte Substition: Variable beginnt mit Bindestrich
$conf = Config::Manager::Conf->new();
defined $conf->add('t/conf_err_val10.ini') ? nok() : ok();
$conf->error() eq "Syntax error in file 't/conf_err_val10.ini' line #6 [DEFAULT]: found '\$' followed by '-', expecting '{' or [A-Za-z]" ? ok() : nok();
t/01_____config.t view on Meta::CPAN
defined $conf->add('t/conf_err_val11.ini') ? nok() : ok();
$conf->error() eq "Syntax error in file 't/conf_err_val11.ini' line #6 [DEFAULT]: illegal terminating '-' in identifier 'NO-NO-'" ? ok() : nok();
############################################################
# Schreibzugriffe auf reservierte Sections
############################################################
# Versuch, eine Umgebungsvariable aus einer Datei einzulesen
$conf = Config::Manager::Conf->new();
defined $conf->add('t/conf_err_wp01.ini') ? nok() : ok();
$conf->error() eq 'Configuration constant $[ENV]{TMP} is read-only' ? ok() : nok();
# Versuch, eine Umgebungsvariable zu setzen
$conf = Config::Manager::Conf->new();
defined $conf->set('ENV', 'DINGS', 'tralala') ? nok() : ok();
$conf->error() eq 'Configuration constant $[ENV]{DINGS} is read-only' ? ok() : nok();
# Versuch, eine SPECIAL-Variable aus einer Datei einzulesen
$conf = Config::Manager::Conf->new();
defined $conf->add('t/conf_err_wp02.ini') ? nok() : ok();
$conf->error() eq 'Configuration constant $[SPECIAL]{DINGS} is read-only' ? ok() : nok();
# SPECIAL-Variable mit set() setzen (das ist erlaubt!)
$conf = Config::Manager::Conf->new();
defined $conf->set('SPECIAL', 'DAY', '32') ? ok() : nok();
$conf->get('SPECIAL', 'DAY') eq '32' ? ok() : nok();
# SPECIAL::OS mit set() setzen (das ist wiederum nicht erlaubt)
$conf = Config::Manager::Conf->new();
defined $conf->set('SPECIAL', 'OS', 'CP/M') ? nok() : ok();
$conf->error() eq 'Configuration constant $[SPECIAL]{OS} is read-only' ? ok() : nok();
# SPECIAL::SCOPE mit set() setzen (das ist wiederum nicht erlaubt)
$conf = Config::Manager::Conf->new();
defined $conf->set('SPECIAL', 'SCOPE', 'UNIVERSE') ? nok() : ok();
$conf->error() eq 'Configuration constant $[SPECIAL]{SCOPE} is read-only' ? ok() : nok();
################################################################################
# Werte setzen und auswerten #
################################################################################
$conf = Config::Manager::Conf->new();
# Wert setzen und wieder auslesen
$conf->set('SPU', 'TMP1', 'C:\tmp') ? ok(): nok();
$conf->get('SPU', 'TMP1') eq 'C:\tmp' ? ok(): nok();
$conf->set('SPU', 'TMP2', 'D:\tmp') ? ok() : nok();
t/01_____config.t view on Meta::CPAN
$conf->get('KM', 'TMP3') eq 'X:\temp' ? ok() : nok();
# Die Werte in SPU muessen nach wie vor stimmen
$conf->get('SPU', 'TMP1') eq 'C:\tmp' ? ok() : nok();
$conf->get('SPU', 'TMP2') eq 'D:\tmp' ? ok() : nok();
$conf->get('SPU', 'TMP1') eq 'C:\tmp' ? ok() : nok();
$conf->get('SPU', 'TMP2') eq 'D:\tmp' ? ok() : nok();
$conf->get('KM', 'TMP1') eq 'C:\temp' ? ok() : nok();
$conf->get('KM', 'TMP2') eq 'D:\temp' ? ok() : nok();
# Zugriff auf undefinierten Wert
$conf->get('SPU', 'TRALALA') ? nok() : ok();
$conf->error() eq "Configuration constant \$[SPU]{TRALALA} not found" ? ok() : nok();
$conf->get('SPX', 'TMP1') ? nok() : ok();
$conf->error() eq "Configuration constant \$[SPX]{TMP1} not found" ? ok() : nok();
$conf->get('SPX', 'TRALALA') ? nok() : ok();
$conf->error() eq "Configuration constant \$[SPX]{TRALALA} not found" ? ok() : nok();
$conf->get('TRALALA') ? nok() : ok();
$conf->error() eq "Configuration constant \$[DEFAULT]{TRALALA} not found" ? ok() : nok();
################################################################################
# Konstruktor auf Instanz anwenden statt auf Klasse #
################################################################################
$conf = $conf->new();
$conf->get('SPU', 'TMP1') ? nok() : ok();
$conf->error() eq "Configuration constant \$[SPU]{TMP1} not found" ? ok() : nok();
################################################################################
# Einlesen und Auswerten einer korrekten Datei sowie Kommandozeilenoptionen #
################################################################################
# Ich mache alle Tests sowohl auf einem frischen Objekt ($conf) als auch auf
# der Klasse, d.h. auf der Default-Instanz.
############################################################
# Daten einlesen, Kommandozeilenoptionen setzen
t/01_____config.t view on Meta::CPAN
conf()->get('PATH') eq 'C:/sys/wrk;C:/sys/inst' ? ok() : nok();
Config::Manager::Conf->get('PATH') eq 'C:/sys/wrk;C:/sys/inst' ? ok() : nok();
############################################################
# Zyklen erkennen und abbrechen
############################################################
# Die duemmste Art, einen Zyklus zu produzieren
$conf = conf();
defined $conf->get('SIMPLE_LOOP') ? nok() : ok();
$conf->error() eq "Infinite recursion in file 't/conf_public.ini' line #84 [DEFAULT]: \$[DEFAULT]{SIMPLE_LOOP} = \"This is a \$SIMPLE_LOOP\"" ? ok() : nok();
defined Config::Manager::Conf->get('SIMPLE_LOOP') ? nok() : ok();
Config::Manager::Conf->error() eq "Infinite recursion in file 't/conf_public.ini' line #84 [DEFAULT]: \$[DEFAULT]{SIMPLE_LOOP} = \"This is a \$SIMPLE_LOOP\"" ? ok() : nok();
# Etwas weniger auffaellig
$conf = conf();
defined $conf->get('LOOP') ? nok() : ok();
$conf->error() eq "Infinite recursion in file 't/conf_public.ini' line #87 [DEFAULT]: \$[DEFAULT]{LOOP} = \"\$THIS will loop\"" ? ok() : nok();
defined Config::Manager::Conf->get('LOOP') ? nok() : ok();
Config::Manager::Conf->error() eq "Infinite recursion in file 't/conf_public.ini' line #87 [DEFAULT]: \$[DEFAULT]{LOOP} = \"\$THIS will loop\"" ? ok() : nok();
# Unauffaellig
$conf = conf();
defined $conf->get('THAT') ? nok() : ok();
$conf->error() eq "Infinite recursion in file 't/conf_public.ini' line #85 [DEFAULT]: \$[DEFAULT]{THIS} = \"This \$WILL loop\"" ? ok() : nok();
defined Config::Manager::Conf->get('THAT') ? nok() : ok();
Config::Manager::Conf->error() eq "Infinite recursion in file 't/conf_public.ini' line #85 [DEFAULT]: \$[DEFAULT]{THIS} = \"This \$WILL loop\"" ? ok() : nok();
############################################################
# Qualifizierter Zugriff
############################################################
# Wert ist in der Default-Section und zwei weiteren Sections definiert
conf()->get('EVERYWHERE') eq 'default' ? ok() : nok();
Config::Manager::Conf->get('EVERYWHERE') eq 'default' ? ok() : nok();
conf()->get('A', 'EVERYWHERE') eq 'at a' ? ok() : nok();
Config::Manager::Conf->get('A', 'EVERYWHERE') eq 'at a' ? ok() : nok();
conf()->get('B', 'EVERYWHERE') eq 'at b' ? ok() : nok();
Config::Manager::Conf->get('B', 'EVERYWHERE') eq 'at b' ? ok() : nok();
# Wert ist in zwei Sections, aber nicht in der Default-Section definiert
$conf = conf();
defined $conf->get('HELLO') ? nok() : ok();
$conf->error() eq "Configuration constant \$[DEFAULT]{HELLO} not found" ? ok() : nok();
defined Config::Manager::Conf->get('HELLO') ? nok() : ok();
Config::Manager::Conf->error() eq "Configuration constant \$[DEFAULT]{HELLO} not found" ? ok() : nok();
conf()->get('A', 'HELLO') eq 'a_hello' ? ok() : nok();
Config::Manager::Conf->get('A', 'HELLO') eq 'a_hello' ? ok() : nok();
conf()->get('B', 'HELLO') eq 'b_hello' ? ok() : nok();
Config::Manager::Conf->get('B', 'HELLO') eq 'b_hello' ? ok() : nok();
# Wert ist in der Default-Section und einer weiteren Section definiert
conf()->get('A') eq 'a' ? ok() : nok();
Config::Manager::Conf->get('A') eq 'a' ? ok() : nok();
conf()->get('A', 'A') eq 'a, too' ? ok() : nok();
Config::Manager::Conf->get('A', 'A') eq 'a, too' ? ok() : nok();
$conf = conf();
defined $conf->get('B', 'A') ? nok() : ok();
$conf->error() eq "Configuration constant \$[B]{A} not found" ? ok() : nok();
defined Config::Manager::Conf->get('B', 'A') ? nok() : ok();
Config::Manager::Conf->error() eq "Configuration constant \$[B]{A} not found" ? ok() : nok();
# Wert ist nicht in der Default-Section, aber in einer weiteren Section definiert
defined conf()->get('EXCLUSIVE') ? nok() : ok();
defined Config::Manager::Conf->get('EXCLUSIVE') ? nok() : ok();
conf()->get('A', 'EXCLUSIVE') eq 'XA' ? ok() : nok();
Config::Manager::Conf->get('A', 'EXCLUSIVE') eq 'XA' ? ok() : nok();
$conf = conf();
defined $conf->get('B', 'EXCLUSIVE') ? nok() : ok();
$conf->error() eq "Configuration constant \$[B]{EXCLUSIVE} not found" ? ok() : nok();
defined Config::Manager::Conf->get('B', 'EXCLUSIVE') ? nok() : ok();
Config::Manager::Conf->error() eq "Configuration constant \$[B]{EXCLUSIVE} not found" ? ok() : nok();
# Wert ist nirgendwo definiert
$conf = conf();
defined $conf->get('HURZ') ? nok() : ok();
$conf->error() eq "Configuration constant \$[DEFAULT]{HURZ} not found" ? ok() : nok();
defined Config::Manager::Conf->get('HURZ') ? nok() : ok();
Config::Manager::Conf->error() eq "Configuration constant \$[DEFAULT]{HURZ} not found" ? ok() : nok();
$conf = conf();
defined $conf->get('A', 'HURZ') ? nok() : ok();
$conf->error() eq "Configuration constant \$[A]{HURZ} not found" ? ok() : nok();
defined Config::Manager::Conf->get('A', 'HURZ') ? nok() : ok();
Config::Manager::Conf->error() eq "Configuration constant \$[A]{HURZ} not found" ? ok() : nok();
############################################################
# Qualifizierte Substitutionen
############################################################
# Wert ist in der Default-Section und zwei weiteren Sections definiert
conf()->get('ANYTHING', 'EVERYWHERE1') eq '%default%' ? ok() : nok();
Config::Manager::Conf->get('ANYTHING', 'EVERYWHERE1') eq '%default%' ? ok() : nok();
conf()->get('ANYTHING', 'EVERYWHERE2') eq '%default%' ? ok() : nok();
Config::Manager::Conf->get('ANYTHING', 'EVERYWHERE2') eq '%default%' ? ok() : nok();
t/01_____config.t view on Meta::CPAN
conf()->get('ANYTHING', 'EVERYWHERE4') eq '%at a%' ? ok() : nok();
Config::Manager::Conf->get('ANYTHING', 'EVERYWHERE4') eq '%at a%' ? ok() : nok();
conf()->get('ANYTHING', 'EVERYWHERE5') eq '%at b%' ? ok() : nok();
Config::Manager::Conf->get('ANYTHING', 'EVERYWHERE5') eq '%at b%' ? ok() : nok();
conf()->get('ANYTHING', 'EVERYWHERE6') eq '%at b%' ? ok() : nok();
Config::Manager::Conf->get('ANYTHING', 'EVERYWHERE6') eq '%at b%' ? ok() : nok();
# Wert ist in zwei Sections, aber nicht in der Default-Section definiert
$conf = conf();
defined $conf->get('ANYTHING', 'HELLO1') ? nok() : ok();
$conf->error() eq "Configuration constant \$[DEFAULT]{HELLO} not found" ? ok() : nok();
defined Config::Manager::Conf->get('ANYTHING', 'HELLO1') ? nok() : ok();
Config::Manager::Conf->error() eq "Configuration constant \$[DEFAULT]{HELLO} not found" ? ok() : nok();
$conf = conf();
defined $conf->get('ANYTHING', 'HELLO2') ? nok() : ok();
$conf->error() eq "Configuration constant \$[DEFAULT]{HELLO} not found" ? ok() : nok();
defined Config::Manager::Conf->get('ANYTHING', 'HELLO2') ? nok() : ok();
Config::Manager::Conf->error() eq "Configuration constant \$[DEFAULT]{HELLO} not found" ? ok() : nok();
conf()->get('ANYTHING', 'HELLO3') eq '%a_hello%' ? ok() : nok();
Config::Manager::Conf->get('ANYTHING', 'HELLO3') eq '%a_hello%' ? ok() : nok();
conf()->get('ANYTHING', 'HELLO4') eq '%a_hello%' ? ok() : nok();
Config::Manager::Conf->get('ANYTHING', 'HELLO4') eq '%a_hello%' ? ok() : nok();
conf()->get('ANYTHING', 'HELLO5') eq '%b_hello%' ? ok() : nok();
Config::Manager::Conf->get('ANYTHING', 'HELLO5') eq '%b_hello%' ? ok() : nok();
conf()->get('ANYTHING', 'HELLO6') eq '%b_hello%' ? ok() : nok();
Config::Manager::Conf->get('ANYTHING', 'HELLO6') eq '%b_hello%' ? ok() : nok();
# Wert ist in der Default-Section und einer weiteren Section definiert
conf()->get('ANYTHING', 'A1') eq '%a%' ? ok() : nok();
Config::Manager::Conf->get('ANYTHING', 'A1') eq '%a%' ? ok() : nok();
conf()->get('ANYTHING', 'A2') eq '%a%' ? ok() : nok();
Config::Manager::Conf->get('ANYTHING', 'A2') eq '%a%' ? ok() : nok();
conf()->get('ANYTHING', 'A3') eq '%a, too%' ? ok() : nok();
Config::Manager::Conf->get('ANYTHING', 'A3') eq '%a, too%' ? ok() : nok();
conf()->get('ANYTHING', 'A4') eq '%a, too%' ? ok() : nok();
Config::Manager::Conf->get('ANYTHING', 'A4') eq '%a, too%' ? ok() : nok();
$conf = conf();
defined $conf->get('ANYTHING', 'A5') ? nok() : ok();
$conf->error() eq "Configuration constant \$[B]{A} not found" ? ok() : nok();
defined Config::Manager::Conf->get('ANYTHING', 'A5') ? nok() : ok();
Config::Manager::Conf->error() eq "Configuration constant \$[B]{A} not found" ? ok() : nok();
$conf = conf();
defined $conf->get('ANYTHING', 'A6') ? nok() : ok();
$conf->error() eq "Configuration constant \$[B]{A} not found" ? ok() : nok();
defined Config::Manager::Conf->get('ANYTHING', 'A6') ? nok() : ok();
Config::Manager::Conf->error() eq "Configuration constant \$[B]{A} not found" ? ok() : nok();
# Wert ist nicht in der Default-Section, aber in einer weiteren Section definiert
$conf = conf();
defined $conf->get('ANYTHING', 'EXCLUSIVE1') ? nok() : ok();
$conf->error() eq "Configuration constant \$[DEFAULT]{EXCLUSIVE} not found" ? ok() : nok();
defined Config::Manager::Conf->get('ANYTHING', 'EXCLUSIVE1') ? nok() : ok();
Config::Manager::Conf->error() eq "Configuration constant \$[DEFAULT]{EXCLUSIVE} not found" ? ok() : nok();
$conf = conf();
defined $conf->get('ANYTHING', 'EXCLUSIVE2') ? nok() : ok();
$conf->error() eq "Configuration constant \$[DEFAULT]{EXCLUSIVE} not found" ? ok() : nok();
defined Config::Manager::Conf->get('ANYTHING', 'EXCLUSIVE2') ? nok() : ok();
Config::Manager::Conf->error() eq "Configuration constant \$[DEFAULT]{EXCLUSIVE} not found" ? ok() : nok();
conf()->get('ANYTHING', 'EXCLUSIVE3') eq '%XA%' ? ok() : nok();
Config::Manager::Conf->get('ANYTHING', 'EXCLUSIVE3') eq '%XA%' ? ok() : nok();
conf()->get('ANYTHING', 'EXCLUSIVE4') eq '%XA%' ? ok() : nok();
Config::Manager::Conf->get('ANYTHING', 'EXCLUSIVE4') eq '%XA%' ? ok() : nok();
$conf = conf();
defined $conf->get('ANYTHING', 'EXCLUSIVE5') ? nok() : ok();
$conf->error() eq "Configuration constant \$[B]{EXCLUSIVE} not found" ? ok() : nok();
defined Config::Manager::Conf->get('ANYTHING', 'EXCLUSIVE5') ? nok() : ok();
Config::Manager::Conf->error() eq "Configuration constant \$[B]{EXCLUSIVE} not found" ? ok() : nok();
$conf = conf();
defined $conf->get('ANYTHING', 'EXCLUSIVE6') ? nok() : ok();
$conf->error() eq "Configuration constant \$[B]{EXCLUSIVE} not found" ? ok() : nok();
defined Config::Manager::Conf->get('ANYTHING', 'EXCLUSIVE6') ? nok() : ok();
Config::Manager::Conf->error() eq "Configuration constant \$[B]{EXCLUSIVE} not found" ? ok() : nok();
# Wert ist nirgendwo definiert
$conf = conf();
defined $conf->get('ANYTHING', 'HURZ1') ? nok() : ok();
$conf->error() eq "Configuration constant \$[DEFAULT]{HURZ} not found" ? ok() : nok();
defined Config::Manager::Conf->get('ANYTHING', 'HURZ1') ? nok() : ok();
Config::Manager::Conf->error() eq "Configuration constant \$[DEFAULT]{HURZ} not found" ? ok() : nok();
$conf = conf();
defined $conf->get('ANYTHING', 'HURZ2') ? nok() : ok();
$conf->error() eq "Configuration constant \$[DEFAULT]{HURZ} not found" ? ok() : nok();
defined Config::Manager::Conf->get('ANYTHING', 'HURZ2') ? nok() : ok();
Config::Manager::Conf->error() eq "Configuration constant \$[DEFAULT]{HURZ} not found" ? ok() : nok();
$conf = conf();
defined $conf->get('ANYTHING', 'HURZ3') ? nok() : ok();
$conf->error() eq "Configuration constant \$[A]{HURZ} not found" ? ok() : nok();
defined Config::Manager::Conf->get('ANYTHING', 'HURZ3') ? nok() : ok();
Config::Manager::Conf->error() eq "Configuration constant \$[A]{HURZ} not found" ? ok() : nok();
$conf = conf();
defined $conf->get('ANYTHING', 'HURZ4') ? nok() : ok();
$conf->error() eq "Configuration constant \$[A]{HURZ} not found" ? ok() : nok();
defined Config::Manager::Conf->get('ANYTHING', 'HURZ4') ? nok() : ok();
Config::Manager::Conf->error() eq "Configuration constant \$[A]{HURZ} not found" ? ok() : nok();
############################################################
# Funktioniert der Zugriff ueber die Default-Instanz?
############################################################
# default() als Klassenmethode aufgefasst
Config::Manager::Conf->default()->get('SYSDIR') eq 'sys' ? ok() : nok();
# default() als Funktion aufgefasst
Config::Manager::Conf::default()->get('SYSDIR') eq 'sys' ? ok() : nok();
# default() als Instanzmethode aufgefasst
t/01_____config.t view on Meta::CPAN
# Zugriff auf Umgebungsvariablen #
################################################################################
$ENV{DONALD} = 'Duck';
# Zugriff auf Umgebungsvariable
conf()->get('ENV', 'DONALD') eq 'Duck' ? ok() : nok();
Config::Manager::Conf->get('ENV', 'DONALD') eq 'Duck' ? ok() : nok();
# Qualifizierter Name erforderlich
$conf = conf();
defined $conf->get('DONALD') ? nok() : ok();
$conf->error() eq "Configuration constant \$[DEFAULT]{DONALD} not found" ? ok() : nok();
defined Config::Manager::Conf->get('DONALD') ? nok() : ok();
Config::Manager::Conf->error() eq "Configuration constant \$[DEFAULT]{DONALD} not found" ? ok() : nok();
# Umgebungsvariable nicht gefunden
$conf = conf();
defined $conf->get('ENV', 'DAGOBERT') ? nok() : ok();
$conf->error() eq "Configuration constant \$[ENV]{DAGOBERT} not found" ? ok() : nok();
defined Config::Manager::Conf->get('ENV', 'DAGOBERT') ? nok() : ok();
Config::Manager::Conf->error() eq "Configuration constant \$[ENV]{DAGOBERT} not found" ? ok() : nok();
# Substitution unter Verwendung einer Umgebungsvariablen
$conf = conf();
$conf->set('SUBST_ENV1', 'Dagobert $[ENV]DONALD') ? ok() : nok();
$conf->get('SUBST_ENV1') eq 'Dagobert Duck' ? ok() : nok();
Config::Manager::Conf->set('SUBST_ENV1', 'Dagobert $[ENV]DONALD') ? ok() : nok();
Config::Manager::Conf->get('SUBST_ENV1') eq 'Dagobert Duck' ? ok() : nok();
# Nochmal Substitution, aber {}-Syntax verwenden
$conf = conf();
$conf->set('SUBST_ENV2', 'Dagobert $[ENV]{DONALD}') ? ok() : nok();
$conf->get('SUBST_ENV2') eq 'Dagobert Duck' ? ok() : nok();
Config::Manager::Conf->set('SUBST_ENV2', 'Dagobert $[ENV]{DONALD}') ? ok() : nok();
Config::Manager::Conf->get('SUBST_ENV2') eq 'Dagobert Duck' ? ok() : nok();
# Substitution unter Verwendung einer fehlenden Umgebungsvariablen
$conf = conf();
$conf->set('SUBST_NOENV', 'Donald $[ENV]DAGOBERT') ? ok() : nok();
defined $conf->get('SUBST_NOENV') ? nok() : ok();
$conf->error() eq "Configuration constant \$[ENV]{DAGOBERT} not found" ? ok() : nok();
Config::Manager::Conf->set('SUBST_NOENV', 'Donald $[ENV]DAGOBERT') ? ok() : nok();
defined Config::Manager::Conf->get('SUBST_NOENV') ? nok() : ok();
Config::Manager::Conf->error() eq "Configuration constant \$[ENV]{DAGOBERT} not found" ? ok() : nok();
################################################################################
# Zugriff auf SPECIAL-Werte #
################################################################################
############################################################
# Jahr, Monat, Tag
############################################################
# Ich kann hier aus naheliegenden Gruenden nicht auf konkrete Werte abfragen,
t/02____example.t view on Meta::CPAN
if (defined ($conf = &user_conf($user)))
{print "ok $n\n";} else {print "not ok $n\n";$conf=Config::Manager::Conf->new();}
$n++;
if (defined ($list = $conf->get_all()))
{print "ok $n\n";} else {print "not ok $n\n";$list=[];}
$n++;
$orig =
[
[ 1, '$[DEFAULT]{CONFIGPATH}', 't', '^.+/Config/Manager/Conf\\.ini$', 29 ],
[ 1, '$[DEFAULT]{LASTCONF}', 't/soft_defaults.ini', '^t/hard_defaults\\.ini$', 6 ],
[ 1, '$[DEFAULT]{LOGFILEPATH}', '.', '^.+/Config/Manager/Conf\\.ini$', 30 ],
[ 1, '$[DEFAULT]{PROJCONF}', 't/project.ini', '^t/hard_defaults\\.ini$', 5 ],
[ 1, '$[DEFAULT]{USERCONF}', 't/user.ini', '^t/hard_defaults\\.ini$', 4 ],
[ 1, '$[Eureka]{Hat_geklappt}', 'Juppie', '^t/soft_defaults\\.ini$', 3 ],
[ 1, '$[Manager]{NEXTCONF}', 't/hard_defaults.ini', '^.+/Config/Manager/Conf\\.ini$', 33 ],
[ 1, '$[Person]{Name}', 'Steffen Beyer', '^t/user\\.ini$', 3 ],
[ 1, '$[Person]{Telefon}', '0162 77 49 721', '^t/user\\.ini$', 4 ],
[ 1, '$[TEST]{NEXTCONF}', 't/TEST.ini', '^.+/Config/Manager/Conf\\.ini$', 36 ]
];
$index = 0;
for ( $count = 0; $count < @{$list}; $count++ )
{
$item = ${$list}[$count];
next if ($$item[3] =~ /^<.+>$/);
$comp = ${$orig}[$index++];
$ok = 1;
for ( $i = 0; $i < @{$item}; $i++ )
t/conf_err_val05.ini view on Meta::CPAN
################################################################################
# Test fuer Fehlerfall: Verunglueckte qualifizierte Substitution
################################################################################
# Nur oeffnende Klammer
SQ_O = $[A{HELLO}
t/conf_err_val06.ini view on Meta::CPAN
################################################################################
# Test fuer Fehlerfall: Verunglueckte qualifizierte Substitution
################################################################################
# Nur Section
SQ_Q = $[A]
t/conf_err_val07.ini view on Meta::CPAN
################################################################################
# Test fuer Fehlerfall: Verunglueckte qualifizierte Substitution
################################################################################
# Nur oeffnende Klammer und Section
SQ_OS = $[A]{
t/conf_err_val08.ini view on Meta::CPAN
################################################################################
# Test fuer Fehlerfall: Verunglueckte qualifizierte Substitution
################################################################################
# Nur Section und schliessende Klammer
SQ_SC = $[A]}
t/conf_public.ini view on Meta::CPAN
# Folgende Zeilen sind absichtlich leer, damit die Zeilennummerierung in meinen
# Testscripts nicht durcheinander geraet
# Substitution: Nur schliessende Klammer
S_C = $SYS}
# Qualifizierte Substitution: Nur schliessende Klammer
SQ_C = $[A]{HELLO}}
# Sonderlocke fuer Steffen Beyer :-)
$SONDERLOCKE = Key faengt mit $$ an
# Fuer jene Faelle, in denen versehentlich eine Section als Key interpretiert wird :-)
A = a
# Gross- und Kleinschreibung fuer Schluessel wird unterschieden
t/conf_public.ini view on Meta::CPAN
[A]
# HELLO gibt's in A und B
HELLO = a_hello
# Gross- und Kleinschreibung fuer Schluessel
hello = oink
EVERYWHERE = at a
# Achtung, weiter unten wird diese Section noch fortgesetzt ...
[B]
# $[B]{HELLO} wird durch conf_private.ini ueberschrieben
HELLO = no-no
EVERYWHERE = at b
[a]
# Gross- und Kleinschreibung fuer Sections
HELLO = oink
[A]
# Hier geht's weiter mit Section A
A = a, too
EXCLUSIVE = XA
[ANYTHING]
EVERYWHERE1 = %$EVERYWHERE%
EVERYWHERE2 = %${EVERYWHERE}%
EVERYWHERE3 = %$[A]{EVERYWHERE}%
EVERYWHERE4 = %$[A]EVERYWHERE%
EVERYWHERE5 = %$[B]EVERYWHERE%
EVERYWHERE6 = %$[B]{EVERYWHERE}%
HELLO1 = %$HELLO%
HELLO2 = %${HELLO}%
HELLO3 = %$[A]HELLO%
HELLO4 = %$[A]{HELLO}%
HELLO5 = %$[B]HELLO%
HELLO6 = %$[B]{HELLO}%
A1 = %$A%
A2 = %${A}%
A3 = %$[A]A%
A4 = %$[A]{A}%
A5 = %$[B]A%
A6 = %$[B]{A}%
EXCLUSIVE1 = %$EXCLUSIVE%
EXCLUSIVE2 = %${EXCLUSIVE}%
EXCLUSIVE3 = %$[A]EXCLUSIVE%
EXCLUSIVE4 = %$[A]{EXCLUSIVE}%
EXCLUSIVE5 = %$[B]EXCLUSIVE%
EXCLUSIVE6 = %$[B]{EXCLUSIVE}%
HURZ1 = %$HURZ%
HURZ2 = %${HURZ}%
HURZ3 = %$[A]HURZ%
HURZ4 = %$[A]{HURZ}%
[WITH-SLASH]
FOR-EXAMPLE = -
T-1 = A${FOR-EXAMPLE}Z
T-2 = A$[WITH-SLASH]{FOR-EXAMPLE}O
T-3 = +$FOR-EXAMPLE
T-4 = 4$[WITH-SLASH]FOR-EXAMPLE
T-5 = 5$FOR-EXAMPLE;
T-6 = 6$[WITH-SLASH]FOR-EXAMPLE;
# Es folgen Tests fuer den Zugriff auf die eigene Section
[A1]
A = a1>$[A2]B
B = b1
C = c1
D = d1
[A2]
A = a2
B = b2>$C
C = c2>$[A3]D
D = d2
[A3]
A = a3
B = b3
C = c3
D = d3>$A
# Es folgen Tests fuer indirekte Substitution
[WHO]
USER = FRITZ
NAME = $[${USER}]{NAME}
name = $[$[WHO]{USER}]{NAME}
IQ = ${$[USER]{IQ}}
ZERO = 0
XYZ = ${$USER}
xyz = ${$[WHO]{USER}}
XXX = $[WHO]{$USER}
xxx = $[WHO]{$[WHO]{USER}}
FRITZ = fritz
UVW = $[${USER}]{$USER}
uvw = $[$[WHO]{USER}]{$[WHO]{USER}}
[FRITZ]
NAME = Fritz Fischer
FRITZ = fritzfritz
[USER]
IQ = ZERO
t/hard_defaults.ini view on Meta::CPAN
[DEFAULT]
#USERCONF = $[DEFAULT]{CONFIGPATH}/$[SPECIAL]{WHOAMI}.ini
USERCONF = $[DEFAULT]{CONFIGPATH}/user.ini
PROJCONF = $[DEFAULT]{CONFIGPATH}/project.ini
LASTCONF = $[DEFAULT]{CONFIGPATH}/soft_defaults.ini
[Manager]
NEXTCONF = $[DEFAULT]{USERCONF}
t/project.ini view on Meta::CPAN
[Manager]
NEXTCONF = $[DEFAULT]{LASTCONF}
[Person]
Name = Steffen Beyer
Telefon = 0162 77 49 721
[Manager]
NEXTCONF = $[DEFAULT]{PROJCONF}