| 1 | package ExtUtils::MakeMaker::CPANfile; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use ExtUtils::MakeMaker (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use File::Spec::Functions qw/catfile rel2abs/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use Module::CPANfile; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 4 | ▶ | use CPAN::Meta::Requirements; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 4 | ▶ | use version; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 4 | our $VERSION = "0.11"; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 4 | ▶ | sub import { | ||||||||||||||||||||||||||
|
Subroutine
import: called CC=1 SCAR=1.1
| |||||||||||||||||||||||||||||
| 14 | 4 | my $class = shift; | |||||||||||||||||||||||||||
| 15 | 4 | my $orig = \&ExtUtils::MakeMaker::WriteMakefile; | |||||||||||||||||||||||||||
| 16 | 3 | ▶ | my $writer = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=31 SCAR=51.2
| |||||||||||||||||||||||||||||
| 17 | 3 | my %params = @_; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | # Do nothing if not called from Makefile.PL | ||||||||||||||||||||||||||||
| 20 | 3 | my ($caller, $file, $line) = caller; | |||||||||||||||||||||||||||
| 21 | 3 | ▶ | (my $root = rel2abs($file)) =~ s/Makefile\.PL$//i or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 3 | ▶ | if (my $file = eval { Module::CPANfile->load(catfile($root, "cpanfile")) }) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 24 | 3 | my $prereqs = $file->prereqs; | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | # Runtime requires => PREREQ_PM | ||||||||||||||||||||||||||||
| 27 | 3 | _merge( | |||||||||||||||||||||||||||
| 28 | \%params, | ||||||||||||||||||||||||||||
| 29 | _get($prereqs, 'runtime', 'requires'), | ||||||||||||||||||||||||||||
| 30 | 'PREREQ_PM', | ||||||||||||||||||||||||||||
| 31 | ); | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | # Build requires => BUILD_REQUIRES / PREREQ_PM | ||||||||||||||||||||||||||||
| 34 | 3 | ▶ | _merge( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | \%params, | ||||||||||||||||||||||||||||
| 36 | _get($prereqs, 'build', 'requires'), | ||||||||||||||||||||||||||||
| 37 | _eumm('6.56') ? 'BUILD_REQUIRES' : 'PREREQ_PM', | ||||||||||||||||||||||||||||
| 38 | ); | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | # Test requires => TEST_REQUIRES / BUILD_REQUIRES / PREREQ_PM | ||||||||||||||||||||||||||||
| 41 | 3 | ▶ | _merge( | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 42 | \%params, | ||||||||||||||||||||||||||||
| 43 | _get($prereqs, 'test', 'requires'), | ||||||||||||||||||||||||||||
| 44 | _eumm('6.63_03') ? 'TEST_REQUIRES' : | ||||||||||||||||||||||||||||
| 45 | _eumm('6.56') ? 'BUILD_REQUIRES' : 'PREREQ_PM', | ||||||||||||||||||||||||||||
| 46 | ); | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | # Configure requires => CONFIGURE_REQUIRES / ignored | ||||||||||||||||||||||||||||
| 49 | 3 | ▶ | _merge( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | \%params, | ||||||||||||||||||||||||||||
| 51 | _get($prereqs, 'configure', 'requires'), | ||||||||||||||||||||||||||||
| 52 | _eumm('6.52') ? 'CONFIGURE_REQUIRES' : undef, | ||||||||||||||||||||||||||||
| 53 | ); | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | # Add myself to configure requires (if possible) | ||||||||||||||||||||||||||||
| 56 | 3 | ▶ | _merge( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | \%params, | ||||||||||||||||||||||||||||
| 58 | _req('ExtUtils::MakeMaker::CPANfile' => $VERSION), | ||||||||||||||||||||||||||||
| 59 | _eumm('6.52') ? 'CONFIGURE_REQUIRES' : undef, | ||||||||||||||||||||||||||||
| 60 | ); | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | # Set dynamic_config to 0 if not set explicitly | ||||||||||||||||||||||||||||
| 63 | 3 | ▶ | if (!exists $params{META_ADD}{dynamic_config} && | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $params{"META_ADD"}{"dynamic_config"} or exists $params{"META_MERGE"}{"dynamic_config"}
MC/DC0%0/2
exists $params{"META_ADD"}{"dynamic_config"} or exists $params{"META_MERGE"}{"dynamic_config"}
exists $params{"META_ADD"}{"dynamic_config"}
exists $params{"META_MERGE"}{"dynamic_config"}
Truth table33%1/3
A or B
A= exists $params{"META_ADD"}{"dynamic_config"}B= exists $params{"META_MERGE"}{"dynamic_config"}
| |||||||||||||||||||||||||||||
| 64 | !exists $params{META_MERGE}{dynamic_config}) { | ||||||||||||||||||||||||||||
| 65 | 3 | $params{META_MERGE}{dynamic_config} = 0; | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | # recommends, suggests, conflicts | ||||||||||||||||||||||||||||
| 69 | 3 | my $requires_2_0; | |||||||||||||||||||||||||||
| 70 | 3 | for my $type (qw/recommends suggests conflicts/) { | |||||||||||||||||||||||||||
| 71 | 9 | for my $phase (qw/configure build test runtime develop/) { | |||||||||||||||||||||||||||
| 72 | 45 | ▶ | my %tmp = %{$params{META_MERGE}{prereqs}{$phase} || {}}; | ||||||||||||||||||||||||||
|
Condition100%2/2
$params{'META_MERGE'}{'prereqs'}{$phase} || {}
MC/DC100%1/1
$params{'META_MERGE'}{'prereqs'}{$phase} || {}
$params{'META_MERGE'}{'prereqs'}{$phase}
Truth table100%2/2
A
A= $params{'META_MERGE'}{'prereqs'}{$phase}
| |||||||||||||||||||||||||||||
| 73 | 45 | _merge( | |||||||||||||||||||||||||||
| 74 | \%tmp, | ||||||||||||||||||||||||||||
| 75 | _get($prereqs, $phase, $type), | ||||||||||||||||||||||||||||
| 76 | $type, | ||||||||||||||||||||||||||||
| 77 | ); | ||||||||||||||||||||||||||||
| 78 | 45 | ▶ | if ($tmp{$type}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | 1 | $params{META_MERGE}{prereqs}{$phase} = \%tmp; | |||||||||||||||||||||||||||
| 80 | 1 | $requires_2_0 = 1; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | 3 | ▶ | if ($requires_2_0) { # for better recommends support | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | # stash prereqs, which is already converted | ||||||||||||||||||||||||||||
| 86 | 1 | my $tmp_prereqs = delete $params{META_MERGE}{prereqs}; | |||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 1 | require CPAN::Meta::Converter; | |||||||||||||||||||||||||||
| 89 | 1 | for my $key (qw/META_ADD META_MERGE/) { | |||||||||||||||||||||||||||
| 90 | 2 | ▶ | next unless %{$params{$key} || {}}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$params{$key} || {}
MC/DC0%0/1
$params{$key} || {}
$params{$key}
Truth table50%1/2
A
A= $params{$key}
| |||||||||||||||||||||||||||||
| 91 | 2 | my $converter = CPAN::Meta::Converter->new($params{$key}, default_version => 1.4); | |||||||||||||||||||||||||||
| 92 | 2 | $params{$key} = $converter->upgrade_fragment; | |||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 1 | ▶ | if ($params{META_MERGE}{prereqs}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | 0 | require CPAN::Meta::Requirements; | |||||||||||||||||||||||||||
| 97 | 0 | ▶ | for my $phase (keys %{$tmp_prereqs || {}}) { | ||||||||||||||||||||||||||
|
Condition0%0/2
$tmp_prereqs || {}
MC/DC0%0/1
$tmp_prereqs || {}
$tmp_prereqs
Truth table0%0/2
A
A= $tmp_prereqs
| |||||||||||||||||||||||||||||
| 98 | 0 | ▶ | for my $rel (keys %{$tmp_prereqs->{$phase} || {}}) { | ||||||||||||||||||||||||||
|
Condition0%0/2
$tmp_prereqs->{$phase} || {}
MC/DC0%0/1
$tmp_prereqs->{$phase} || {}
$tmp_prereqs->{$phase}
Truth table0%0/2
A
A= $tmp_prereqs->{$phase}
| |||||||||||||||||||||||||||||
| 99 | 0 | my $req1 = CPAN::Meta::Requirements->from_string_hash($tmp_prereqs->{$phase}{$rel}); | |||||||||||||||||||||||||||
| 100 | 0 | my $req2 = CPAN::Meta::Requirements->from_string_hash($params{META_MERGE}{prereqs}{$phase}{$rel}); | |||||||||||||||||||||||||||
| 101 | 0 | $req1->add_requirements($req2); | |||||||||||||||||||||||||||
| 102 | 0 | $params{META_MERGE}{prereqs}{$phase} = $req1->as_string_hash; | |||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | } else { | ||||||||||||||||||||||||||||
| 106 | 1 | $params{META_MERGE}{prereqs} = $tmp_prereqs; | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | # XXX: better to use also META_MERGE when applicable? | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | # As a small bonus, remove params that the installed version | ||||||||||||||||||||||||||||
| 113 | # of EUMM doesn't know, so that we can always write them | ||||||||||||||||||||||||||||
| 114 | # in Makefile.PL without caring about EUMM version. | ||||||||||||||||||||||||||||
| 115 | # (EUMM warns if it finds unknown parameters.) | ||||||||||||||||||||||||||||
| 116 | # As EUMM 6.17 is our prereq, we can safely ignore the keys | ||||||||||||||||||||||||||||
| 117 | # defined before 6.17. | ||||||||||||||||||||||||||||
| 118 | { | ||||||||||||||||||||||||||||
| 119 | 3 | ▶ | last if _eumm('6.66_03'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 120 | 0 | ▶ | if (my $r = delete $params{TEST_REQUIRES}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 121 | 0 | _merge(\%params, $r, 'BUILD_REQUIRES'); | |||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | 0 | ▶ | last if _eumm('6.56'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 124 | 0 | ▶ | if (my $r = delete $params{BUILD_REQUIRES}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 125 | 0 | _merge(\%params, $r, 'PREREQ_PM'); | |||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 0 | ▶ | last if _eumm('6.52'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 129 | 0 | delete $params{CONFIGURE_REQUIRES}; | |||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 0 | ▶ | last if _eumm('6.47_01'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 132 | 0 | delete $params{MIN_PERL_VERSION}; | |||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 0 | ▶ | last if _eumm('6.45_01'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 135 | 0 | delete $params{META_ADD}; | |||||||||||||||||||||||||||
| 136 | 0 | delete $params{META_MERGE}; | |||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | 0 | ▶ | last if _eumm('6.30_01'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 139 | 0 | delete $params{LICENSE}; | |||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||
| 141 | } else { | ||||||||||||||||||||||||||||
| 142 | 0 | print "cpanfile is not available: $@\n"; | |||||||||||||||||||||||||||
| 143 | 0 | exit 0; # N/A | |||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | 3 | $orig->(%params); | |||||||||||||||||||||||||||
| 147 | 4 | }; | |||||||||||||||||||||||||||
| 148 | { | ||||||||||||||||||||||||||||
| 149 | 4 | ▶ | no warnings 'redefine'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 150 | 4 | *main::WriteMakefile = | |||||||||||||||||||||||||||
| 151 | *ExtUtils::MakeMaker::WriteMakefile = $writer; | ||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | 15 | ▶ | sub _eumm { | ||||||||||||||||||||||||||
|
Subroutine
_eumm: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||
| 156 | 15 | my $version = shift; | |||||||||||||||||||||||||||
| 157 | 15 | ▶ | eval { ExtUtils::MakeMaker->VERSION($version) } ? 1 : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | 57 | ▶ | sub _get { | ||||||||||||||||||||||||||
|
Subroutine
_get: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 161 | 57 | my $prereqs = shift; | |||||||||||||||||||||||||||
| 162 | 57 | eval { $prereqs->requirements_for(@_) }; | |||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | 3 | ▶ | sub _req { | ||||||||||||||||||||||||||
|
Subroutine
_req: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 166 | 3 | my $requires = CPAN::Meta::Requirements->new; | |||||||||||||||||||||||||||
| 167 | 3 | $requires->add_string_requirement(@_); | |||||||||||||||||||||||||||
| 168 | 3 | $requires; | |||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | 60 | ▶ | sub _merge { | ||||||||||||||||||||||||||
|
Subroutine
_merge: called CC=6 SCAR=18.2
| |||||||||||||||||||||||||||||
| 172 | 60 | my ($params, $requires, $key) = @_; | |||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | 60 | ▶ | return unless $key && $requires; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$key and $requires
MC/DC0%0/2
$key and $requires
$key
$requires
Truth table33%1/3
A and B
A= $keyB= $requires
| |||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | 60 | ▶ | for my $module (keys %{ $params->{$key} || {} }) { | ||||||||||||||||||||||||||
|
Condition100%2/2
$params->{$key} || {}
MC/DC100%1/1
$params->{$key} || {}
$params->{$key}
Truth table100%2/2
A
A= $params->{$key}
| |||||||||||||||||||||||||||||
| 177 | 5 | $requires->add_string_requirement($module => $params->{$key}{$module}); | |||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||
| 179 | 60 | my $new_hash = $requires->as_string_hash; | |||||||||||||||||||||||||||
| 180 | 60 | ▶ | return unless %$new_hash; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | 16 | $params->{$key} = $new_hash; | |||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | 4 | 1; | |||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | __END__ | ||||||||||||||||||||||||||||