Commit | Line | Data |
77e96e88 |
1 | package Module::Build::Config; |
2 | |
3 | use strict; |
7a827510 |
4 | use vars qw($VERSION); |
613f422f |
5 | $VERSION = '0.35_08'; |
7a827510 |
6 | $VERSION = eval $VERSION; |
77e96e88 |
7 | use Config; |
8 | |
9 | sub new { |
10 | my ($pack, %args) = @_; |
11 | return bless { |
12 | stack => {}, |
13 | values => $args{values} || {}, |
14 | }, $pack; |
15 | } |
16 | |
17 | sub get { |
18 | my ($self, $key) = @_; |
19 | return $self->{values}{$key} if ref($self) && exists $self->{values}{$key}; |
20 | return $Config{$key}; |
21 | } |
22 | |
23 | sub set { |
24 | my ($self, $key, $val) = @_; |
25 | $self->{values}{$key} = $val; |
26 | } |
27 | |
28 | sub push { |
29 | my ($self, $key, $val) = @_; |
30 | push @{$self->{stack}{$key}}, $self->{values}{$key} |
31 | if exists $self->{values}{$key}; |
32 | $self->{values}{$key} = $val; |
33 | } |
34 | |
35 | sub pop { |
36 | my ($self, $key) = @_; |
37 | |
38 | my $val = delete $self->{values}{$key}; |
39 | if ( exists $self->{stack}{$key} ) { |
40 | $self->{values}{$key} = pop @{$self->{stack}{$key}}; |
41 | delete $self->{stack}{$key} unless @{$self->{stack}{$key}}; |
42 | } |
43 | |
44 | return $val; |
45 | } |
46 | |
47 | sub values_set { |
48 | my $self = shift; |
49 | return undef unless ref($self); |
50 | return $self->{values}; |
51 | } |
52 | |
53 | sub all_config { |
54 | my $self = shift; |
55 | my $v = ref($self) ? $self->{values} : {}; |
56 | return {%Config, %$v}; |
57 | } |
58 | |
59 | 1; |