This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Upgrade to Module::Build 0.2806
[perl5.git] / lib / Module / Build / Config.pm
CommitLineData
77e96e88
RGS
1package Module::Build::Config;
2
3use strict;
4use Config;
5
6sub new {
7 my ($pack, %args) = @_;
8 return bless {
9 stack => {},
10 values => $args{values} || {},
11 }, $pack;
12}
13
14sub get {
15 my ($self, $key) = @_;
16 return $self->{values}{$key} if ref($self) && exists $self->{values}{$key};
17 return $Config{$key};
18}
19
20sub set {
21 my ($self, $key, $val) = @_;
22 $self->{values}{$key} = $val;
23}
24
25sub push {
26 my ($self, $key, $val) = @_;
27 push @{$self->{stack}{$key}}, $self->{values}{$key}
28 if exists $self->{values}{$key};
29 $self->{values}{$key} = $val;
30}
31
32sub pop {
33 my ($self, $key) = @_;
34
35 my $val = delete $self->{values}{$key};
36 if ( exists $self->{stack}{$key} ) {
37 $self->{values}{$key} = pop @{$self->{stack}{$key}};
38 delete $self->{stack}{$key} unless @{$self->{stack}{$key}};
39 }
40
41 return $val;
42}
43
44sub values_set {
45 my $self = shift;
46 return undef unless ref($self);
47 return $self->{values};
48}
49
50sub all_config {
51 my $self = shift;
52 my $v = ref($self) ? $self->{values} : {};
53 return {%Config, %$v};
54}
55
561;