|
| 1 | +package ExtUtils::Config; |
| 2 | +{ |
| 3 | + $ExtUtils::Config::VERSION = '0.006'; |
| 4 | +} |
| 5 | + |
| 6 | +use strict; |
| 7 | +use warnings; |
| 8 | +use Config; |
| 9 | + |
| 10 | +sub new { |
| 11 | + my ($pack, $args) = @_; |
| 12 | + return bless { |
| 13 | + values => ($args ? { %$args } : {}), |
| 14 | + }, $pack; |
| 15 | +} |
| 16 | + |
| 17 | +sub clone { |
| 18 | + my $self = shift; |
| 19 | + return __PACKAGE__->new($self->{values}); |
| 20 | +} |
| 21 | + |
| 22 | +sub get { |
| 23 | + my ($self, $key) = @_; |
| 24 | + return exists $self->{values}{$key} ? $self->{values}{$key} : $Config{$key}; |
| 25 | +} |
| 26 | + |
| 27 | +sub set { |
| 28 | + my ($self, $key, $val) = @_; |
| 29 | + $self->{values}{$key} = $val; |
| 30 | +} |
| 31 | + |
| 32 | +sub clear { |
| 33 | + my ($self, $key) = @_; |
| 34 | + return delete $self->{values}{$key}; |
| 35 | +} |
| 36 | + |
| 37 | +sub exists { |
| 38 | + my ($self, $key) = @_; |
| 39 | + return exists $self->{values}{$key} || exists $Config{$key}; |
| 40 | +} |
| 41 | + |
| 42 | +sub values_set { |
| 43 | + my $self = shift; |
| 44 | + return { %{$self->{values}} }; |
| 45 | +} |
| 46 | + |
| 47 | +sub all_config { |
| 48 | + my $self = shift; |
| 49 | + return { %Config, %{ $self->{values}} }; |
| 50 | +} |
| 51 | + |
| 52 | +1; |
| 53 | + |
| 54 | + |
| 55 | + |
| 56 | +=pod |
| 57 | +
|
| 58 | +=head1 NAME |
| 59 | +
|
| 60 | +ExtUtils::Config - A wrapper for perl's configuration |
| 61 | +
|
| 62 | +=head1 VERSION |
| 63 | +
|
| 64 | +version 0.006 |
| 65 | +
|
| 66 | +=head1 SYNOPSIS |
| 67 | +
|
| 68 | + my $config = ExtUtils::Config->new(); |
| 69 | + $config->set('installsitelib', "$ENV{HOME}/lib"); |
| 70 | +
|
| 71 | +=head1 DESCRIPTION |
| 72 | +
|
| 73 | +ExtUtils::Config is an abstraction around the %Config hash. |
| 74 | +
|
| 75 | +=head1 METHODS |
| 76 | +
|
| 77 | +=head2 new(\%config) |
| 78 | +
|
| 79 | +Create a new ExtUtils::Config object. The values in C<\%config> are used to initialize the object. |
| 80 | +
|
| 81 | +=head2 get($key) |
| 82 | +
|
| 83 | +Get the value of C<$key>. If not overriden it will return the value in %Config. |
| 84 | +
|
| 85 | +=head2 exists($key) |
| 86 | +
|
| 87 | +Tests for the existence of $key. |
| 88 | +
|
| 89 | +=head2 set($key, $value) |
| 90 | +
|
| 91 | +Set/override the value of C<$key> to C<$value>. |
| 92 | +
|
| 93 | +=head2 clear($key) |
| 94 | +
|
| 95 | +Reset the value of C<$key> to its original value. |
| 96 | +
|
| 97 | +=head2 values_set |
| 98 | +
|
| 99 | +Get a hashref of all overridden values. |
| 100 | +
|
| 101 | +=head2 all_config |
| 102 | +
|
| 103 | +Get a hashref of the complete configuration, including overrides. |
| 104 | +
|
| 105 | +=head2 clone |
| 106 | +
|
| 107 | +Clone the current configuration object. |
| 108 | +
|
| 109 | +=head1 AUTHORS |
| 110 | +
|
| 111 | +=over 4 |
| 112 | +
|
| 113 | +=item * |
| 114 | +
|
| 115 | + |
| 116 | +
|
| 117 | +=item * |
| 118 | +
|
| 119 | +Leon Timmermans <[email protected]> |
| 120 | +
|
| 121 | +=back |
| 122 | +
|
| 123 | +=head1 COPYRIGHT AND LICENSE |
| 124 | +
|
| 125 | +This software is copyright (c) 2006 by Ken Williams, Leon Timmermans. |
| 126 | +
|
| 127 | +This is free software; you can redistribute it and/or modify it under |
| 128 | +the same terms as the Perl 5 programming language system itself. |
| 129 | +
|
| 130 | +=cut |
| 131 | + |
| 132 | + |
| 133 | +__END__ |
| 134 | +
|
| 135 | +# ABSTRACT: A wrapper for perl's configuration |
| 136 | +
|
0 commit comments