1 |
williamc |
1.1 |
#
|
2 |
|
|
# BuildEnvironment.pm
|
3 |
|
|
#
|
4 |
|
|
# Originally Written by Christopher Williams
|
5 |
|
|
#
|
6 |
|
|
# Description
|
7 |
|
|
#
|
8 |
|
|
# Interface
|
9 |
|
|
# ---------
|
10 |
|
|
# new() : A new BuildEnvironment object
|
11 |
|
|
# newenv() :Set the current environment to a copy of the previous one
|
12 |
|
|
# restoreenv() : Restore the previous environment, deleting the current one
|
13 |
|
|
# addparam(name, value) : add the value to the variable name
|
14 |
|
|
# setparam(name, value) : Replace the current value of name with value
|
15 |
|
|
# getparam(name) : return the value of the parameter as a list
|
16 |
|
|
|
17 |
|
|
package BuildSystem::BuildEnvironment;
|
18 |
|
|
|
19 |
|
|
sub new {
|
20 |
|
|
my $class=shift;
|
21 |
|
|
$self={};
|
22 |
|
|
bless $self, $class;
|
23 |
|
|
$self->{env}[0]={}; # set up the base environment hash
|
24 |
|
|
return $self;
|
25 |
|
|
}
|
26 |
|
|
|
27 |
|
|
sub newenv {
|
28 |
|
|
my $self=shift;
|
29 |
|
|
my $oldenv=$#{$self->{env}};
|
30 |
|
|
my $newenv=$oldenv+1;
|
31 |
|
|
|
32 |
|
|
# create new hash
|
33 |
|
|
push @{$self->{env}}, {};
|
34 |
|
|
# copy old hash into new
|
35 |
|
|
foreach $key ( %{$self->{env}[$oldenv]} ){
|
36 |
|
|
$self->{env}[$newenv]{$key}=$self->{env}[$oldenv]{$key};
|
37 |
|
|
}
|
38 |
|
|
}
|
39 |
|
|
|
40 |
|
|
sub restoreenv {
|
41 |
|
|
my $self=shift;
|
42 |
|
|
|
43 |
|
|
undef $self->{env}[$#{$self->{env}}];
|
44 |
|
|
pop @{$self->{env}};
|
45 |
|
|
}
|
46 |
|
|
|
47 |
|
|
sub addparam {
|
48 |
|
|
my $self=shift;
|
49 |
|
|
my $name=shift;
|
50 |
|
|
my $value=shift;
|
51 |
|
|
|
52 |
|
|
push @{$self->{env}[$#{$self->{env}}]{$name}}, $value;
|
53 |
|
|
|
54 |
|
|
}
|
55 |
|
|
|
56 |
|
|
sub setparam {
|
57 |
|
|
my $self=shift;
|
58 |
|
|
my $name=shift;
|
59 |
|
|
my $value=shift;
|
60 |
|
|
|
61 |
|
|
undef @{$self->{env}[$#{$self->{env}}]{$name}}}
|
62 |
|
|
$self->addparam($name,$value);
|
63 |
|
|
|
64 |
|
|
}
|
65 |
|
|
|
66 |
|
|
sub getparam {
|
67 |
|
|
my $self=shift;
|
68 |
|
|
my $name=shift;
|
69 |
|
|
|
70 |
|
|
return @{$self->{env}[$#{$self->{env}}]{$name}};
|
71 |
|
|
}
|