[405] | 1 | #!/usr/bin/perl -w
|
---|
| 2 | #
|
---|
| 3 | # ProjectBuilder Conf module
|
---|
| 4 | # Conf files subroutines brought by the the Project-Builder project
|
---|
| 5 | # which can be easily used by wahtever perl project
|
---|
| 6 | #
|
---|
[2032] | 7 | # Copyright B. Cornec 2007-2016
|
---|
[1528] | 8 | # Eric Anderson's changes are (c) Copyright 2012 Hewlett Packard
|
---|
| 9 | # Provided under the GPL v2
|
---|
| 10 | #
|
---|
[405] | 11 | # $Id$
|
---|
| 12 | #
|
---|
| 13 |
|
---|
| 14 | package ProjectBuilder::Conf;
|
---|
| 15 |
|
---|
| 16 | use strict;
|
---|
[1507] | 17 | use Carp 'confess';
|
---|
[405] | 18 | use Data::Dumper;
|
---|
| 19 | use ProjectBuilder::Base;
|
---|
[1148] | 20 | use ProjectBuilder::Version;
|
---|
[2241] | 21 | #use YAML;
|
---|
[405] | 22 |
|
---|
| 23 | # Inherit from the "Exporter" module which handles exporting functions.
|
---|
| 24 |
|
---|
[2241] | 25 | use vars qw($VERSION $REVISION @ISA @EXPORT);
|
---|
[405] | 26 | use Exporter;
|
---|
| 27 |
|
---|
| 28 | # Export, by default, all the functions into the namespace of
|
---|
| 29 | # any code which uses this module.
|
---|
| 30 |
|
---|
| 31 | our @ISA = qw(Exporter);
|
---|
[2154] | 32 | our @EXPORT = qw(pb_conf_init pb_conf_add pb_conf_read pb_conf_read_if pb_conf_write pb_conf_get pb_conf_get_if pb_conf_get_all pb_conf_get_hash pb_conf_cache);
|
---|
[2241] | 33 | ($VERSION,$REVISION) = pb_version_init();
|
---|
[405] | 34 |
|
---|
[898] | 35 | # Global hash of conf files
|
---|
| 36 | # Key is the conf file name
|
---|
| 37 | # Value is its rank
|
---|
| 38 | my %pbconffiles;
|
---|
[409] | 39 |
|
---|
[1495] | 40 | # Global hash of conf file content
|
---|
| 41 | # Key is the config keyword
|
---|
| 42 | # Value is a hash whose key depends on the nature of the config keyword as documented
|
---|
| 43 | # and value is the confguration value
|
---|
[898] | 44 | # We consider that values can not change during the life of pb
|
---|
[1495] | 45 | my $h = ();
|
---|
[898] | 46 |
|
---|
[405] | 47 | =pod
|
---|
| 48 |
|
---|
| 49 | =head1 NAME
|
---|
| 50 |
|
---|
| 51 | ProjectBuilder::Conf, part of the project-builder.org - module dealing with configuration files
|
---|
| 52 |
|
---|
| 53 | =head1 DESCRIPTION
|
---|
| 54 |
|
---|
| 55 | This modules provides functions dealing with configuration files.
|
---|
| 56 |
|
---|
| 57 | =head1 SYNOPSIS
|
---|
| 58 |
|
---|
| 59 | use ProjectBuilder::Conf;
|
---|
| 60 |
|
---|
| 61 | #
|
---|
| 62 | # Read hash codes of values from a configuration file and return table of pointers
|
---|
| 63 | #
|
---|
| 64 | my ($k1, $k2) = pb_conf_read_if("$ENV{'HOME'}/.pbrc","key1","key2");
|
---|
| 65 | my ($k) = pb_conf_read("$ENV{'HOME'}/.pbrc","key");
|
---|
| 66 |
|
---|
| 67 | =head1 USAGE
|
---|
| 68 |
|
---|
[2152] | 69 | The configuration files are loaded in a specific order from most generic to the most specific
|
---|
| 70 | to allow for overwrite to work:
|
---|
| 71 |
|
---|
[2241] | 72 | 1. /usr/share/pb/pb.conf - the read-only system conf file provided by install
|
---|
| 73 | 2. /etc/pb/pb.conf - the same global conf file given to the sysadmin in order to make system wide modifications
|
---|
[2152] | 74 | 3. /path/to/project.pb - Configuration file for the project we're building for
|
---|
| 75 | 4. /(vm|ve|rm)path/to/.pbrc - configuration file for VM, VE or RM specific parameters. Cumulative should be orthogonal
|
---|
| 76 | 5. $HOME/.pbrc - user's configuration file
|
---|
| 77 |
|
---|
[405] | 78 | =over 4
|
---|
| 79 |
|
---|
[505] | 80 | =item B<pb_conf_init>
|
---|
| 81 |
|
---|
[898] | 82 | This function setup the environment PBPROJ for project-builder function usage from other projects.
|
---|
[505] | 83 | The first parameter is the project name.
|
---|
[898] | 84 | It sets up environment variables (PBPROJ)
|
---|
[505] | 85 |
|
---|
| 86 | =cut
|
---|
| 87 |
|
---|
| 88 | sub pb_conf_init {
|
---|
| 89 |
|
---|
[1907] | 90 | my $proj=shift;
|
---|
[505] | 91 |
|
---|
[1495] | 92 | pb_log(1,"Entering pb_conf_init\n");
|
---|
[1584] | 93 | #
|
---|
| 94 | # Check project name
|
---|
| 95 | # Could be with env var PBPROJ
|
---|
| 96 | # or option -p
|
---|
| 97 | # if not defined take the first in conf file
|
---|
| 98 | #
|
---|
| 99 | if ((defined $ENV{'PBPROJ'}) &&
|
---|
| 100 | (not defined $proj)) {
|
---|
| 101 | pb_log(2,"PBPROJ env var setup ($ENV{'PBPROJ'}) so using it\n");
|
---|
| 102 | $proj = $ENV{'PBPROJ'};
|
---|
| 103 | }
|
---|
| 104 |
|
---|
[505] | 105 | if (defined $proj) {
|
---|
| 106 | $ENV{'PBPROJ'} = $proj;
|
---|
| 107 | } else {
|
---|
| 108 | $ENV{'PBPROJ'} = "default";
|
---|
| 109 | }
|
---|
[1495] | 110 | pb_log(1,"PBPROJ = $ENV{'PBPROJ'}\n");
|
---|
[505] | 111 | }
|
---|
| 112 |
|
---|
| 113 |
|
---|
[1495] | 114 | =item B<pb_conf_cache>
|
---|
[505] | 115 |
|
---|
[1495] | 116 | This function caches the configuration file content passed as first parameter into the a hash passed in second parameter
|
---|
| 117 | It returns the modified hash
|
---|
| 118 | Can be used in correlation with the %h hash to store permanently values or not if temporarily.
|
---|
| 119 |
|
---|
| 120 | =cut
|
---|
| 121 |
|
---|
| 122 | sub pb_conf_cache {
|
---|
| 123 |
|
---|
| 124 | my $cf = shift;
|
---|
| 125 | my $lh = shift;
|
---|
| 126 |
|
---|
[2249] | 127 | my $ldfunc;
|
---|
| 128 |
|
---|
[2077] | 129 | # Read the content of the config file and cache it in the %h hash then available for queries
|
---|
[2241] | 130 | if ($confver < 0.15) {
|
---|
[2176] | 131 | open(CONF,$cf) || confess "Unable to open $cf";
|
---|
| 132 | # This is the original conf file format for versions up to 0.14
|
---|
| 133 | while(<CONF>) {
|
---|
| 134 | next if (/^#/);
|
---|
| 135 | if (/^\s*([A-z0-9-_.]+)\s+([[A-z0-9-_.\?\[\]\*\+\\]+)\s*=\s*(.*)$/) {
|
---|
| 136 | pb_log(3,"DEBUG: 1:$1 2:$2 3:$3\n");
|
---|
| 137 | $lh->{$1}->{$2}=$3;
|
---|
| 138 | }
|
---|
[1495] | 139 | }
|
---|
[2176] | 140 | close(CONF);
|
---|
| 141 | } else {
|
---|
[2249] | 142 | eval {
|
---|
| 143 | require YAML;
|
---|
| 144 | YAML->import();
|
---|
| 145 | };
|
---|
| 146 | if ($@) {
|
---|
| 147 | eval {
|
---|
| 148 | # No YAML found using a more std but less complete one. Old perl only
|
---|
| 149 | require Module::Build::YAML;
|
---|
| 150 | Module::Build::YAML->import();
|
---|
| 151 | };
|
---|
| 152 | if ($@) {
|
---|
| 153 | die "Unable to handle YAML configuration files without a YAML.pm module\n";
|
---|
| 154 | } else {
|
---|
| 155 | $ldfunc = \&Module::Build::YAML::LoadFile;
|
---|
| 156 | }
|
---|
| 157 | } else {
|
---|
| 158 | $ldfunc = \&YAML::LoadFile;
|
---|
| 159 | }
|
---|
| 160 |
|
---|
| 161 | $lh = $ldfunc->($cf);
|
---|
[1495] | 162 | }
|
---|
| 163 | return($lh);
|
---|
| 164 | }
|
---|
| 165 |
|
---|
[409] | 166 | =item B<pb_conf_add>
|
---|
| 167 |
|
---|
[1495] | 168 | This function adds the configuration file to the list last, and cache their content in the %h hash
|
---|
[409] | 169 |
|
---|
| 170 | =cut
|
---|
| 171 |
|
---|
| 172 | sub pb_conf_add {
|
---|
| 173 |
|
---|
[415] | 174 | pb_log(2,"DEBUG: pb_conf_add with ".Dumper(@_)."\n");
|
---|
[1495] | 175 | my $lh;
|
---|
[898] | 176 |
|
---|
| 177 | foreach my $cf (@_) {
|
---|
[1495] | 178 | if (! -r $cf) {
|
---|
| 179 | pb_log(0,"WARNING: pb_conf_add can not read $cf\n");
|
---|
| 180 | next;
|
---|
| 181 | }
|
---|
[898] | 182 | # Skip already used conf files
|
---|
[1495] | 183 | return($lh) if (defined $pbconffiles{$cf});
|
---|
| 184 |
|
---|
[2154] | 185 | # The new conf file overload values already managed
|
---|
[898] | 186 | my $num = keys %pbconffiles;
|
---|
[1495] | 187 | pb_log(2,"DEBUG: pb_conf_cache of $cf at position $num\n");
|
---|
[898] | 188 | $pbconffiles{$cf} = $num;
|
---|
[1495] | 189 |
|
---|
| 190 | # Read the content of the config file
|
---|
| 191 | $lh = pb_conf_cache($cf,$lh);
|
---|
| 192 | # and cache it in the %h hash for further queries but after the previous
|
---|
| 193 | # as we load conf files in reverse order (most precise first)
|
---|
| 194 | pb_conf_add_last_in_hash($lh)
|
---|
[409] | 195 | }
|
---|
[898] | 196 | }
|
---|
[409] | 197 |
|
---|
[1495] | 198 |
|
---|
[405] | 199 | =item B<pb_conf_read_if>
|
---|
| 200 |
|
---|
| 201 | This function returns a table of pointers on hashes
|
---|
| 202 | corresponding to the keys in a configuration file passed in parameter.
|
---|
| 203 | If that file doesn't exist, it returns undef.
|
---|
| 204 |
|
---|
| 205 | The format of the configuration file is as follows:
|
---|
| 206 |
|
---|
| 207 | key tag = value1,value2,...
|
---|
| 208 |
|
---|
| 209 | Supposing the file is called "$ENV{'HOME'}/.pbrc", containing the following:
|
---|
| 210 |
|
---|
| 211 | $ cat $HOME/.pbrc
|
---|
| 212 | pbver pb = 3
|
---|
| 213 | pbver default = 1
|
---|
| 214 | pblist pb = 12,25
|
---|
| 215 |
|
---|
| 216 | calling it like this:
|
---|
| 217 |
|
---|
| 218 | my ($k1, $k2) = pb_conf_read_if("$ENV{'HOME'}/.pbrc","pbver","pblist");
|
---|
| 219 |
|
---|
| 220 | will allow to get the mapping:
|
---|
| 221 |
|
---|
| 222 | $k1->{'pb'} contains 3
|
---|
[409] | 223 | $k1->{'default'} contains 1
|
---|
[405] | 224 | $k2->{'pb'} contains 12,25
|
---|
| 225 |
|
---|
| 226 | Valid chars for keys and tags are letters, numbers, '-' and '_'.
|
---|
| 227 |
|
---|
[1495] | 228 | The file read is forgotten after its usage. If you want permanent caching of the data, use pb_conf_add then pb_conf_get
|
---|
| 229 |
|
---|
[405] | 230 | =cut
|
---|
| 231 |
|
---|
| 232 | sub pb_conf_read_if {
|
---|
| 233 |
|
---|
| 234 | my $conffile = shift;
|
---|
| 235 | my @param = @_;
|
---|
| 236 |
|
---|
| 237 | open(CONF,$conffile) || return((undef));
|
---|
| 238 | close(CONF);
|
---|
| 239 | return(pb_conf_read($conffile,@param));
|
---|
| 240 | }
|
---|
| 241 |
|
---|
| 242 | =item B<pb_conf_read>
|
---|
| 243 |
|
---|
| 244 | This function is similar to B<pb_conf_read_if> except that it dies when the file in parameter doesn't exist.
|
---|
| 245 |
|
---|
| 246 | =cut
|
---|
| 247 |
|
---|
| 248 | sub pb_conf_read {
|
---|
| 249 |
|
---|
| 250 | my $conffile = shift;
|
---|
| 251 | my @param = @_;
|
---|
| 252 | my @ptr;
|
---|
[1495] | 253 | my $lh;
|
---|
[405] | 254 |
|
---|
[1495] | 255 | $lh = pb_conf_cache($conffile,$lh);
|
---|
| 256 |
|
---|
| 257 | foreach my $param (@param) {
|
---|
| 258 | push @ptr,$lh->{$param};
|
---|
[405] | 259 | }
|
---|
[1495] | 260 | return(@ptr);
|
---|
| 261 | }
|
---|
[405] | 262 |
|
---|
[1904] | 263 | =item B<pb_conf_write>
|
---|
[1495] | 264 |
|
---|
[1904] | 265 | This function writes in the file passed ias first parameter the hash of values passed as second parameter
|
---|
[1495] | 266 |
|
---|
[1904] | 267 | =cut
|
---|
| 268 |
|
---|
| 269 | sub pb_conf_write {
|
---|
| 270 |
|
---|
| 271 | my $conffile = shift;
|
---|
[1905] | 272 | my $h = shift;
|
---|
[2249] | 273 | my $dpfunc;
|
---|
[1904] | 274 |
|
---|
[1905] | 275 | confess "No configuration file defined to write into !" if (not defined $conffile);
|
---|
| 276 | confess "No hash defined to read from !" if (not defined $h);
|
---|
| 277 | open(CONF,"> $conffile") || confess "Unable to write into $conffile";
|
---|
[1904] | 278 |
|
---|
[2241] | 279 | if ($confver < 0.15) {
|
---|
[2176] | 280 | # This is the original conf file format for versions up to 0.14
|
---|
| 281 | foreach my $p (sort keys %$h) {
|
---|
| 282 | my $j = $h->{$p};
|
---|
| 283 | foreach my $k (sort keys %$j) {
|
---|
| 284 | print CONF "$p $k = $j->{$k}\n";
|
---|
| 285 | }
|
---|
[1904] | 286 | }
|
---|
[2176] | 287 | } else {
|
---|
| 288 | # This is the new YAML format
|
---|
[2249] | 289 | eval {
|
---|
| 290 | require YAML;
|
---|
| 291 | YAML->import();
|
---|
| 292 | };
|
---|
| 293 | if ($@) {
|
---|
| 294 | eval {
|
---|
| 295 | # No YAML found using a more std but less complete one. Old perl only
|
---|
| 296 | require Module::Build::YAML;
|
---|
| 297 | Module::Build::YAML->import();
|
---|
| 298 | };
|
---|
| 299 | if ($@) {
|
---|
| 300 | die "Unable to handle YAML configuration files without a YAML.pm module\n";
|
---|
| 301 | } else {
|
---|
| 302 | $dpfunc = \&Module::Build::YAML::Dump;
|
---|
| 303 | }
|
---|
| 304 | } else {
|
---|
| 305 | $dpfunc = \&YAML::Dump;
|
---|
| 306 | }
|
---|
| 307 |
|
---|
| 308 | print CONF $dpfunc->($h);
|
---|
[1904] | 309 | }
|
---|
| 310 | close(CONF);
|
---|
| 311 | }
|
---|
| 312 |
|
---|
| 313 |
|
---|
| 314 |
|
---|
[1495] | 315 | =item B<pb_conf_get_in_hash_if>
|
---|
| 316 |
|
---|
[1594] | 317 | This function returns a table, corresponding to a set of values queried in the hash passed in parameter or undef if it doesn't exist.
|
---|
| 318 | It takes a table of keys as an input parameter.
|
---|
[1495] | 319 |
|
---|
| 320 | =cut
|
---|
| 321 |
|
---|
| 322 | sub pb_conf_get_in_hash_if {
|
---|
| 323 |
|
---|
| 324 | my $lh = shift || return(());
|
---|
| 325 | my @params = @_;
|
---|
| 326 | my @ptr = ();
|
---|
| 327 |
|
---|
| 328 | pb_log(2,"DEBUG: pb_conf_get_in_hash_if on params ".join(' ',@params)."\n");
|
---|
| 329 | foreach my $k (@params) {
|
---|
| 330 | push @ptr,$lh->{$k};
|
---|
[405] | 331 | }
|
---|
[1495] | 332 |
|
---|
| 333 | pb_log(2,"DEBUG: pb_conf_get_in_hash_if returns\n".Dumper(@ptr));
|
---|
[405] | 334 | return(@ptr);
|
---|
| 335 | }
|
---|
| 336 |
|
---|
[1495] | 337 |
|
---|
| 338 |
|
---|
[409] | 339 | =item B<pb_conf_get_if>
|
---|
[405] | 340 |
|
---|
[1495] | 341 | This function returns a table, corresponding to a set of values queried in the %h hash or undef if it doen't exist. It takes a table of keys as an input parameter.
|
---|
[405] | 342 |
|
---|
[409] | 343 | The format of the configurations file is as follows:
|
---|
| 344 |
|
---|
| 345 | key tag = value1,value2,...
|
---|
| 346 |
|
---|
[1495] | 347 | It will gather the values from all the configurations files passed to pb_conf_add, and return the values for the keys
|
---|
[409] | 348 |
|
---|
| 349 | $ cat $HOME/.pbrc
|
---|
| 350 | pbver pb = 1
|
---|
| 351 | pblist pb = 4
|
---|
| 352 | $ cat $HOME/.pbrc2
|
---|
| 353 | pbver pb = 3
|
---|
| 354 | pblist default = 5
|
---|
| 355 |
|
---|
| 356 | calling it like this:
|
---|
| 357 |
|
---|
[505] | 358 | pb_conf_add("$HOME/.pbrc","$HOME/.pbrc2");
|
---|
[409] | 359 | my ($k1, $k2) = pb_conf_get_if("pbver","pblist");
|
---|
| 360 |
|
---|
| 361 | will allow to get the mapping:
|
---|
| 362 |
|
---|
| 363 | $k1->{'pb'} contains 3
|
---|
| 364 | $k2->{'pb'} contains 4
|
---|
| 365 |
|
---|
| 366 | Valid chars for keys and tags are letters, numbers, '-' and '_'.
|
---|
| 367 |
|
---|
| 368 | =cut
|
---|
| 369 |
|
---|
| 370 | sub pb_conf_get_if {
|
---|
| 371 |
|
---|
[2154] | 372 | my @param = @_;
|
---|
| 373 | my @return = pb_conf_get_in_hash_if($h,@_);
|
---|
| 374 | my $proj = undef;
|
---|
| 375 |
|
---|
| 376 | if (not defined $ENV{'PBPROJ'}) {
|
---|
| 377 | $proj = "unknown";
|
---|
| 378 | } else {
|
---|
| 379 | $proj = $ENV{'PBPROJ'};
|
---|
[405] | 380 | }
|
---|
[409] | 381 |
|
---|
[2154] | 382 | foreach my $i (0..$#param) {
|
---|
| 383 | if (not defined $return[$i]->{$proj}) {
|
---|
| 384 | $return[$i]->{$proj} = $return[$i]->{'default'} if (defined $return[$i]->{'default'});
|
---|
| 385 | }
|
---|
| 386 | }
|
---|
| 387 | return(@return);
|
---|
| 388 | }
|
---|
| 389 |
|
---|
[1495] | 390 | =item B<pb_conf_add_last_in_hash>
|
---|
[405] | 391 |
|
---|
[1495] | 392 | This function merges the values passed in the hash parameter into the %h hash, but only if itdoesn't already contain a value, or if the value is more precise (real value instead of default)
|
---|
[405] | 393 |
|
---|
[1495] | 394 | It is used internally by pb_conf_add and is not exported.
|
---|
[409] | 395 |
|
---|
| 396 | =cut
|
---|
| 397 |
|
---|
[1495] | 398 | sub pb_conf_add_last_in_hash {
|
---|
[409] | 399 |
|
---|
[1907] | 400 | my $ptr = shift;
|
---|
[409] | 401 |
|
---|
[1495] | 402 | return if (not defined $ptr);
|
---|
| 403 | # TODO: test $ptr is a hash pointer
|
---|
[405] | 404 |
|
---|
[1509] | 405 | # When called without correct initialization, try to work anyway with default as project
|
---|
| 406 | pb_conf_init("default") if (not defined $ENV{'PBPROJ'});
|
---|
| 407 |
|
---|
[1495] | 408 | my @params = (sort keys %$ptr);
|
---|
[405] | 409 |
|
---|
[1495] | 410 | # Everything is returned via @h
|
---|
| 411 | # @h contains the values overloading what @ptr may contain.
|
---|
[2154] | 412 | my @h = pb_conf_get_in_hash_if($h,@params);
|
---|
[1495] | 413 | my @ptr = pb_conf_get_in_hash_if($ptr,@params);
|
---|
[409] | 414 |
|
---|
[405] | 415 | my $p1;
|
---|
| 416 | my $p2;
|
---|
| 417 |
|
---|
[1495] | 418 | pb_log(2,"DEBUG: pb_conf_add_last_in_hash params: ".Dumper(@params)."\n");
|
---|
[2154] | 419 | pb_log(2,"DEBUG: pb_conf_add_last_in_hash current hash: ".Dumper(@h)."\n");
|
---|
| 420 | pb_log(2,"DEBUG: pb_conf_add_last_in_hash new inputs: ".Dumper(@ptr)."\n");
|
---|
[405] | 421 |
|
---|
[1495] | 422 | foreach my $i (0..$#params) {
|
---|
| 423 | $p1 = $h[$i];
|
---|
| 424 | $p2 = $ptr[$i];
|
---|
[2154] | 425 | # Always try to take the param from h in priority
|
---|
[1495] | 426 | # in order to mask what could be defined already in ptr
|
---|
[405] | 427 | if (not defined $p2) {
|
---|
[415] | 428 | # exit if no p1 either
|
---|
[1509] | 429 | next if (not defined $p1);
|
---|
[405] | 430 | } else {
|
---|
[409] | 431 | # Ref found in p2
|
---|
[405] | 432 | if (not defined $p1) {
|
---|
[409] | 433 | # No ref in p1 so use p2's value
|
---|
[405] | 434 | $p1 = $p2;
|
---|
| 435 | } else {
|
---|
| 436 | # Both are defined - handling the overloading
|
---|
[2154] | 437 | # Now copy back into p1 all p2 content
|
---|
| 438 | # as p1 content always has priority over p2
|
---|
[405] | 439 | if (not defined $p1->{$ENV{'PBPROJ'}}) {
|
---|
| 440 | if (defined $p2->{$ENV{'PBPROJ'}}) {
|
---|
[1594] | 441 | $p1->{$ENV{'PBPROJ'}} = $p2->{$ENV{'PBPROJ'}};
|
---|
[405] | 442 | }
|
---|
| 443 | }
|
---|
| 444 | # Now copy back into p1 all p2 content which doesn't exist in p1
|
---|
[2154] | 445 | # # p1 content always has priority over p2
|
---|
[405] | 446 | foreach my $k (keys %$p2) {
|
---|
| 447 | $p1->{$k} = $p2->{$k} if (not defined $p1->{$k});
|
---|
| 448 | }
|
---|
| 449 | }
|
---|
| 450 | }
|
---|
[1495] | 451 | $h->{$params[$i]} = $p1;
|
---|
[405] | 452 | }
|
---|
[1495] | 453 | pb_log(2,"DEBUG: pb_conf_add_last_in_hash output: ".Dumper($h)."\n");
|
---|
[405] | 454 | }
|
---|
| 455 |
|
---|
[409] | 456 | =item B<pb_conf_get>
|
---|
[405] | 457 |
|
---|
[409] | 458 | This function is the same B<pb_conf_get_if>, except that it tests each returned value as they need to exist in that case.
|
---|
| 459 |
|
---|
| 460 | =cut
|
---|
| 461 |
|
---|
| 462 | sub pb_conf_get {
|
---|
| 463 |
|
---|
| 464 | my @param = @_;
|
---|
| 465 | my @return = pb_conf_get_if(@param);
|
---|
[932] | 466 | my $proj = undef;
|
---|
[409] | 467 |
|
---|
[932] | 468 | if (not defined $ENV{'PBPROJ'}) {
|
---|
| 469 | $proj = "unknown";
|
---|
| 470 | } else {
|
---|
| 471 | $proj = $ENV{'PBPROJ'};
|
---|
| 472 | }
|
---|
[409] | 473 |
|
---|
[1538] | 474 | confess "No params found for $proj" if (not @return);
|
---|
[932] | 475 |
|
---|
[409] | 476 | foreach my $i (0..$#param) {
|
---|
[1507] | 477 | confess "No $param[$i] defined for $proj" if (not defined $return[$i]);
|
---|
[409] | 478 | }
|
---|
| 479 | return(@return);
|
---|
| 480 | }
|
---|
| 481 |
|
---|
[1495] | 482 |
|
---|
[1694] | 483 | =item B<pb_conf_get_all>
|
---|
| 484 |
|
---|
[2077] | 485 | This function returns an array with all configuration parameters
|
---|
[1694] | 486 |
|
---|
| 487 | =cut
|
---|
| 488 |
|
---|
| 489 | sub pb_conf_get_all {
|
---|
| 490 |
|
---|
| 491 | return(sort keys %$h);
|
---|
| 492 | }
|
---|
| 493 |
|
---|
[2077] | 494 |
|
---|
| 495 | =item B<pb_conf_get_hash>
|
---|
| 496 |
|
---|
| 497 | This function returns a pointer to the hash with all configuration parameters
|
---|
| 498 |
|
---|
| 499 | =cut
|
---|
| 500 |
|
---|
| 501 | sub pb_conf_get_hash {
|
---|
| 502 |
|
---|
| 503 | return($h);
|
---|
| 504 | }
|
---|
| 505 |
|
---|
[405] | 506 | =back
|
---|
| 507 |
|
---|
| 508 | =head1 WEB SITES
|
---|
| 509 |
|
---|
| 510 | The main Web site of the project is available at L<http://www.project-builder.org/>. Bug reports should be filled using the trac instance of the project at L<http://trac.project-builder.org/>.
|
---|
| 511 |
|
---|
| 512 | =head1 USER MAILING LIST
|
---|
| 513 |
|
---|
| 514 | None exists for the moment.
|
---|
| 515 |
|
---|
| 516 | =head1 AUTHORS
|
---|
| 517 |
|
---|
| 518 | The Project-Builder.org team L<http://trac.project-builder.org/> lead by Bruno Cornec L<mailto:bruno@project-builder.org>.
|
---|
| 519 |
|
---|
| 520 | =head1 COPYRIGHT
|
---|
| 521 |
|
---|
| 522 | Project-Builder.org is distributed under the GPL v2.0 license
|
---|
| 523 | described in the file C<COPYING> included with the distribution.
|
---|
| 524 |
|
---|
| 525 | =cut
|
---|
| 526 |
|
---|
| 527 |
|
---|
| 528 | 1;
|
---|