1 package Module::Build::ConfigData;
3 my $arrayref = eval do {local $/; <DATA>}
4 or die "Couldn't load ConfigData data: $@";
6 my ($config, $features, $auto_features) = @$arrayref;
8 sub config { $config->{$_[1]} }
10 sub set_config { $config->{$_[1]} = $_[2] }
11 sub set_feature { $features->{$_[1]} = 0+!!$_[2] } # Constrain to 1 or 0
13 sub auto_feature_names { grep !exists $features->{$_}, keys %$auto_features }
16 my @features = (keys %$features, auto_feature_names());
20 sub config_names { keys %$config }
27 my $mode_orig = (stat $me)[2] & 07777;
28 chmod($mode_orig | 0222, $me); # Make it writeable
29 my $fh = IO::File->new($me, 'r+') or die "Can't rewrite $me: $!";
34 die "Couldn't find __DATA__ token in $me" if eof($fh);
36 local $Data::Dumper::Terse = 1;
37 seek($fh, tell($fh), 0);
38 $fh->print( Data::Dumper::Dumper([$config, $features, $auto_features]) );
39 truncate($fh, tell($fh));
42 chmod($mode_orig, $me)
43 or warn "Couldn't restore permissions on $me: $!";
47 my ($package, $key) = @_;
48 return $features->{$key} if exists $features->{$key};
50 my $info = $auto_features->{$key} or return 0;
52 # Under perl 5.005, each(%$foo) isn't working correctly when $foo
53 # was reanimated with Data::Dumper and eval(). Not sure why, but
54 # copying to a new hash seems to solve it.
57 require Module::Build; # XXX should get rid of this
58 while (my ($type, $prereqs) = each %info) {
59 next if $type eq 'description' || $type eq 'recommends';
61 my %p = %$prereqs; # Ditto here.
62 while (my ($modname, $spec) = each %p) {
63 my $status = Module::Build->check_installed_status($modname, $spec);
64 if ((!$status->{ok}) xor ($type =~ /conflicts$/)) { return 0; }
73 Module::Build::ConfigData - Configuration for Module::Build
78 use Module::Build::ConfigData;
79 $value = Module::Build::ConfigData->config('foo');
80 $value = Module::Build::ConfigData->feature('bar');
82 @names = Module::Build::ConfigData->config_names;
83 @names = Module::Build::ConfigData->feature_names;
85 Module::Build::ConfigData->set_config(foo => $new_value);
86 Module::Build::ConfigData->set_feature(bar => $new_value);
87 Module::Build::ConfigData->write; # Save changes
92 This module holds the configuration data for the C<Module::Build>
93 module. It also provides a programmatic interface for getting or
94 setting that configuration data. Note that in order to actually make
95 changes, you'll have to have write access to the C<Module::Build::ConfigData>
96 module, and you should attempt to understand the repercussions of your
106 Given a string argument, returns the value of the configuration item
107 by that name, or C<undef> if no such item exists.
111 Given a string argument, returns the value of the feature by that
112 name, or C<undef> if no such feature exists.
114 =item set_config($name, $value)
116 Sets the configuration item with the given name to the given value.
117 The value may be any Perl scalar that will serialize correctly using
118 C<Data::Dumper>. This includes references, objects (usually), and
119 complex data structures. It probably does not include transient
120 things like filehandles or sockets.
122 =item set_feature($name, $value)
124 Sets the feature with the given name to the given boolean value. The
125 value will be converted to 0 or 1 automatically.
129 Returns a list of all the names of config items currently defined in
130 C<Module::Build::ConfigData>, or in scalar context the number of items.
132 =item feature_names()
134 Returns a list of all the names of features currently defined in
135 C<Module::Build::ConfigData>, or in scalar context the number of features.
137 =item auto_feature_names()
139 Returns a list of all the names of features whose availability is
140 dynamically determined, or in scalar context the number of such
141 features. Does not include such features that have later been set to
146 Commits any changes from C<set_config()> and C<set_feature()> to disk.
147 Requires write access to the C<Module::Build::ConfigData> module.
154 C<Module::Build::ConfigData> was automatically created using C<Module::Build>.
155 C<Module::Build> was written by Ken Williams, but he holds no
156 authorship claim or copyright claim to the contents of C<Module::Build::ConfigData>.
168 'YAML' => ' >= 0.35, != 0.49_01 '
170 'description' => 'Use YAML.pm to write META.yml files'
172 'manpage_support' => {
176 'description' => 'Create Unix man pages'
180 'ExtUtils::CBuilder' => '0.15'
183 'ExtUtils::ParseXS' => '1.02'
185 'description' => 'Compile/link C & XS code'
191 'description' => 'Create HTML documentation'