Temporarily reverse out change cd5cc49dbc0e5ee748252c2da8b435855908e6d2.
[p5sagit/p5-mst-13.2.git] / lib / Module / Build / ConfigData.pm
CommitLineData
bb4e9162 1package Module::Build::ConfigData;
2use strict;
3my $arrayref = eval do {local $/; <DATA>}
4 or die "Couldn't load ConfigData data: $@";
5close DATA;
6my ($config, $features, $auto_features) = @$arrayref;
7
8sub config { $config->{$_[1]} }
9
10sub set_config { $config->{$_[1]} = $_[2] }
11sub set_feature { $features->{$_[1]} = 0+!!$_[2] } # Constrain to 1 or 0
12
13sub auto_feature_names { grep !exists $features->{$_}, keys %$auto_features }
14
15sub feature_names {
16 my @features = (keys %$features, auto_feature_names());
17 @features;
18}
19
20sub config_names { keys %$config }
21
22sub write {
23 my $me = __FILE__;
24 require IO::File;
25 require Data::Dumper;
26
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: $!";
30 seek($fh, 0, 0);
31 while (<$fh>) {
32 last if /^__DATA__$/;
33 }
34 die "Couldn't find __DATA__ token in $me" if eof($fh);
35
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));
40 $fh->close;
41
42 chmod($mode_orig, $me)
43 or warn "Couldn't restore permissions on $me: $!";
44}
45
46sub feature {
47 my ($package, $key) = @_;
48 return $features->{$key} if exists $features->{$key};
49
50 my $info = $auto_features->{$key} or return 0;
51
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.
55 my %info = %$info;
56
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';
60
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; }
65 }
66 }
67 return 1;
68}
69
70
71=head1 NAME
72
73Module::Build::ConfigData - Configuration for Module::Build
74
75
76=head1 SYNOPSIS
77
78 use Module::Build::ConfigData;
79 $value = Module::Build::ConfigData->config('foo');
80 $value = Module::Build::ConfigData->feature('bar');
81
82 @names = Module::Build::ConfigData->config_names;
83 @names = Module::Build::ConfigData->feature_names;
84
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
88
89
90=head1 DESCRIPTION
91
92This module holds the configuration data for the C<Module::Build>
93module. It also provides a programmatic interface for getting or
94setting that configuration data. Note that in order to actually make
95changes, you'll have to have write access to the C<Module::Build::ConfigData>
96module, and you should attempt to understand the repercussions of your
97actions.
98
99
100=head1 METHODS
101
102=over 4
103
104=item config($name)
105
106Given a string argument, returns the value of the configuration item
107by that name, or C<undef> if no such item exists.
108
109=item feature($name)
110
111Given a string argument, returns the value of the feature by that
112name, or C<undef> if no such feature exists.
113
114=item set_config($name, $value)
115
116Sets the configuration item with the given name to the given value.
117The value may be any Perl scalar that will serialize correctly using
118C<Data::Dumper>. This includes references, objects (usually), and
119complex data structures. It probably does not include transient
120things like filehandles or sockets.
121
122=item set_feature($name, $value)
123
124Sets the feature with the given name to the given boolean value. The
125value will be converted to 0 or 1 automatically.
126
127=item config_names()
128
129Returns a list of all the names of config items currently defined in
130C<Module::Build::ConfigData>, or in scalar context the number of items.
131
132=item feature_names()
133
134Returns a list of all the names of features currently defined in
135C<Module::Build::ConfigData>, or in scalar context the number of features.
136
137=item auto_feature_names()
138
139Returns a list of all the names of features whose availability is
140dynamically determined, or in scalar context the number of such
141features. Does not include such features that have later been set to
142a fixed value.
143
144=item write()
145
146Commits any changes from C<set_config()> and C<set_feature()> to disk.
147Requires write access to the C<Module::Build::ConfigData> module.
148
149=back
150
151
152=head1 AUTHOR
153
154C<Module::Build::ConfigData> was automatically created using C<Module::Build>.
155C<Module::Build> was written by Ken Williams, but he holds no
156authorship claim or copyright claim to the contents of C<Module::Build::ConfigData>.
157
158=cut
159
160__DATA__
161
162[
163 {},
164 {},
165 {
166 'YAML_support' => {
167 'requires' => {
168 'YAML' => ' >= 0.35, != 0.49_01 '
169 },
cbe85d23 170 'description' => 'Use YAML.pm to write META.yml files'
bb4e9162 171 },
172 'manpage_support' => {
173 'requires' => {
174 'Pod::Man' => 0
175 },
cbe85d23 176 'description' => 'Create Unix man pages'
bb4e9162 177 },
178 'C_support' => {
179 'requires' => {
180 'ExtUtils::CBuilder' => '0.15'
181 },
182 'recommends' => {
183 'ExtUtils::ParseXS' => '1.02'
184 },
cbe85d23 185 'description' => 'Compile/link C & XS code'
bb4e9162 186 },
187 'HTML_support' => {
188 'requires' => {
189 'Pod::Html' => 0
190 },
cbe85d23 191 'description' => 'Create HTML documentation'
bb4e9162 192 }
193 }
194 ]