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