blib/lib/Gentoo/Util/VirtualDepend.pm untested

filter: Statementstmt 0.0% 0 / 118 Branchbran 0.0% 0 / 46 Conditioncond 0.0% 0 / 10 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 22 Podpod 0.0% 0 / 13 totaltotal 0.0% 0 / 209 SCAR 64.0
CC
24
Cov
0%
module_is_perl
110.0
_load_mod2gentoo
12.0
_load_dist2gentoo
12.0
CRAP 600.0
1 use 5.006;
2 use strict;
3 use warnings;
4  
5 package Gentoo::Util::VirtualDepend;
6  
7 our $VERSION = '0.003021';
8  
9 # ABSTRACT: Hard-coded replacements for perl-core/ dependencies and dependencies with odd names in Gentoo
10  
11 our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY
12  
13 use Moo qw( has );
14 use Path::Tiny qw( path );
15 use File::ShareDir qw( dist_file );
16  
17 # Note: this should be the version default max_perl is in
18 use Module::CoreList 5.20151213;
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 has max_perl => ( is => 'ro', lazy => 1, default => sub { '5.22.1' } );
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 has min_perl => ( is => 'ro', lazy => 1, default => sub { '5.18.2' } );
43  
44 my %MOD2GENTOO;
45 my $MOD2GENTOO_LOADED;
46 my $MOD2GENTOO_FILE = 'module-to-gentoo.csv';
47  
48 my %DIST2GENTOO;
49 my $DIST2GENTOO_LOADED;
50 my $DIST2GENTOO_FILE = 'dist-to-gentoo.csv';
51  
52 my %GENTOO2DIST;
53 my %GENTOO2MOD;
54  
55 my $DIST = q[Gentoo-Util-VirtualDepend];
56  
57 sub _load_mod2gentoo {
58 return if $MOD2GENTOO_LOADED;
59 my $fh = path( dist_file( $DIST, $MOD2GENTOO_FILE ) )->openr_raw;
60 while ( my $line = <$fh> ) {
61 chomp $line;
62 my ( $module, $map ) = split /,/, $line; ## no critic (RegularExpressions)
63 $MOD2GENTOO{$module} = $map;
64 $GENTOO2MOD{$map} = [] unless exists $GENTOO2MOD{$map};
65 push @{ $GENTOO2MOD{$map} }, $module;
66 }
67 return $MOD2GENTOO_LOADED = 1;
68 }
69  
70 sub _load_dist2gentoo {
71 return if $DIST2GENTOO_LOADED;
72 my $fh = path( dist_file( $DIST, $DIST2GENTOO_FILE ) )->openr_raw;
73 while ( my $line = <$fh> ) {
74 chomp $line;
75 my ( $module, $map ) = split /,/, $line; ## no critic (RegularExpressions)
76 $DIST2GENTOO{$module} = $map;
77 $GENTOO2DIST{$map} = [] unless exists $GENTOO2DIST{$map};
78 push @{ $GENTOO2DIST{$map} }, $module;
79 }
80 return $DIST2GENTOO_LOADED = 1;
81 }
82  
83 sub has_module_override {
84 my ( undef, $module ) = @_;
85 _load_mod2gentoo unless $MOD2GENTOO_LOADED;
86 return exists $MOD2GENTOO{$module};
87 }
88  
89 sub get_module_override {
90 my ( undef, $module ) = @_;
91 _load_mod2gentoo unless $MOD2GENTOO_LOADED;
92 return $MOD2GENTOO{$module};
93 }
94  
95 sub has_dist_override {
96 my ( undef, $dist ) = @_;
97 _load_dist2gentoo unless $DIST2GENTOO_LOADED;
98 return exists $DIST2GENTOO{$dist};
99 }
100  
101 sub get_dist_override {
102 my ( undef, $dist ) = @_;
103 _load_mod2gentoo unless $DIST2GENTOO_LOADED;
104 return $DIST2GENTOO{$dist};
105 }
106  
107 sub has_gentoo_package {
108 my ( undef, $package ) = @_;
109 _load_dist2gentoo unless $DIST2GENTOO_LOADED;
110 return exists $GENTOO2DIST{$package};
111 }
112  
113 sub get_dists_in_gentoo_package {
114 my ( undef, $package ) = @_;
115 _load_dist2gentoo unless $DIST2GENTOO_LOADED;
116 return @{ $GENTOO2DIST{$package} || [] };
117 }
118  
119 sub get_modules_in_gentoo_package {
120 my ( undef, $package ) = @_;
121 _load_mod2gentoo unless $MOD2GENTOO_LOADED;
122 return @{ $GENTOO2MOD{$package} || [] };
123 }
124  
125 sub get_known_gentoo_packages {
126 _load_dist2gentoo unless $DIST2GENTOO_LOADED;
127 return keys %GENTOO2DIST;
128 }
129  
130 sub get_known_dists {
131 _load_dist2gentoo unless $DIST2GENTOO_LOADED;
132 return keys %DIST2GENTOO;
133 }
134  
135 sub get_known_modules {
136 _load_mod2gentoo unless $MOD2GENTOO_LOADED;
137 return keys %MOD2GENTOO;
138 }
139  
140 sub module_is_perl {
141 my ( $self, $opts, $module, $mod_version ) = @_;
142 if ( not ref $opts ) {
143 ( $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 return if $self->has_module_override($module);
150 require version;
151  
152 $opts->{min_perl} ||= $self->min_perl;
153 my $min_perl = version->parse( $opts->{min_perl} );
154 $opts->{max_perl} ||= $self->max_perl;
155 my $max_perl = version->parse( $opts->{max_perl} );
156  
157 my $seen;
158 ## no critic (Variables::ProhibitPackageVars)
159 for my $version ( keys %Module::CoreList::version ) {
160 my $perlver = version->parse($version);
161 ## no critic (ControlStructures::ProhibitNegativeExpressionsInUnlessAndUntilConditions)
162 next unless $perlver >= $min_perl;
163 next unless $perlver <= $max_perl;
164  
165 # If any version in the range returns "deprecated", then we should
166 # default to CPAN
167 return if $Module::CoreList::deprecated{$version}{$module};
168  
169 # If any version in the range does not exist, then we should default to CPAN
170 #
171 return if not exists $Module::CoreList::version{$version}{$module};
172  
173 if ( not defined $mod_version ) {
174 $seen = 1;
175 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 return if not defined $Module::CoreList::version{$version}{$module};
181  
182 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 return if $this_version < version->parse($mod_version);
188  
189 $seen = 1;
190 }
191 return $seen;
192 }
193  
194 no Moo;
195  
196 1;
197  
198 __END__