lib/Gentoo/Util/VirtualDepend.pm

filter: Statementstmt 84.4% 92 / 109 Branchbran 57.4% 31 / 54 Conditioncond 66.6% 4 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 73.9% 17 / 23 Podpod 100% 11 / 11 totaltotal 74.8% 155 / 207 SCAR 38.2
CC
31
Cov
75%
module_is_perl
13.1
get_dists_in_gentoo_package
12.0
get_modules_in_gentoo_package
12.0
CRAP 45.8
« blib/lib/Gentoo/Util/VirtualDepend.pm ↑ Summary
1 4 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package Gentoo::Util::VirtualDepend;
6  
7 4 our $VERSION = '0.003021';
8  
9 # ABSTRACT: Hard-coded replacements for perl-core/ dependencies and dependencies with odd names in Gentoo
10  
11 4 our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY
12  
13 4 ▶use Moo qw( has );
Subroutine BEGIN: called CC=1 SCAR=0.0
14 4 ▶use Path::Tiny qw( path );
Subroutine BEGIN: called CC=1 SCAR=0.0
15 4 ▶use File::ShareDir qw( dist_file );
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 # Note: this should be the version default max_perl is in
18 4 ▶use Module::CoreList 5.20151213;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29 # Note: This should be the latest visible version in portage at time of release
30 1 ▶has max_perl => ( is => 'ro', lazy => 1, default => sub { '5.22.1' } );
Subroutine __ANON__: called CC=1 SCAR=0.0
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41 # Note: This should be the lowest visible version 12 months prior to the time of release
42 1 ▶has min_perl => ( is => 'ro', lazy => 1, default => sub { '5.18.2' } );
Subroutine __ANON__: called CC=1 SCAR=0.0
43  
44 4 my %MOD2GENTOO;
45 my $MOD2GENTOO_LOADED;
46 4 my $MOD2GENTOO_FILE = 'module-to-gentoo.csv';
47  
48 4 my %DIST2GENTOO;
49 my $DIST2GENTOO_LOADED;
50 4 my $DIST2GENTOO_FILE = 'dist-to-gentoo.csv';
51  
52 4 my %GENTOO2DIST;
53 my %GENTOO2MOD;
54  
55 4 my $DIST = q[Gentoo-Util-VirtualDepend];
56  
57 sub _load_mod2gentoo {
58 3 ▶ return if $MOD2GENTOO_LOADED;
Subroutine _load_mod2gentoo: called CC=4 SCAR=13.9
Branch: 1 branch
BranchTrueFalseTotal
if $MOD2GENTOO_LOADED 0 3 3
59 3 my $fh = path( dist_file( $DIST, $MOD2GENTOO_FILE ) )->openr_raw;
60 3 ▶ while ( my $line = <$fh> ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $fh)) 6930 3 6933
61 6930 chomp $line;
62 6930 my ( $module, $map ) = split /,/, $line; ## no critic (RegularExpressions)
63 6930 $MOD2GENTOO{$module} = $map;
64 6930 ▶ $GENTOO2MOD{$map} = [] unless exists $GENTOO2MOD{$map};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $GENTOO2MOD{$map} 354 6576 6930
65 6930 push @{ $GENTOO2MOD{$map} }, $module;
66 }
67 3 return $MOD2GENTOO_LOADED = 1;
68 }
69  
70 sub _load_dist2gentoo {
71 1 ▶ return if $DIST2GENTOO_LOADED;
Subroutine _load_dist2gentoo: called CC=4 SCAR=13.9
Branch: 1 branch
BranchTrueFalseTotal
if $DIST2GENTOO_LOADED 0 1 1
72 1 my $fh = path( dist_file( $DIST, $DIST2GENTOO_FILE ) )->openr_raw;
73 1 ▶ while ( my $line = <$fh> ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $fh)) 121 1 122
74 121 chomp $line;
75 121 my ( $module, $map ) = split /,/, $line; ## no critic (RegularExpressions)
76 121 $DIST2GENTOO{$module} = $map;
77 121 ▶ $GENTOO2DIST{$map} = [] unless exists $GENTOO2DIST{$map};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $GENTOO2DIST{$map} 121 0 121
78 121 push @{ $GENTOO2DIST{$map} }, $module;
79 }
80 1 return $DIST2GENTOO_LOADED = 1;
81 }
82  
83 sub has_module_override {
84 189 ▶ my ( undef, $module ) = @_;
Subroutine has_module_override: called CC=2 SCAR=6.9
Pod documented
85 189 ▶ _load_mod2gentoo unless $MOD2GENTOO_LOADED;
Branch: 1 branch
BranchTrueFalseTotal
unless $MOD2GENTOO_LOADED 3 186 189
86 189 return exists $MOD2GENTOO{$module};
87 }
88  
89 sub get_module_override {
90 30 ▶ my ( undef, $module ) = @_;
Subroutine get_module_override: called CC=2 SCAR=7.1
Pod documented
91 30 ▶ _load_mod2gentoo unless $MOD2GENTOO_LOADED;
Branch: 1 branch
BranchTrueFalseTotal
unless $MOD2GENTOO_LOADED 0 30 30
92 30 return $MOD2GENTOO{$module};
93 }
94  
95 sub has_dist_override {
96 2 ▶ my ( undef, $dist ) = @_;
Subroutine has_dist_override: called CC=2 SCAR=6.9
Pod documented
97 2 ▶ _load_dist2gentoo unless $DIST2GENTOO_LOADED;
Branch: 1 branch
BranchTrueFalseTotal
unless $DIST2GENTOO_LOADED 1 1 2
98 2 return exists $DIST2GENTOO{$dist};
99 }
100  
101 sub get_dist_override {
102 1 ▶ my ( undef, $dist ) = @_;
Subroutine get_dist_override: called CC=2 SCAR=7.1
Pod documented
103 1 ▶ _load_mod2gentoo unless $DIST2GENTOO_LOADED;
Branch: 1 branch
BranchTrueFalseTotal
unless $DIST2GENTOO_LOADED 0 1 1
104 1 return $DIST2GENTOO{$dist};
105 }
106  
107 sub has_gentoo_package {
108 0 ▶ my ( undef, $package ) = @_;
Subroutine has_gentoo_package: not called CC=2 SCAR=17.9
Pod documented
109 0 ▶ _load_dist2gentoo unless $DIST2GENTOO_LOADED;
Branch: 1 branch
BranchTrueFalseTotal
unless $DIST2GENTOO_LOADED 0 0 0
110 0 return exists $GENTOO2DIST{$package};
111 }
112  
113 sub get_dists_in_gentoo_package {
114 0 ▶ my ( undef, $package ) = @_;
Subroutine get_dists_in_gentoo_package: not called CC=3 SCAR=24.8
Pod documented
115 0 ▶ _load_dist2gentoo unless $DIST2GENTOO_LOADED;
Branch: 1 branch
BranchTrueFalseTotal
unless $DIST2GENTOO_LOADED 0 0 0
116 0 ▶ return @{ $GENTOO2DIST{$package} || [] };
Branch: 1 branch
BranchTrueFalseTotal
$GENTOO2DIST{$package} or [] 0 0 0
117 }
118  
119 sub get_modules_in_gentoo_package {
120 0 ▶ my ( undef, $package ) = @_;
Subroutine get_modules_in_gentoo_package: not called CC=3 SCAR=24.8
Pod documented
121 0 ▶ _load_mod2gentoo unless $MOD2GENTOO_LOADED;
Branch: 1 branch
BranchTrueFalseTotal
unless $MOD2GENTOO_LOADED 0 0 0
122 0 ▶ return @{ $GENTOO2MOD{$package} || [] };
Branch: 1 branch
BranchTrueFalseTotal
$GENTOO2MOD{$package} or [] 0 0 0
123 }
124  
125 sub get_known_gentoo_packages {
126 0 ▶ _load_dist2gentoo unless $DIST2GENTOO_LOADED;
Subroutine get_known_gentoo_packages: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
unless $DIST2GENTOO_LOADED 0 0 0
127 0 return keys %GENTOO2DIST;
128 }
129  
130 sub get_known_dists {
131 0 ▶ _load_dist2gentoo unless $DIST2GENTOO_LOADED;
Subroutine get_known_dists: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
unless $DIST2GENTOO_LOADED 0 0 0
132 0 return keys %DIST2GENTOO;
133 }
134  
135 sub get_known_modules {
136 0 ▶ _load_mod2gentoo unless $MOD2GENTOO_LOADED;
Subroutine get_known_modules: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
unless $MOD2GENTOO_LOADED 0 0 0
137 0 return keys %MOD2GENTOO;
138 }
139  
140 sub module_is_perl {
141 83 ▶ my ( $self, $opts, $module, $mod_version ) = @_;
Subroutine module_is_perl: called CC=13 SCAR=25.7
Pod documented
142 83 ▶ if ( not ref $opts ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $opts) 75 8 83
143 75 ( $opts, $module, $mod_version ) = ( {}, $opts, $module );
144 }
145  
146 # If the module has a virtual, don't even consider
147 # CPAN/perl decisions
148  
149 83 ▶ return if $self->has_module_override($module);
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_module_override($module) 0 83 83
150 83 require version;
151  
152 83 ▶ $opts->{min_perl} ||= $self->min_perl;
Condition66%2/3
$opts->{"min_perl"} ||= $self->min_perl
l!l&&r!l&&!r
8750
MC/DC0%0/2
$opts->{"min_perl"} ||= $self->min_perl
$opts->{"min_perl"} $self->min_perl
Truth table66%2/3
A ||= B
A= $opts->{"min_perl"}B= $self->min_perl
ABresult
1X1
011
000
153 83 my $min_perl = version->parse( $opts->{min_perl} );
154 83 ▶ $opts->{max_perl} ||= $self->max_perl;
Condition66%2/3
$opts->{"max_perl"} ||= $self->max_perl
l!l&&r!l&&!r
8750
MC/DC0%0/2
$opts->{"max_perl"} ||= $self->max_perl
$opts->{"max_perl"} $self->max_perl
Truth table66%2/3
A ||= B
A= $opts->{"max_perl"}B= $self->max_perl
ABresult
1X1
011
000
155 83 my $max_perl = version->parse( $opts->{max_perl} );
156  
157 83 my $seen;
158 ## no critic (Variables::ProhibitPackageVars)
159 83 for my $version ( keys %Module::CoreList::version ) {
160 4471 my $perlver = version->parse($version);
161 ## no critic (ControlStructures::ProhibitNegativeExpressionsInUnlessAndUntilConditions)
162 4471 ▶ next unless $perlver >= $min_perl;
Branch: 1 branch
BranchTrueFalseTotal
unless $perlver >= $min_perl 1321 3150 4471
163 3150 ▶ next unless $perlver <= $max_perl;
Branch: 1 branch
BranchTrueFalseTotal
unless $perlver <= $max_perl 2910 240 3150
164  
165 # If any version in the range returns "deprecated", then we should
166 # default to CPAN
167 240 ▶ return if $Module::CoreList::deprecated{$version}{$module};
Branch: 1 branch
BranchTrueFalseTotal
if $Module::CoreList::deprecated{$version}{$module} 3 237 240
168  
169 # If any version in the range does not exist, then we should default to CPAN
170 #
171 237 ▶ return if not exists $Module::CoreList::version{$version}{$module};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $Module::CoreList::version{$version}{$module} 72 165 237
172  
173 165 ▶ if ( not defined $mod_version ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $mod_version) 68 97 165
174 68 $seen = 1;
175 68 next;
176 }
177  
178 # If any version in the range is undef, and a specific version is requested,
179 # Default to CPAN, because it means a virtual is not provisioned.
180 97 ▶ return if not defined $Module::CoreList::version{$version}{$module};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Module::CoreList::version{$version}{$module} 0 97 97
181  
182 97 my $this_version = version->parse( $Module::CoreList::version{$version}{$module} );
183  
184 # If any version in the range is lower than required, default to CPAN
185 # because it means a virtual is not provisioned, and a breakage will occur
186 # on one of the versions.
187 97 ▶ return if $this_version < version->parse($mod_version);
Branch: 1 branch
BranchTrueFalseTotal
if $this_version < "version"->parse($mod_version) 1 96 97
188  
189 96 $seen = 1;
190 }
191 7 return $seen;
192 }
193  
194 4 ▶no Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
195  
196 4 1;
197  
198 __END__
« blib/lib/Gentoo/Util/VirtualDepend.pm ↑ Summary