1
2
3
4
5
6
7
8
9
10
11
12
use Moose;
use Kernel::Config;
# ------------------------------------------------------------------------
my %Config = Kernel::Config -> Config_Loader( );
print "Value des Config - Objekts : $Config{ 'DB_Handle' }";
# -------------------------------------------------------------------------
1;
$Config{ 'Werte des Hashs aus der Config' }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package Kernel::Config;
use Moose;
extends 'Kernel::Config::Defaults';
# ------------------------------------------------------------------------
sub Config_Loader {
my %Config_Werte = ( Home => 'C:\Scripts\Aktuell' );
my $Defaults_Handler = Kernel::Config::Defaults -> new( ) ;
my $Defaults_Referenz = $Defaults_Handler -> Load_Defaults( ) ;
my %Defaults_Werte = %$Defaults_Referenz;
# print "@{[ %Defaults_Werte ]}";
return( %Defaults_Werte );
}
# --------------------------------------------------------------------------------
no Moose;
# ---------------------------------------------------------------------------------
__PACKAGE__ -> meta -> make_immutable;
my $Defaults_Handler = Kernel::Config::Defaults -> new( ) ;
$Defaults_Referenz = $Defaults_Handler -> Load_Defaults( );
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package Kernel::Config::Defaults;
use Moose;
# --------------------------------------------------------------------------------------------------------------------------------------------------------
sub Load_Defaults {
my %DB_Connection = ( DB_Handle => 'Microsoft SQL Server' );
if ( -e "C:/Scripts/Aktuell/Kernel/Config/Files" )
{
print "Positive Erkennung des Config - Files Ordners ..." , "\n";
}
return { %{ \%DB_Connection } }
};
# --------------------------------------------------------------------------------------------------------------------------------------------------------
no Moose;
# --------------------------------------------------------------------------------------------------------------------------------------------------------
__PACKAGE__ -> meta -> make_immutable;
1;
1
2
3
$Self -> { Database } = 'Bezeichnung der DB';
$Self -> { DatabaseUser } = 'Standard User';
$Self -> { DatabasePw } = 'XXXXXXXX';
my %DB_Connection = ( DB_Handle => 'Microsoft SQL Server' );
-e "C:/Scripts/Aktuell/Kernel/Config/Files/"
-e "$Self->{Home}/Kernel/Config/Files/"
1 2 3
-e "$Self->{Home}/Kernel/Config/Files/" # wird wie erwartet interpoliert -e "$Self->Home()/Kernel/Config/Files/" # Hier wird nur $Self interpoliert. -e ($Self->Home . "/Kernel/Config/Files/") # So geht's dann wieder.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
package Kernel::Config::Defaults; use strict; # ---------------------------------------------------------------------- sub Load_Defaults { my ($Config_Dir) = @_; our $Self = { DB_Handle => 'Microsoft SQL Server'}; if ( -e "$Config_Dir" ) { print "Positive Erkennung des Config - Files Ordners $Config_Dir\n"; # Ich nehme an, hier wird noch mehr Zeug aus den Dateien # in den Hash eingetragen, hier einfach hart codiert: $Self -> { Database } = 'Bezeichnung der DB'; $Self -> { DatabaseUser } = 'Standard User'; $Self -> { DatabasePw } = 'XXXXXXXX'; } else { die "Keine Defaults, keine Attribute. Versuch's nochmal."; } return %$Self; }; # ---------------------------------------------------------------------- 1;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
package Kernel::Config; use Moose; use Kernel::Config::Defaults; # ------------------------------------------------------------------------ my $Home = $ENV{CONFIG_HOME} // 'C:\Scripts\Aktuell'; # ------------------------------------------------------------------------ has Home => ( is => 'rw', default => $Home, ); my %Config = Kernel::Config::Defaults::Load_Defaults($Home); while (my ($attribute,$default) = each %Config) { has $attribute => ( is => 'rw', default => $default, ); } # -------------------------------------------------------------------------------- no Moose; # --------------------------------------------------------------------------------- __PACKAGE__ -> meta -> make_immutable;
has => ([ keys %Config ], is => 'rw');
1 2 3 4 5 6 7 8 9 10 11
use strict; use Kernel::Config; # ---------------------------------------------------------------------- my $Config = Kernel::Config -> new(DatabasePw => 'Geheim!!11!'); # ------------------------------------------------------------------- printf ("Value des Config - Werts Home: %s\n", $Config->Home); printf ("Value des Config - Werts Database: %s\n", $Config->Database); printf ("Value des Config - Werts DatabasePw: %s\n", $Config->DatabasePw); printf ("Value des Config - Werts DB_Handle: %s\n", $Config->DB_Handle);
1
2
3
4
5
Positive Erkennung des Config - Files Ordners /tmp
Value des Config - Werts Home: /tmp
Value des Config - Werts Database: Bezeichnung der DB
Value des Config - Werts DatabasePw: Geheim!!11!
Value des Config - Werts DB_Handle: Microsoft SQL Server