blib/lib/CPAN/Meta/Prereqs/Filter.pm

filter: Statementstmt 77.4% 55 / 71 Branchbran 57.8% 22 / 38 Conditioncond 20.0% 1 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 100% 7 / 7 Podpod 100% 1 / 1 totaltotal 68.8% 86 / 125 SCAR 41.6
CC
32
Cov
68%
filter_prereqs
67.9
_normalize_version
6.4
BEGIN
1.0
CRAP 64.2
↑ Summary
1 package CPAN::Meta::Prereqs::Filter;
2 1 $CPAN::Meta::Prereqs::Filter::VERSION = '0.006';
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  
6 1 ▶use Exporter 5.57 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 our @EXPORT_OK = qw/filter_prereqs/;
8  
9 1 ▶use Carp 'croak';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Scalar::Util 'isvstring';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 my @phases = qw/configure build test runtime develop/;
13 1 my @relationships = qw/requires recommends suggests/;
14  
15 1 my %dependents_for = (
16 configure => [ qw/build test develop/ ],
17 runtime => [ qw/build test develop/ ],
18 build => [ qw/test develop/ ],
19 test => [ qw/develop/ ],
20 );
21  
22 sub _normalize_version {
23 1 ▶ my $raw = shift;
Subroutine _normalize_version: called CC=4 SCAR=18.6
24 1 ▶ if (isvstring($raw)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&isvstring($raw)) 0 1 1
25 0 $raw = sprintf 'v%vd', $raw;
26 }
27 1 ▶ if ($raw =~ / \A v5 (?> \. \d+)* \z /x) {
Branch: 2 branches
BranchTrueFalseTotal
if ($raw =~ / \A v5 (?> \. \d+)* \z /x) { } 0 1 1
elsif ($raw eq 'latest') { } 0 1 1
28 0 require version;
29 0 return sprintf '%7.6f', version->new($raw)->numify;
30 }
31 elsif ($raw eq 'latest') {
32 0 require Module::CoreList;
33 0 return (reverse sort keys %Module::CoreList::version)[0];
34 }
35 1 return sprintf '%7.6f', $raw;
36 }
37  
38 sub filter_prereqs {
39 3 ▶ my ($prereqs, %args) = @_;
Subroutine filter_prereqs: called CC=29 SCAR=42.2
Pod documented
40 3 ▶ return $prereqs if not grep { $_ } values %args;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_;} values %args 0 3 3
41 3 $prereqs = $prereqs->clone;
42 3 ▶ my $core_version = defined $args{omit_core} ? _normalize_version($args{omit_core}) : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $args{'omit_core'} ? : 1 2 3
43 3 ▶ if ($core_version) {
Branch: 1 branch
BranchTrueFalseTotal
if ($core_version) 1 2 3
44 1 require Module::CoreList;
45 1 ▶ croak "$core_version is not a known perl version" if not exists $Module::CoreList::version{$core_version};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $Module::CoreList::version{$core_version} 0 1 1
46 1 for my $phase (@phases) {
47 5 for my $relation (@relationships) {
48 15 my $req = $prereqs->requirements_for($phase, $relation);
49  
50 15 ▶ $req->clear_requirement('perl') if $req->accepts_module('perl', $core_version);
Branch: 1 branch
BranchTrueFalseTotal
if $req->accepts_module("perl", $core_version) 15 0 15
51 15 for my $module ($req->required_modules) {
52 2 ▶ next if not exists $Module::CoreList::version{$core_version}{$module};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $Module::CoreList::version{$core_version}{$module} 1 1 2
53 1 ▶ next if not $req->accepts_module($module, $Module::CoreList::version{$core_version}{$module});
Branch: 1 branch
BranchTrueFalseTotal
unless $req->accepts_module($module, $Module::CoreList::version{$core_version}{$module}) 0 1 1
54 1 ▶ next if Module::CoreList->is_deprecated($module, $core_version);
Branch: 1 branch
BranchTrueFalseTotal
if "Module::CoreList"->is_deprecated($module, $core_version) 0 1 1
55 1 $req->clear_requirement($module);
56 }
57 }
58 }
59 }
60 3 ▶ if ($args{sanitize}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"sanitize"}) 0 3 3
61 0 for my $parent (qw/runtime configure build/) {
62 0 for my $child ( @{ $dependents_for{$parent} } ) {
63 0 for my $relationship (@relationships) {
64 0 my $source = $prereqs->requirements_for($parent, $relationship);
65 0 my $sink = $prereqs->requirements_for($child, $relationship);
66 0 for my $module ($source->required_modules) {
67 0 ▶ next if not defined(my $right = $sink->requirements_for_module($module));
Branch: 1 branch
BranchTrueFalseTotal
unless defined(my $right = $sink->requirements_for_module($module)) 0 0 0
68 0 my $left = $source->requirements_for_module($module);
69 0 ▶ $sink->clear_requirement($module) if $left ge $right;
Branch: 1 branch
BranchTrueFalseTotal
if $left ge $right 0 0 0
70 }
71 }
72 }
73 }
74 }
75 3 ▶ if ($args{only_missing}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"only_missing"}) 1 2 3
76 1 require Module::Metadata;
77 1 for my $phase (@phases) {
78 5 for my $relation (@relationships) {
79 15 my $req = $prereqs->requirements_for($phase, $relation);
80 15 ▶ $req->clear_requirement('perl') if $req->accepts_module('perl', $]);
Branch: 1 branch
BranchTrueFalseTotal
if $req->accepts_module("perl", $]) 15 0 15
81 15 for my $module ($req->required_modules) {
82 3 ▶ if ($req->requirements_for_module($module)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->requirements_for_module($module)) { } 1 2 3
83 1 my $metadata = Module::Metadata->new_from_module($module);
84 1 ▶ if ($metadata && $req->accepts_module($module, $metadata->version($module) || 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($metadata and $req->accepts_module($module, $metadata->version($module) || 0)) 0 1 1
Condition20%1/5
$metadata and $req->accepts_module($module, $metadata->version($module) || 0)
!ll&&!rl&&r
100
$metadata->version($module) || 0
l!l
00
MC/DC0%0/2
$metadata and $req->accepts_module($module, $metadata->version($module) || 0)
$metadata $req->accepts_module($module, $metadata->version($module) || 0)
MC/DC0%0/1
$metadata->version($module) || 0
$metadata->version($module)
Truth table33%1/3
A and B
A= $metadataB= $req->accepts_module($module, $metadata->version($module) || 0)
ABresult
0X0
100
111
Truth table0%0/2
A
A= $metadata->version($module)
Aresult
11
00
85 0 $req->clear_requirement($module);
86 }
87 }
88 else {
89 2 ▶ $req->clear_requirement($module) if Module::Metadata->find_module_by_name($module);
Branch: 1 branch
BranchTrueFalseTotal
if "Module::Metadata"->find_module_by_name($module) 2 0 2
90 }
91 }
92 }
93 }
94 }
95 3 return $prereqs;
96 }
97  
98 1 1;
99  
100 # ABSTRACT: Filtering various things out of CPAN::Meta::Prereqs
101  
102 __END__
↑ Summary