This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Update Module-Build to CPAN version 0.4200
[perl5.git] / cpan / Module-Build / lib / Module / Build / ConfigData.pm
CommitLineData
6d3892ec
CBW
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__;
6d3892ec
CBW
24
25 # Can't use Module::Build::Dumper here because M::B is only a
26 # build-time prereq of this module
27 require Data::Dumper;
28
29 my $mode_orig = (stat $me)[2] & 07777;
30 chmod($mode_orig | 0222, $me); # Make it writeable
46de787b 31 open(my $fh, '+<', $me) or die "Can't rewrite $me: $!";
6d3892ec
CBW
32 seek($fh, 0, 0);
33 while (<$fh>) {
34 last if /^__DATA__$/;
35 }
36 die "Couldn't find __DATA__ token in $me" if eof($fh);
37
38 seek($fh, tell($fh), 0);
39 my $data = [$config, $features, $auto_features];
46de787b 40 print($fh 'do{ my '
6d3892ec
CBW
41 . Data::Dumper->new([$data],['x'])->Purity(1)->Dump()
42 . '$x; }' );
43 truncate($fh, tell($fh));
46de787b 44 close $fh;
6d3892ec
CBW
45
46 chmod($mode_orig, $me)
47 or warn "Couldn't restore permissions on $me: $!";
48}
49
50sub feature {
51 my ($package, $key) = @_;
52 return $features->{$key} if exists $features->{$key};
53
54 my $info = $auto_features->{$key} or return 0;
55
56 # Under perl 5.005, each(%$foo) isn't working correctly when $foo
57 # was reanimated with Data::Dumper and eval(). Not sure why, but
58 # copying to a new hash seems to solve it.
59 my %info = %$info;
60
61 require Module::Build; # XXX should get rid of this
62 while (my ($type, $prereqs) = each %info) {
63 next if $type eq 'description' || $type eq 'recommends';
64
65 my %p = %$prereqs; # Ditto here.
66 while (my ($modname, $spec) = each %p) {
67 my $status = Module::Build->check_installed_status($modname, $spec);
68 if ((!$status->{ok}) xor ($type =~ /conflicts$/)) { return 0; }
69 if ( ! eval "require $modname; 1" ) { return 0; }
70 }
71 }
72 return 1;
73}
74
75
76=head1 NAME
77
78Module::Build::ConfigData - Configuration for Module::Build
79
80=head1 SYNOPSIS
81
82 use Module::Build::ConfigData;
83 $value = Module::Build::ConfigData->config('foo');
84 $value = Module::Build::ConfigData->feature('bar');
85
86 @names = Module::Build::ConfigData->config_names;
87 @names = Module::Build::ConfigData->feature_names;
88
89 Module::Build::ConfigData->set_config(foo => $new_value);
90 Module::Build::ConfigData->set_feature(bar => $new_value);
91 Module::Build::ConfigData->write; # Save changes
92
93
94=head1 DESCRIPTION
95
96This module holds the configuration data for the C<Module::Build>
97module. It also provides a programmatic interface for getting or
98setting that configuration data. Note that in order to actually make
99changes, you'll have to have write access to the C<Module::Build::ConfigData>
100module, and you should attempt to understand the repercussions of your
101actions.
102
103
104=head1 METHODS
105
106=over 4
107
108=item config($name)
109
110Given a string argument, returns the value of the configuration item
111by that name, or C<undef> if no such item exists.
112
113=item feature($name)
114
115Given a string argument, returns the value of the feature by that
116name, or C<undef> if no such feature exists.
117
118=item set_config($name, $value)
119
120Sets the configuration item with the given name to the given value.
121The value may be any Perl scalar that will serialize correctly using
122C<Data::Dumper>. This includes references, objects (usually), and
123complex data structures. It probably does not include transient
124things like filehandles or sockets.
125
126=item set_feature($name, $value)
127
128Sets the feature with the given name to the given boolean value. The
129value will be converted to 0 or 1 automatically.
130
131=item config_names()
132
133Returns a list of all the names of config items currently defined in
134C<Module::Build::ConfigData>, or in scalar context the number of items.
135
136=item feature_names()
137
138Returns a list of all the names of features currently defined in
139C<Module::Build::ConfigData>, or in scalar context the number of features.
140
141=item auto_feature_names()
142
143Returns a list of all the names of features whose availability is
144dynamically determined, or in scalar context the number of such
145features. Does not include such features that have later been set to
146a fixed value.
147
148=item write()
149
150Commits any changes from C<set_config()> and C<set_feature()> to disk.
151Requires write access to the C<Module::Build::ConfigData> module.
152
153=back
154
155
156=head1 AUTHOR
157
158C<Module::Build::ConfigData> was automatically created using C<Module::Build>.
159C<Module::Build> was written by Ken Williams, but he holds no
160authorship claim or copyright claim to the contents of C<Module::Build::ConfigData>.
161
162=cut
163
164
165__DATA__
166do{ my $x = [
167 {},
168 {},
169 {
18b2aa6a
CBW
170 'inc_bundling_support' => {
171 'description' => 'Bundle Module::Build in inc/',
172 'requires' => {
173 'ExtUtils::Installed' => '1.999',
174 'ExtUtils::Install' => '1.54'
175 }
176 },
177 'license_creation' => {
178 'description' => 'Create licenses automatically in distributions',
179 'requires' => {
180 'Software::License' => 0
181 }
182 },
6d3892ec 183 'manpage_support' => {
18b2aa6a 184 'description' => 'Create Unix man pages',
6d3892ec
CBW
185 'requires' => {
186 'Pod::Man' => 0
18b2aa6a 187 }
6d3892ec 188 },
18b2aa6a
CBW
189 'HTML_support' => {
190 'description' => 'Create HTML documentation',
191 'requires' => {
192 'Pod::Html' => 0
193 }
194 },
6d3892ec 195 'dist_authoring' => {
6d3892ec
CBW
196 'recommends' => {
197 'Module::Signature' => '0.21',
198 'Pod::Readme' => '0.04'
199 },
6e4bdc3f
CBW
200 'description' => 'Create new distributions',
201 'requires' => {
202 'Archive::Tar' => '1.09'
203 }
6d3892ec 204 },
6e4bdc3f
CBW
205 'PPM_support' => {
206 'description' => 'Generate PPM files for distributions'
18b2aa6a 207 }
6d3892ec
CBW
208 }
209 ];
210$x; }