File Coverage

blib/lib/Module/Build/ConfigData.pm
Criterion Covered Total %
statement 15 39 38.4
branch 6 18 33.3
condition 3 7 42.8
subroutine 2 9 22.2
pod 8 8 100.0
total 34 81 41.9


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