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