-
Notifications
You must be signed in to change notification settings - Fork 0
/
configurationManager.pm
117 lines (97 loc) · 2.46 KB
/
configurationManager.pm
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package configurationManager;
use strict;
use warnings;
use Getopt::Long qw(GetOptions);
Getopt::Long::Configure qw(pass_through);
$ModuleAutoloader::VERSION = "1.1";
my $debugList = '';
GetOptions (
"ConfigManager-DebugList" => \$debugList,
);
my $currentFileDirectory = " ";
BEGIN
{
foreach my $dir (@INC) {
next if (!defined $dir);
next if (ref($dir));
if (-f $dir."/configurationManager.pm") {
$currentFileDirectory = $dir."/";
last;
}
}
if ($currentFileDirectory eq " ") {
die BaseException->new({
message => "configurationManager can't resolve itself dependancy",
code => "3a8ddc3b1",
previous => undef,
});
}
push(@INC, $currentFileDirectory."/configurationManagerLib/Container");
push(@INC, $currentFileDirectory."/configurationManagerLib/Loader");
push(@INC, $currentFileDirectory."/configurationManagerLib/YAML-1.15/lib");
push(@INC, $currentFileDirectory."/configurationManagerLib/Exception");
push(@INC, $currentFileDirectory."/configurationManagerLib/Explorer");
push(@INC, $currentFileDirectory."/configurationManagerLib");
}
use ConfigurationContainer;
use ConfigurationLoader;
my @configRepositories;
sub new
{
my $class = shift;
my ($args) = @_;
my $self = bless {}, $class;
foreach my $argKey (keys(%{$args})) {
$self->{$argKey} = $args->{$argKey};
}
my @selfRepositories;
push(@selfRepositories, $_) foreach (@configRepositories);
if ($self->{"repositories"}) {
foreach my $repository (@{$self->{"repositories"}}) {
push(@selfRepositories, $repository);
}
}
$self->{container} = ConfigurationContainer->new({
"repositories" => [@selfRepositories],
});
$self->{container}->debug() if $debugList;
$self->{loader} = ConfigurationLoader->new({
"container" => $self->{container},
});
return $self;
}
sub get
{
my $self = shift(@_);
my $key = shift(@_);
$self->{loader}->load($key);
}
sub import
{
my $pkg = shift;
my ($messages) = @_;
if ( defined $messages ) {
if (ref($messages) eq "ARRAY"){
foreach my $message (@{$messages}) {
$pkg->applyMessage($message);
}
} else {
$pkg->applyMessage($messages);
}
}
return;
}
sub applyMessage
{
my $pkg = shift(@_);
my $message = shift(@_);
if ($message =~ /^repo=/) {
my ($repository) = ($message =~ /repo=(.+)/);
push(@configRepositories, $repository);
} elsif ($message =~ /^DebugList=/) {
my ($state) = ($message =~ /DebugList=([01])/);
$debugList = ($state eq "0") ? 0 : 1;
}
}
1;
__END__