File Coverage

blib/lib/ExtUtils/MakeMaker/Attributes.pm
Criterion Covered Total %
statement 43 50 86.0
branch 8 14 57.1
condition 7 15 46.6
subroutine 14 16 87.5
pod 8 8 100.0
total 80 103 77.6


line stmt bran cond sub pod time code
1             package ExtUtils::MakeMaker::Attributes;
2              
3 1     1   55082 use strict;
  1         8  
  1         24  
4 1     1   4 use warnings;
  1         2  
  1         27  
5 1     1   6 use Carp;
  1         1  
  1         44  
6 1     1   4 use Exporter 'import';
  1         2  
  1         29  
7 1     1   2412 use Module::CoreList;
  1         88522  
  1         11  
8 1     1   582 use version;
  1         2  
  1         8  
9              
10             our $VERSION = '0.001';
11              
12             my @exports = qw(
13             known_eumm_attributes is_known_eumm_attribute
14             eumm_attribute_requires_version eumm_attribute_fallback
15             eumm_version_supported_attributes eumm_version_supports_attribute
16             perl_version_supported_attributes perl_version_supports_attribute
17             );
18             our @EXPORT_OK = @exports;
19             our %EXPORT_TAGS = (all => \@exports);
20              
21             my %attributes = (
22             ABSTRACT => {},
23             ABSTRACT_FROM => {},
24             AUTHOR => {},
25             BINARY_LOCATION => {},
26             BUILD_REQUIRES => {
27             requires => '6.55_03',
28             fallback => {method => 'merge_prereqs', merge_target => 'PREREQ_PM'},
29             },
30             C => {},
31             CCFLAGS => {},
32             CONFIG => {},
33             CONFIGURE => {},
34             CONFIGURE_REQUIRES => {requires => '6.52'},
35             DEFINE => {},
36             DESTDIR => {},
37             DIR => {},
38             DISTNAME => {},
39             DISTVNAME => {},
40             DLEXT => {},
41             DL_FUNCS => {},
42             DL_VARS => {},
43             EXCLUDE_EXT => {},
44             EXE_FILES => {},
45             FIRST_MAKEFILE => {},
46             FULLPERL => {},
47             FULLPERLRUN => {},
48             FULLPERLRUNINST => {},
49             FUNCLIST => {},
50             H => {},
51             IMPORTS => {},
52             INC => {},
53             INCLUDE_EXT => {},
54             INSTALLARCHLIB => {},
55             INSTALLBIN => {},
56             INSTALLDIRS => {},
57             INSTALLMAN1DIR => {},
58             INSTALLMAN3DIR => {},
59             INSTALLPRIVLIB => {},
60             INSTALLSCRIPT => {},
61             INSTALLSITEARCH => {},
62             INSTALLSITEBIN => {},
63             INSTALLSITELIB => {},
64             INSTALLSITEMAN1DIR => {},
65             INSTALLSITEMAN3DIR => {},
66             INSTALLSITESCRIPT => {requires => '6.30_02'},
67             INSTALLVENDORARCH => {},
68             INSTALLVENDORBIN => {},
69             INSTALLVENDORLIB => {},
70             INSTALLVENDORMAN1DIR => {},
71             INSTALLVENDORMAN3DIR => {},
72             INSTALLVENDORSCRIPT => {requires => '6.30_02'},
73             INST_ARCHLIB => {},
74             INST_BIN => {},
75             INST_LIB => {},
76             INST_MAN1DIR => {},
77             INST_MAN3DIR => {},
78             INST_SCRIPT => {},
79             LD => {},
80             LDDLFLAGS => {},
81             LDFROM => {},
82             LIB => {},
83             LIBPERL_A => {},
84             LIBS => {},
85             LICENSE => {requires => '6.31'},
86             LINKTYPE => {},
87             MAGICXS => {requires => '6.8305'},
88             MAKE => {requires => '6.30_01'},
89             MAKEAPERL => {},
90             MAKEFILE_OLD => {},
91             MAN1PODS => {},
92             MAN3PODS => {},
93             MAP_TARGET => {},
94             META_ADD => {requires => '6.46'},
95             META_MERGE => {requires => '6.46'},
96             MIN_PERL_VERSION => {requires => '6.48'},
97             MYEXTLIB => {},
98             NAME => {},
99             NEEDS_LINKING => {},
100             NOECHO => {},
101             NORECURS => {},
102             NO_META => {},
103             NO_MYMETA => {requires => '6.57_02'},
104             NO_PACKLIST => {requires => '6.7501'},
105             NO_PERLLOCAL => {requires => '6.7501'},
106             NO_VC => {},
107             OBJECT => {},
108             OPTIMIZE => {},
109             PERL => {},
110             PERL_CORE => {},
111             PERLMAINCC => {},
112             PERL_ARCHLIB => {},
113             PERL_LIB => {},
114             PERL_MALLOC_OK => {},
115             PERLPREFIX => {},
116             PERLRUN => {},
117             PERLRUNINST => {},
118             PERL_SRC => {},
119             PERM_DIR => {requires => '6.51_01'},
120             PERM_RW => {},
121             PERM_RWX => {},
122             PL_FILES => {},
123             PM => {},
124             PMLIBDIRS => {},
125             PM_FILTER => {},
126             POLLUTE => {},
127             PPM_INSTALL_EXEC => {},
128             PPM_INSTALL_SCRIPT => {},
129             PPM_UNINSTALL_EXEC => {requires => '6.8502'},
130             PPM_UNINSTALL_SCRIPT => {requires => '6.8502'},
131             PREFIX => {},
132             PREREQ_FATAL => {},
133             PREREQ_PM => {},
134             PREREQ_PRINT => {},
135             PRINT_PREREQ => {},
136             SITEPREFIX => {},
137             SIGN => {requires => '6.18'},
138             SKIP => {},
139             TEST_REQUIRES => {
140             requires => '6.64',
141             fallback => {method => 'merge_prereqs', merge_target => 'PREREQ_PM'},
142             },
143             TYPEMAPS => {},
144             VENDORPREFIX => {},
145             VERBINST => {},
146             VERSION => {},
147             VERSION_FROM => {},
148             VERSION_SYM => {},
149             XS => {},
150             XSBUILD => {requires => '7.12'},
151             XSMULTI => {requires => '7.12'},
152             XSOPT => {},
153             XSPROTOARG => {},
154             XS_VERSION => {},
155             clean => {},
156             depend => {},
157             dist => {},
158             dynamic_lib => {},
159             linkext => {},
160             macro => {},
161             postamble => {},
162             realclean => {},
163             test => {},
164             tool_autosplit => {},
165             );
166              
167             sub known_eumm_attributes {
168 1     1   942 no locale;
  1         475  
  1         5  
169 3     3 1 270 return sort keys %attributes;
170             }
171              
172             sub is_known_eumm_attribute {
173 280     280 1 983 my ($attribute) = @_;
174 280   66     742 return !!(defined $attribute && exists $attributes{$attribute});
175             }
176              
177             sub eumm_attribute_requires_version {
178 276     276 1 364 my ($attribute) = @_;
179 276 50       360 croak "Unknown ExtUtils::MakeMaker attribute $attribute"
180             unless is_known_eumm_attribute($attribute);
181 276   100     738 return $attributes{$attribute}{requires} || 0;
182             }
183              
184             sub eumm_attribute_fallback {
185 2     2 1 10 my ($attribute) = @_;
186 2 50       4 croak "Unknown ExtUtils::MakeMaker attribute $attribute"
187             unless is_known_eumm_attribute($attribute);
188 2 100       8 if (defined(my $fallback = $attributes{$attribute}{fallback})) {
189 1         10 return +{%$fallback};
190             }
191 1         4 return undef;
192             }
193              
194             sub eumm_version_supports_attribute {
195 0     0 1 0 my ($attribute, $eumm_version) = @_;
196 0 0       0 return 0 unless is_known_eumm_attribute($attribute);
197 0   0     0 my $required_version = eumm_attribute_requires_version($attribute) || return 1;
198 0 0 0     0 return version->parse($eumm_version || 0) >= version->parse($required_version) ? 1 : 0;
199             }
200              
201             sub perl_version_supports_attribute {
202 0     0 1 0 my ($attribute, $perl_version) = @_;
203 0         0 return eumm_version_supports_attribute($attribute, _eumm_version_for_perl($perl_version));
204             }
205              
206             sub eumm_version_supported_attributes {
207 2     2 1 22 my ($eumm_version) = @_;
208 2   100     15 $eumm_version = version->parse($eumm_version || 0);
209 2         4 my @supported;
210 2         5 foreach my $attribute (known_eumm_attributes()) {
211 274 100       366 if (my $required_version = eumm_attribute_requires_version($attribute)) {
212 40 100       216 push @supported, $attribute if $eumm_version >= version->parse($required_version);
213             } else {
214 234         427 push @supported, $attribute;
215             }
216             }
217 2         46 return @supported;
218             }
219              
220             sub perl_version_supported_attributes {
221 1     1 1 680 return eumm_version_supported_attributes(_eumm_version_for_perl(@_));
222             }
223              
224             sub _eumm_version_for_perl {
225 1     1   3 my ($perl_version) = @_;
226 1   50     5 my $module_versions = Module::CoreList::find_version($perl_version) || return 0;
227 0   0       return $module_versions->{'ExtUtils::MakeMaker'} || 0;
228             }
229              
230             1;
231              
232             =head1 NAME
233              
234             ExtUtils::MakeMaker::Attributes - Determine when ExtUtils::MakeMaker attributes
235             are available
236              
237             =head1 SYNOPSIS
238              
239             use ExtUtils::MakeMaker::Attributes ':all';
240            
241             my @eumm_available = eumm_version_supported_attributes(ExtUtils::MakeMaker->VERSION);
242             my @core_available = perl_version_supported_attributes($]);
243            
244             unless (perl_version_supports_attribute('v5.10.1', 'TEST_REQUIRES')) {
245             ...
246             }
247            
248             my $fallback = eumm_attribute_fallback('TEST_REQUIRES');
249             my $required_eumm = eumm_attribute_requires_version('TEST_REQUIRES');
250             unless (eval { ExtUtils::MakeMaker->VERSION($required_eumm); 1 }) {
251             ...
252             }
253              
254             =head1 DESCRIPTION
255              
256             This module provides an API to determine what attributes are available to a
257             particular version of L, and conversely, what version of
258             L is required for a particular attribute. See
259             L for more details on
260             the available attributes.
261              
262             =head1 FUNCTIONS
263              
264             All functions are exported on demand, and can be exported individually or via
265             the C<:all> tag.
266              
267             =head2 known_eumm_attributes
268              
269             my @attributes = known_eumm_attributes;
270              
271             Returns a list of attributes known to be accepted by the latest version of
272             L.
273              
274             =head2 is_known_eumm_attribute
275              
276             my $boolean = is_known_eumm_attribute($attribute);
277              
278             Returns a boolean whether the attribute is known to be accepted by the latest
279             version of L.
280              
281             =head2 eumm_attribute_requires_version
282              
283             my $version = eumm_attribute_requires_version($attribute);
284              
285             Returns the minimum version of L that accepts the
286             attribute.
287              
288             =head2 eumm_attribute_fallback
289              
290             my $hashref = eumm_attribute_fallback($attribute);
291              
292             In cases where the active version of L does not support an
293             attribute, the attribute should be deleted from the options passed to
294             C. However, some attributes may still be useful in other ways,
295             as indicated by this function. If the attribute has an associated fallback
296             method, it returns a hashref containing a C and possibly other related
297             keys. Otherwise, it returns C. Currently it may return these methods:
298              
299             =over 2
300              
301             =item merge_prereqs
302              
303             The key's contents (as a hashref of prerequisites) should be merged into the
304             C (returned in the fallback hashref), ideally using
305             L.
306              
307             =back
308              
309             =head2 eumm_version_supports_attribute
310              
311             my $boolean = eumm_version_supports_attribute($attribute, $eumm_version);
312              
313             Returns a boolean whether the L supports the attribute at
314             the specified version.
315              
316             =head2 perl_version_supports_attribute
317              
318             my $boolean = perl_version_supports_attribute($attribute, $perl_version);
319              
320             Returns a boolean whether the version of L shipped in the
321             specified version of Perl supports the attribute.
322              
323             =head2 eumm_version_supported_attributes
324              
325             my @attributes = eumm_version_supported_attributes($eumm_version);
326              
327             Returns a list of all attributes supported by the specified version of
328             L.
329              
330             =head2 perl_version_supported_attributes
331              
332             my @attributes = perl_version_supported_attributes($perl_version);
333              
334             Returns a list of all attributes supported by the version of
335             L shipped in the specified version of Perl.
336              
337             =head1 BUGS
338              
339             Report any issues on the public bugtracker.
340              
341             =head1 AUTHOR
342              
343             Dan Book
344              
345             =head1 COPYRIGHT AND LICENSE
346              
347             This software is Copyright (c) 2017 by Dan Book.
348              
349             This is free software, licensed under:
350              
351             The Artistic License 2.0 (GPL Compatible)
352              
353             =head1 SEE ALSO
354              
355             L