cpan2arch/CheckPackages.pm

filter: Statementstmt 6.5% 26 / 395 Branchbran 0.0% 0 / 206 Conditioncond 0.0% 0 / 78 MC/DCmcdc 0.0% 0 / 51 Subroutinesub 24.0% 6 / 25 Podpod 33.3% 1 / 3 totaltotal 4.3% 33 / 758 CC 148 SCAR 85.9
CC
148
Cov
4%
_preproc_prereqs
9506.0
_postproc_prereqs
210.0
is_aur_pkg
156.0
CRAP 5399.0
↑ Summary cpan2arch/WritePkgbuild.pm »
1 1 ▶use v5.42.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
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 ▶no source::encoding; # Avoid dying on v5.42.0 (non-ASCII char in POD).
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use Object::Pad 0.825;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 package App::cpan2arch::CheckPackages; # For toolchain compatibility.
10 role App::cpan2arch::CheckPackages;
11  
12 1 ▶use List::Util qw< any uniq >;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 our $VERSION = 'v1.1.2';
15  
16 1 field $_mua_arch;
17 0 ▶field %_arch_prereqs :reader :writer;
Subroutine arch_prereqs: not called CC=1 SCAR=4.1
Subroutine set_arch_prereqs: not called CC=1 SCAR=4.1
Pod undocumented
Pod undocumented
18  
19 # Check whether prerequisite dists exist as packages in Arch's Official/AUR repos
20 # and build PKGBUILD data.
21 #
22 # References:
23 # https://wiki.archlinux.org/title/Official_repositories_web_interface
24 # https://wiki.archlinux.org/title/Aurweb_RPC_interface
25 0 ▶method check_packages ()
Subroutine check_packages: not called CC=10 SCAR=47.0
Pod documented
26 {
27 0 $self->_psub;
28  
29 0 $self->_init_mua_arch;
30  
31 # Query Arch's perl pkg and Official + AUR Perl pkgs in bulk.
32 0 my $perl;
33 0 my %pkgs = (
34 official => undef,
35 aur => undef,
36 );
37 {
38 0 my %QUERIES = (
39 perl => 'https://archlinux.org/packages/core/x86_64/perl/json/',
40 official => 'https://archlinux.org/packages/search/json/?q=perl-&repo=Core&repo=Extra',
41 aur => 'https://aur.archlinux.org/rpc/v5/search/perl-?by=name',
42 );
43  
44 0 my %json = (
45 perl => undef,
46 official => undef,
47 aur => undef,
48 );
49  
50 0 foreach my $q ( keys %QUERIES ) {
51 0 $self->_pdump( '$q', \$q, "\n" );
52  
53 0 $json{$q} = $self->_get_json( $QUERIES{$q} );
54 0 ▶ return 1 if $json{$q} == 1;
Branch: 1 branch
BranchTrueFalseTotal
if $json{$q} == 1 0 0 0
55  
56 0 ▶ if ( $q eq 'perl' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($q eq 'perl') { } 0 0 0
elsif ($q eq 'official') { } 0 0 0
elsif ($q eq 'aur') { } 0 0 0
57 0 $perl = $json{perl};
58 }
59 elsif ( $q eq 'official' ) {
60 0 $pkgs{official} = [ $json{official}{results}->@* ];
61  
62 0 foreach my $page ( 2 .. $json{official}{num_pages} ) {
63 0 my $url = $QUERIES{official} . "&page=$page";
64  
65 0 my $j = $self->_get_json($url);
66 0 ▶ return 1 if $j == 1;
Branch: 1 branch
BranchTrueFalseTotal
if $j == 1 0 0 0
67  
68 0 push $pkgs{official}->@*, $j->{results}->@*;
69 }
70 }
71 elsif ( $q eq 'aur' ) {
72 0 $pkgs{aur} = [ $json{aur}{results}->@* ];
73 }
74 }
75  
76 #$self->_pdump('$perl', \$perl, '');
77 #$self->_pdump('%pkgs', \%pkgs, "\n");
78 }
79  
80 0 my $core_modules = $self->_get_corelist( $perl->{pkgver} );
81 0 ▶ return 1 if $core_modules == 1;
Branch: 1 branch
BranchTrueFalseTotal
if $core_modules == 1 0 0 0
82  
83 0 my $prereqs = $self->_preproc_prereqs( $core_modules, $perl, %pkgs );
84 0 ▶ return 1 if $prereqs == 1;
Branch: 1 branch
BranchTrueFalseTotal
if $prereqs == 1 0 0 0
85  
86 0 $self->_postproc_prereqs( $prereqs->%* );
87  
88 0 return 0;
89 1 }
90  
91 # Pre-process prerequisites while checking for Arch packages.
92 0 ▶method _preproc_prereqs ( $core_modules, $perl, %pkgs )
Subroutine _preproc_prereqs: not called CC=97 SCAR=91.6
93 {
94 0 $self->_psub;
95  
96 0 my %cpan_prereqs = $self->cpan_prereqs;
97 0 my %prereqs;
98 my %seen_pkgs;
99  
100 # Regexes to validate Perl pkgs in Official/AUR repos.
101 0 my %RE = (
102 words => qr{\b(?> Perl | CPAN )\b}ix,
103 url => qr{\Ahttps?://(?> search\.m? | meta)cpan\.org/}x,
104 license => qr{(?> Perl | Artistic )}x,
105 name => qr{(?> \Aperl- | \Aperl\z )}x,
106 );
107  
108 0 ▶ my sub build_pkgnames ($p)
Subroutine build_pkgnames: not called CC=1 SCAR=6.9
109 {
110 # Some packages do not prepend the perl prefix or exclude 'app-' (e.g. ack,
111 # perl-tidy, jq-lite, cpanminus, perlbrew), so include them in the search.
112 return (
113 0 "perl-$p",
114 "perl-$p" =~ tr{_}{-}r,
115 $p =~ tr{_}{-}r,
116 $p =~ s{\Aapp-}{}r,
117 $p,
118 );
119 }
120  
121 0 ▶ my sub is_official_pkg ($res)
Subroutine is_official_pkg: not called CC=5 SCAR=34.0
122 {
123 my @vars = (
124 $res->{depends}->@*,
125 $res->{makedepends}->@*,
126 $res->{checkdepends}->@*,
127 $res->{optdepends}->@*,
128 $res->{provides}->@*,
129 0 );
130  
131 return
132 $res->{pkgdesc} =~ $RE{words} ? true
133 : $res->{url} =~ $RE{url} ? true
134 0 ▶ : ( any { $_ =~ $RE{name} } @vars ) ? true
Subroutine __ANON__: not called CC=1 SCAR=6.9
135 0 ▶ : ( any { $_ =~ $RE{license} } $res->{licenses}->@* ) ? true
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 4 branches
BranchTrueFalseTotal
$res->{'pkgdesc'} =~ /$RE{'words'}/u ? : 0 0 0
$res->{'url'} =~ /$RE{'url'}/u ? : 0 0 0
&any(sub { $_ =~ /$RE{'name'}/u; } , @vars) ? : 0 0 0
&any(sub { $_ =~ /$RE{'license'}/u; } , @{$$res{'licenses'}}) ? : 0 0 0
136 : false;
137 }
138  
139 0 ▶ my sub is_aur_pkg ($res)
Subroutine is_aur_pkg: not called CC=12 SCAR=50.5
140 {
141 0 ▶ my $desc = $res->{Description} // '';
Condition0%0/2
$res->{"Description"} // ""
l!l
00
MC/DC0%0/1
$res->{"Description"} // ""
$res->{"Description"}
Truth table0%0/2
A
A= $res->{"Description"}
Aresult
11
00
142 0 ▶ my $url = $res->{URL} // '';
Condition0%0/2
$res->{"URL"} // ""
l!l
00
MC/DC0%0/1
$res->{"URL"} // ""
$res->{"URL"}
Truth table0%0/2
A
A= $res->{"URL"}
Aresult
11
00
143 0 my @kwords;
144 my @license;
145 0 my @vars;
146  
147 0 my @PKG_VARS = (
148 qw<
149 Depends
150 MakeDepends
151 CheckDepends
152 OptDepends
153 Provides
154 >
155 );
156  
157 0 foreach my $var (@PKG_VARS) {
158 0 ▶ push @vars, $res->{$var}->@* if defined $res->{$var};
Branch: 1 branch
BranchTrueFalseTotal
if defined $res->{$var} 0 0 0
159 }
160 0 ▶ push @license, $res->{License}->@* if defined $res->{License};
Branch: 1 branch
BranchTrueFalseTotal
if defined $res->{"License"} 0 0 0
161 0 ▶ push @kwords, $res->{Keywords}->@* if defined $res->{Keywords};
Branch: 1 branch
BranchTrueFalseTotal
if defined $res->{"Keywords"} 0 0 0
162  
163 return
164 0 ▶ ( any { $_ =~ $RE{words} } @kwords ) ? true
Subroutine __ANON__: not called CC=1 SCAR=6.9
165 : $desc =~ $RE{words} ? true
166 : $url =~ $RE{url} ? true
167 0 ▶ : ( any { $_ =~ $RE{name} } @vars ) ? true
Subroutine __ANON__: not called CC=1 SCAR=6.9
168 0 ▶ : ( any { $_ =~ $RE{license} } @license ) ? true
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 5 branches
BranchTrueFalseTotal
&any(sub { $_ =~ /$RE{'words'}/u; } , @kwords) ? : 0 0 0
$desc =~ /$RE{'words'}/u ? : 0 0 0
$url =~ /$RE{'url'}/u ? : 0 0 0
&any(sub { $_ =~ /$RE{'name'}/u; } , @vars) ? : 0 0 0
&any(sub { $_ =~ /$RE{'license'}/u; } , @license) ? : 0 0 0
169 : false;
170 }
171  
172 # NOTE:
173 # Sort keys to ensure 'depends' runs before makedepends for correct deduplication.
174 0 foreach my $var ( sort keys %cpan_prereqs ) {
175 0 my $deps = $cpan_prereqs{$var};
176 0 ▶ next unless defined $deps;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $deps 0 0 0
177  
178 0 foreach my ( $module, $info ) ( $deps->%* ) {
179 0 my ( $dist, $version, $failed ) = $info->@{ qw< dist version failed > };
180  
181 0 $self->_pdump( '$var', \$var, '' );
182 0 $self->_pdump( '$module', \$module, '' );
183  
184 0 ▶ if ( $module eq 'perl' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($module eq 'perl') { } 0 0 0
elsif (exists $core_modules->{$module}) { } 0 0 0
185 # Convert perl version to an Arch perl package version.
186 0 ▶ $version = version->parse($version)->to_dotted_decimal =~ s{\Av}{}r
Branch: 1 branch
BranchTrueFalseTotal
if $version ne 0 0 0 0
187 if $version ne '0';
188  
189 # Skip duplicated perl in makedepends, but get the lesser version.
190 0 ▶ if ( $var eq 'makedepends' && exists $prereqs{depends}{perl} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($var eq "makedepends" and exists $prereqs{"depends"}{"perl"}) 0 0 0
Condition0%0/3
$var eq "makedepends" and exists $prereqs{"depends"}{"perl"}
!ll&&!rl&&r
000
MC/DC0%0/2
$var eq "makedepends" and exists $prereqs{"depends"}{"perl"}
$var eq "makedepends" exists $prereqs{"depends"}{"perl"}
Truth table0%0/3
A and B
A= $var eq "makedepends"B= exists $prereqs{"depends"}{"perl"}
ABresult
0X0
100
111
191 0 $self->_pdbg("perl already in depends\n");
192  
193 0 my $ret = $self->_comp_vers( $version, $prereqs{depends}{perl}{version}, '<=' );
194 0 ▶ return 1 if defined $ret && $ret == 1;
Branch: 1 branch
BranchTrueFalseTotal
if defined $ret and $ret == 1 0 0 0
Condition0%0/3
defined $ret and $ret == 1
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ret and $ret == 1
defined $ret $ret == 1
Truth table0%0/3
A and B
A= defined $retB= $ret == 1
ABresult
0X0
100
111
195  
196 0 ▶ $prereqs{depends}{perl}{version} = $version
Branch: 1 branch
BranchTrueFalseTotal
if defined $ret and $ret == 0 0 0 0
Condition0%0/3
defined $ret and $ret == 0
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ret and $ret == 0
defined $ret $ret == 0
Truth table0%0/3
A and B
A= defined $retB= $ret == 0
ABresult
0X0
100
111
197 if defined $ret && $ret == 0;
198  
199 0 next;
200 }
201  
202 $prereqs{$var}{perl} = {
203 version => $version,
204 0 flag_date => _fmt_date( $perl->{flag_date}, 'official' ),
205 };
206  
207 0 $self->_pdbg("\n\n");
208 0 next;
209 }
210 # Core module
211 elsif ( exists $core_modules->{$module} ) {
212 0 $self->_pdbg("$module is a core module\n");
213  
214 0 ▶ if ( defined $failed ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $failed) 0 0 0
215 0 $prereqs{$var}{$module} = {
216 failed => true,
217 version => $version,
218 };
219  
220 0 $self->_pdbg("failed module\n");
221 0 $self->_pdbg("\n\n");
222  
223 0 next;
224 }
225  
226 0 $self->_pdump( '$dist', \$dist, '' );
227  
228 0 ▶ if ( $dist eq 'perl' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dist eq "perl") 0 0 0
229 0 $self->_pdbg("\n\n");
230 0 next;
231 }
232  
233 # Dual-life dist
234 0 $self->_pdbg("$dist is dual lifed\n");
235  
236 0 my $pkg = lc "perl-$dist";
237  
238 # Skip duplicated variable distros but get the lesser version.
239 0 ▶ if ( exists $prereqs{$var}{$pkg} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $prereqs{$var}{$pkg}) 0 0 0
240 0 $self->_pdbg("found var dist dupe; skip\n");
241  
242 0 my $ret = $self->_comp_vers( $version, $prereqs{$var}{$pkg}{version}, '<=' );
243 0 ▶ return 1 if defined $ret && $ret == 1;
Branch: 1 branch
BranchTrueFalseTotal
if defined $ret and $ret == 1 0 0 0
Condition0%0/3
defined $ret and $ret == 1
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ret and $ret == 1
defined $ret $ret == 1
Truth table0%0/3
A and B
A= defined $retB= $ret == 1
ABresult
0X0
100
111
244  
245 0 ▶ $prereqs{$var}{$pkg}{version} = $version
Branch: 1 branch
BranchTrueFalseTotal
if defined $ret and $ret == 0 0 0 0
Condition0%0/3
defined $ret and $ret == 0
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ret and $ret == 0
defined $ret $ret == 0
Truth table0%0/3
A and B
A= defined $retB= $ret == 0
ABresult
0X0
100
111
246 if defined $ret && $ret == 0;
247  
248 0 next;
249 }
250  
251 # Skip duplicated package in makedepends, but get the lesser version.
252 0 ▶ if ( $var eq 'makedepends' && exists $prereqs{depends}{$pkg} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($var eq "makedepends" and exists $prereqs{"depends"}{$pkg}) 0 0 0
Condition0%0/3
$var eq "makedepends" and exists $prereqs{"depends"}{$pkg}
!ll&&!rl&&r
000
MC/DC0%0/2
$var eq "makedepends" and exists $prereqs{"depends"}{$pkg}
$var eq "makedepends" exists $prereqs{"depends"}{$pkg}
Truth table0%0/3
A and B
A= $var eq "makedepends"B= exists $prereqs{"depends"}{$pkg}
ABresult
0X0
100
111
253 0 $self->_pdbg("$pkg already in depends\n");
254  
255 0 my $ret = $self->_comp_vers( $version, $prereqs{depends}{$pkg}{version}, '<=' );
256 0 ▶ return 1 if defined $ret && $ret == 1;
Branch: 1 branch
BranchTrueFalseTotal
if defined $ret and $ret == 1 0 0 0
Condition0%0/3
defined $ret and $ret == 1
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ret and $ret == 1
defined $ret $ret == 1
Truth table0%0/3
A and B
A= defined $retB= $ret == 1
ABresult
0X0
100
111
257  
258 0 ▶ $prereqs{depends}{$pkg}{version} = $version
Branch: 1 branch
BranchTrueFalseTotal
if defined $ret and $ret == 0 0 0 0
Condition0%0/3
defined $ret and $ret == 0
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ret and $ret == 0
defined $ret $ret == 0
Truth table0%0/3
A and B
A= defined $retB= $ret == 0
ABresult
0X0
100
111
259 if defined $ret && $ret == 0;
260  
261 0 next;
262 }
263  
264 0 ▶ if ( exists $seen_pkgs{$pkg} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $seen_pkgs{$pkg}) 0 0 0
265 0 $prereqs{$var}{$pkg}{version} = $version;
266 0 ▶ $prereqs{$var}{$pkg}{module} = $module if $var eq 'optdepends';
Branch: 1 branch
BranchTrueFalseTotal
if $var eq "optdepends" 0 0 0
267  
268 0 $self->_pdbg("found pkg provides dupe; skip\n");
269 0 $self->_pdbg("\n\n");
270  
271 0 next;
272 }
273  
274 # Dist exists in the perl package provides array.
275 0 ▶ if ( any { /\A \Q$pkg\E (?> = [0-9._]+ )?\z/x } $perl->{provides}->@* ) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if (&any(sub { /\A \Q$pkg\E (?> = [0-9._]+ )?\z/ux; } , @{$$perl{"provides"}})) 0 0 0
276 0 $prereqs{$var}{$pkg}{version} = $version;
277 0 ▶ $prereqs{$var}{$pkg}{module} = $module if $var eq 'optdepends';
Branch: 1 branch
BranchTrueFalseTotal
if $var eq "optdepends" 0 0 0
278 0 $seen_pkgs{$pkg} = {};
279  
280 0 $self->_pdbg("found $pkg in provides\n");
281 }
282  
283 0 $self->_pdbg("\n\n");
284 0 next;
285 }
286 # Non-core CPAN module
287 else {
288 0 my $mod = $module;
289  
290 0 $self->_pdbg("$mod is NOT a core module\n");
291  
292 0 ▶ if ( defined $failed ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $failed) 0 0 0
293 0 $prereqs{$var}{$module} = {
294 failed => true,
295 version => $version,
296 };
297  
298 0 $self->_pdbg("failed module\n");
299 0 $self->_pdbg("\n\n");
300  
301 0 next;
302 }
303  
304 0 $self->_pdump( '$dist', \$dist, '' );
305  
306 # Some packages incorrectly use the module name as package name,
307 # (e.g. perl-term-readkey) so search for module names in addition
308 # to dist names.
309 0 my @pkgs;
310 {
311 0 $dist = lc $dist;
312 0 $mod = lc $mod =~ s{::}{-}gr;
313  
314 0 @pkgs = build_pkgnames($dist);
315 0 ▶ push @pkgs, build_pkgnames($mod) if $mod ne $dist;
Branch: 1 branch
BranchTrueFalseTotal
if $mod ne $dist 0 0 0
316  
317 # Hardcode packages that use their own convention, as last resort.
318 0 my %ODD_PKGS = (
319 'libwww-perl' => 'perl-libwww',
320 cairo => 'cairo-perl',
321 glib => 'glib-perl',
322 gtk2 => 'gtk2-perl',
323 pango => 'pango-perl',
324 );
325 0 ▶ push @pkgs, $ODD_PKGS{$dist} if exists $ODD_PKGS{$dist};
Branch: 1 branch
BranchTrueFalseTotal
if exists $ODD_PKGS{$dist} 0 0 0
326  
327 0 @pkgs = uniq @pkgs;
328 }
329  
330 0 my $prereq_pkg_dupe = false;
331  
332 # Dedupe packages.
333 0 foreach my $pkg (@pkgs) {
334 # Skip duplicated variable packages, but get the lesser version.
335 0 ▶ if ( exists $prereqs{$var}{$pkg} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $prereqs{$var}{$pkg}) { } 0 0 0
elsif ($var eq 'makedepends' and exists $prereqs{'depends'}{$pkg}) { } 0 0 0
336 0 $prereq_pkg_dupe = true;
337  
338 0 $self->_pdbg("found var pkg dupe; skip\n");
339 0 $self->_pdump( '$pkg', \$pkg, '' );
340  
341 0 my $ret = $self->_comp_vers( $version, $prereqs{$var}{$pkg}{version}, '<=' );
342 0 ▶ return 1 if defined $ret && $ret == 1;
Branch: 1 branch
BranchTrueFalseTotal
if defined $ret and $ret == 1 0 0 0
Condition0%0/3
defined $ret and $ret == 1
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ret and $ret == 1
defined $ret $ret == 1
Truth table0%0/3
A and B
A= defined $retB= $ret == 1
ABresult
0X0
100
111
343  
344 0 ▶ $prereqs{$var}{$pkg}{version} = $version
Branch: 1 branch
BranchTrueFalseTotal
if defined $ret and $ret == 0 0 0 0
Condition0%0/3
defined $ret and $ret == 0
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ret and $ret == 0
defined $ret $ret == 0
Truth table0%0/3
A and B
A= defined $retB= $ret == 0
ABresult
0X0
100
111
345 if defined $ret && $ret == 0;
346  
347 0 last;
348 }
349 # Skip duplicated package in makedepends, but get the lesser version.
350 ▶ elsif ( $var eq 'makedepends' && exists $prereqs{depends}{$pkg} ) {
Condition0%0/3
$var eq "makedepends" and exists $prereqs{"depends"}{$pkg}
!ll&&!rl&&r
000
MC/DC0%0/2
$var eq "makedepends" and exists $prereqs{"depends"}{$pkg}
$var eq "makedepends" exists $prereqs{"depends"}{$pkg}
Truth table0%0/3
A and B
A= $var eq "makedepends"B= exists $prereqs{"depends"}{$pkg}
ABresult
0X0
100
111
351 0 $prereq_pkg_dupe = true;
352  
353 0 $self->_pdbg("$pkg already in depends\n");
354  
355 0 my $ret = $self->_comp_vers( $version, $prereqs{depends}{$pkg}{version}, '<=' );
356 0 ▶ return 1 if defined $ret && $ret == 1;
Branch: 1 branch
BranchTrueFalseTotal
if defined $ret and $ret == 1 0 0 0
Condition0%0/3
defined $ret and $ret == 1
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ret and $ret == 1
defined $ret $ret == 1
Truth table0%0/3
A and B
A= defined $retB= $ret == 1
ABresult
0X0
100
111
357  
358 0 ▶ $prereqs{depends}{$pkg}{version} = $version
Branch: 1 branch
BranchTrueFalseTotal
if defined $ret and $ret == 0 0 0 0
Condition0%0/3
defined $ret and $ret == 0
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ret and $ret == 0
defined $ret $ret == 0
Truth table0%0/3
A and B
A= defined $retB= $ret == 0
ABresult
0X0
100
111
359 if defined $ret && $ret == 0;
360  
361 0 next;
362 }
363 }
364 0 ▶ next if $prereq_pkg_dupe;
Branch: 1 branch
BranchTrueFalseTotal
if $prereq_pkg_dupe 0 0 0
365  
366 0 my $repo_pkg_dupe = false;
367  
368 # Skip packages already found in Official/AUR repos or missing.
369 0 foreach my $pkg (@pkgs) {
370 0 ▶ if ( exists $seen_pkgs{$pkg} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $seen_pkgs{$pkg}) 0 0 0
371 0 $repo_pkg_dupe = true;
372  
373 $prereqs{$var}{$pkg} = {
374 missing => $seen_pkgs{$pkg}{missing},
375 version => $version,
376 flag_date => $seen_pkgs{$pkg}{flag_date},
377 0 };
378 0 ▶ $prereqs{$var}{$pkg}{module} = $module if $var eq 'optdepends';
Branch: 1 branch
BranchTrueFalseTotal
if $var eq "optdepends" 0 0 0
379  
380 0 $self->_pdbg("found repo pkg dupe; skip\n");
381 0 $self->_pdbg("\n\n");
382  
383 0 last;
384 }
385 }
386 0 ▶ next if $repo_pkg_dupe;
Branch: 1 branch
BranchTrueFalseTotal
if $repo_pkg_dupe 0 0 0
387  
388 # Whether to search for a single package or multiple packages with regex.
389 0 my $pkg_single;
390 my $pkg_rx;
391 {
392 # Bulk search only covers perl-* packages.
393 0 my @bulk_pkgs = grep { /\Aperl-/ } @pkgs;
394  
395 0 ▶ if ( scalar @bulk_pkgs == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @bulk_pkgs == 1) { } 0 0 0
396 0 $pkg_single = $bulk_pkgs[0];
397 }
398 # Only build a regex on multiple packages.
399 else {
400 # Longest matches must be matched first in regex alternations.
401 0 @bulk_pkgs = reverse sort { length $a <=> length $b } @bulk_pkgs;
402  
403 0 my $pat = join '|', map { "\Q$_\E" } @bulk_pkgs;
404 0 $pkg_rx = qr{\A(?'pkg' $pat)\z}x;
405 }
406  
407 0 $self->_pdump( '@pkgs', \@pkgs, '' );
408 0 $self->_pdump( '$pkg_single', \$pkg_single, '' );
409 0 $self->_pdump( '$pkg_rx', \$pkg_rx, "\n" );
410 }
411  
412 # Try to find the package in Official repositories.
413  
414 0 my $found = false;
415  
416 # Bulk search
417 {
418 0 my $pkg;
419  
420 0 foreach my $res ( $pkgs{official}->@* ) {
421 0 ▶ if ( defined $pkg_single && $res->{pkgname} eq $pkg_single ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $pkg_single and $res->{'pkgname'} eq $pkg_single) { } 0 0 0
elsif (defined $pkg_rx and $res->{'pkgname'} =~ /$pkg_rx/u) { } 0 0 0
Condition0%0/3
defined $pkg_single and $res->{"pkgname"} eq $pkg_single
!ll&&!rl&&r
000
MC/DC0%0/2
defined $pkg_single and $res->{"pkgname"} eq $pkg_single
defined $pkg_single $res->{"pkgname"} eq $pkg_single
Truth table0%0/3
A and B
A= defined $pkg_singleB= $res->{"pkgname"} eq $pkg_single
ABresult
0X0
100
111
422 0 $pkg = $pkg_single;
423 }
424 ▶ elsif ( defined $pkg_rx && $res->{pkgname} =~ $pkg_rx ) {
Condition0%0/3
defined $pkg_rx and $res->{"pkgname"} =~ /$pkg_rx/u
!ll&&!rl&&r
000
MC/DC0%0/2
defined $pkg_rx and $res->{"pkgname"} =~ /$pkg_rx/u
defined $pkg_rx $res->{"pkgname"} =~ /$pkg_rx/u
Truth table0%0/3
A and B
A= defined $pkg_rxB= $res->{"pkgname"} =~ /$pkg_rx/u
ABresult
0X0
100
111
425 0 $pkg = $+{pkg};
426 }
427  
428 0 ▶ if ( defined $pkg ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pkg) 0 0 0
429 0 $found = true;
430 0 ▶ $found = is_official_pkg($res) if $pkg !~ /\Aperl-/;
Branch: 1 branch
BranchTrueFalseTotal
unless $pkg =~ /\Aperl-/u 0 0 0
431  
432 0 ▶ if ($found) {
Branch: 1 branch
BranchTrueFalseTotal
if ($found) 0 0 0
433 # Strip leading 'v' from version if package does not use it.
434 0 ▶ $version =~ s{\Av}{} if $version =~ /\Av/ && $res->{pkgver} !~ /\Av/;
Branch: 1 branch
BranchTrueFalseTotal
if $version =~ /\Av/u and not $res->{"pkgver"} =~ /\Av/u 0 0 0
Condition0%0/3
$version =~ /\Av/u and not $res->{"pkgver"} =~ /\Av/u
!ll&&!rl&&r
000
MC/DC0%0/2
$version =~ /\Av/u and not $res->{"pkgver"} =~ /\Av/u
$version =~ /\Av/u not $res->{"pkgver"} =~ /\Av/u
Truth table0%0/3
A and not(B)
A= $version =~ /\Av/uB= not $res->{"pkgver"} =~ /\Av/u
ABresult
0X0
100
111
435  
436 0 my $date = _fmt_date( $res->{flag_date}, 'official' );
437  
438 0 $prereqs{$var}{$pkg} = {
439 version => $version,
440 flag_date => $date,
441 };
442 0 ▶ $prereqs{$var}{$pkg}{module} = $module if $var eq 'optdepends';
Branch: 1 branch
BranchTrueFalseTotal
if $var eq "optdepends" 0 0 0
443  
444 0 $seen_pkgs{$pkg} = { flag_date => $date };
445  
446 0 $self->_pdbg("found $pkg in official repos (bulk)\n");
447 0 $self->_pdbg("\n\n");
448  
449 0 last;
450 }
451 }
452 }
453 }
454 0 ▶ next if $found;
Branch: 1 branch
BranchTrueFalseTotal
if $found 0 0 0
455  
456 # Try an individual search.
457  
458 # perl-* pkgs were already searched in bulk.
459 0 my @exact_pkgs = grep { !/\Aperl-/ } @pkgs;
460  
461 # Exact pkgname search
462 0 foreach my $pkg (@exact_pkgs) {
463 0 my $query = "https://archlinux.org/packages/search/json/?name=$pkg&repo=Core&repo=Extra";
464  
465 0 my $json = $self->_get_json($query);
466 0 ▶ return 1 if $json == 1;
Branch: 1 branch
BranchTrueFalseTotal
if $json == 1 0 0 0
467 0 ▶ next unless scalar $json->{results}->@*;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @{$json->{"results"}} 0 0 0
468  
469 0 my $res = $json->{results}[0];
470  
471 0 ▶ if ( $res->{pkgname} eq $pkg ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->{"pkgname"} eq $pkg) 0 0 0
472 0 $found = true;
473 0 ▶ $found = is_official_pkg($res) if $pkg !~ /\Aperl-/;
Branch: 1 branch
BranchTrueFalseTotal
unless $pkg =~ /\Aperl-/u 0 0 0
474  
475 0 ▶ if ($found) {
Branch: 1 branch
BranchTrueFalseTotal
if ($found) 0 0 0
476 0 ▶ $version =~ s{\Av}{} if $version =~ /\Av/ && $res->{pkgver} !~ /\Av/;
Branch: 1 branch
BranchTrueFalseTotal
if $version =~ /\Av/u and not $res->{"pkgver"} =~ /\Av/u 0 0 0
Condition0%0/3
$version =~ /\Av/u and not $res->{"pkgver"} =~ /\Av/u
!ll&&!rl&&r
000
MC/DC0%0/2
$version =~ /\Av/u and not $res->{"pkgver"} =~ /\Av/u
$version =~ /\Av/u not $res->{"pkgver"} =~ /\Av/u
Truth table0%0/3
A and not(B)
A= $version =~ /\Av/uB= not $res->{"pkgver"} =~ /\Av/u
ABresult
0X0
100
111
477 0 my $date = _fmt_date( $res->{flag_date}, 'official' );
478  
479 0 $prereqs{$var}{$pkg} = {
480 version => $version,
481 flag_date => $date,
482 };
483 0 ▶ $prereqs{$var}{$pkg}{module} = $module if $var eq 'optdepends';
Branch: 1 branch
BranchTrueFalseTotal
if $var eq "optdepends" 0 0 0
484  
485 0 $seen_pkgs{$pkg} = { flag_date => $date };
486  
487 0 $self->_pdbg("found $pkg in official repos (individual)\n");
488 0 $self->_pdbg("\n\n");
489  
490 0 last;
491 }
492 }
493 }
494 0 ▶ next if $found;
Branch: 1 branch
BranchTrueFalseTotal
if $found 0 0 0
495  
496 # Try to find the package in the AUR.
497 #
498 # NOTE:
499 # There are currently ~2000 perl packages in AUR but the Aurweb
500 # API is limited to 5k results, so the archives could be used
501 # when needed.
502  
503 # Bulk search
504 {
505 0 my $pkg;
506  
507 0 foreach my $res ( $pkgs{aur}->@* ) {
508 0 ▶ if ( defined $pkg_single && $res->{PackageBase} eq $pkg_single ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $pkg_single and $res->{'PackageBase'} eq $pkg_single) { } 0 0 0
elsif (defined $pkg_rx and $res->{'PackageBase'} =~ /$pkg_rx/u) { } 0 0 0
Condition0%0/3
defined $pkg_single and $res->{"PackageBase"} eq $pkg_single
!ll&&!rl&&r
000
MC/DC0%0/2
defined $pkg_single and $res->{"PackageBase"} eq $pkg_single
defined $pkg_single $res->{"PackageBase"} eq $pkg_single
Truth table0%0/3
A and B
A= defined $pkg_singleB= $res->{"PackageBase"} eq $pkg_single
ABresult
0X0
100
111
509 0 $pkg = $pkg_single;
510 }
511 ▶ elsif ( defined $pkg_rx && $res->{PackageBase} =~ $pkg_rx ) {
Condition0%0/3
defined $pkg_rx and $res->{"PackageBase"} =~ /$pkg_rx/u
!ll&&!rl&&r
000
MC/DC0%0/2
defined $pkg_rx and $res->{"PackageBase"} =~ /$pkg_rx/u
defined $pkg_rx $res->{"PackageBase"} =~ /$pkg_rx/u
Truth table0%0/3
A and B
A= defined $pkg_rxB= $res->{"PackageBase"} =~ /$pkg_rx/u
ABresult
0X0
100
111
512 0 $pkg = $+{pkg};
513 }
514  
515 0 ▶ if ( defined $pkg ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pkg) 0 0 0
516 0 $found = true;
517 0 ▶ $found = is_aur_pkg($res) if $pkg !~ /\Aperl-/;
Branch: 1 branch
BranchTrueFalseTotal
unless $pkg =~ /\Aperl-/u 0 0 0
518  
519 0 ▶ if ($found) {
Branch: 1 branch
BranchTrueFalseTotal
if ($found) 0 0 0
520 0 ▶ $version =~ s{\Av}{} if $version =~ /\Av/ && $res->{Version} !~ /\A(?> [0-9]+:)?v/x;
Branch: 1 branch
BranchTrueFalseTotal
if $version =~ /\Av/u and not $res->{"Version"} =~ /\A(?> [0-9]+:)?v/ux 0 0 0
Condition0%0/3
$version =~ /\Av/u and not $res->{"Version"} =~ /\A(?> [0-9]+:)?v/ux
!ll&&!rl&&r
000
MC/DC0%0/2
$version =~ /\Av/u and not $res->{"Version"} =~ /\A(?> [0-9]+:)?v/ux
$version =~ /\Av/u not $res->{"Version"} =~ /\A(?> [0-9]+:)?v/ux
Truth table0%0/3
A and not(B)
A= $version =~ /\Av/uB= not $res->{"Version"} =~ /\A(?> [0-9]+:)?v/ux
ABresult
0X0
100
111
521 0 my $date = _fmt_date( $res->{OutOfDate}, 'aur' );
522  
523 0 $prereqs{$var}{$pkg} = {
524 version => $version,
525 flag_date => $date,
526 };
527 0 ▶ $prereqs{$var}{$pkg}{module} = $module if $var eq 'optdepends';
Branch: 1 branch
BranchTrueFalseTotal
if $var eq "optdepends" 0 0 0
528  
529 0 $seen_pkgs{$pkg} = { flag_date => $date };
530  
531 0 $self->_pdbg("found $pkg in AUR repos (bulk)\n");
532 0 $self->_pdbg("\n\n");
533  
534 0 last;
535 }
536 }
537 }
538 }
539 0 ▶ next if $found;
Branch: 1 branch
BranchTrueFalseTotal
if $found 0 0 0
540  
541 # Exact PackageBase search
542 {
543 0 my $query = 'https://aur.archlinux.org/rpc/v5/info?';
544  
545 # Construct multiple arg packages in a single query.
546 0 foreach my ( $idx, $pkg ) ( indexed @exact_pkgs ) {
547 0 my $arg = "arg[]=$pkg";
548 0 ▶ $arg = "&$arg" unless $idx == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $idx == 0 0 0 0
549  
550 0 $query .= $arg;
551 }
552  
553 0 my $json = $self->_get_json($query);
554 0 ▶ return 1 if $json == 1;
Branch: 1 branch
BranchTrueFalseTotal
if $json == 1 0 0 0
555 0 ▶ last unless scalar $json->{results}->@*;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @{$json->{"results"}} 0 0 0
556  
557 0 foreach my $res ( $json->{results}->@* ) {
558 0 my $pkg = $res->{PackageBase};
559  
560 0 $found = true;
561 0 ▶ $found = is_aur_pkg($res) if $pkg !~ /\Aperl-/;
Branch: 1 branch
BranchTrueFalseTotal
unless $pkg =~ /\Aperl-/u 0 0 0
562  
563 0 ▶ if ($found) {
Branch: 1 branch
BranchTrueFalseTotal
if ($found) 0 0 0
564 0 ▶ $version =~ s{\Av}{} if $version =~ /\Av/ && $res->{Version} !~ /\A(?> [0-9]+:)?v/x;
Branch: 1 branch
BranchTrueFalseTotal
if $version =~ /\Av/u and not $res->{"Version"} =~ /\A(?> [0-9]+:)?v/ux 0 0 0
Condition0%0/3
$version =~ /\Av/u and not $res->{"Version"} =~ /\A(?> [0-9]+:)?v/ux
!ll&&!rl&&r
000
MC/DC0%0/2
$version =~ /\Av/u and not $res->{"Version"} =~ /\A(?> [0-9]+:)?v/ux
$version =~ /\Av/u not $res->{"Version"} =~ /\A(?> [0-9]+:)?v/ux
Truth table0%0/3
A and not(B)
A= $version =~ /\Av/uB= not $res->{"Version"} =~ /\A(?> [0-9]+:)?v/ux
ABresult
0X0
100
111
565 0 my $date = _fmt_date( $res->{OutOfDate}, 'aur' );
566  
567 0 $prereqs{$var}{$pkg} = {
568 version => $version,
569 flag_date => $date,
570 };
571 0 ▶ $prereqs{$var}{$pkg}{module} = $module if $var eq 'optdepends';
Branch: 1 branch
BranchTrueFalseTotal
if $var eq "optdepends" 0 0 0
572  
573 0 $seen_pkgs{$pkg} = { flag_date => $date };
574  
575 0 $self->_pdbg("found $pkg in AUR repos (individual)\n");
576 0 $self->_pdbg("\n\n");
577  
578 0 last;
579 }
580 }
581 }
582 0 ▶ next if $found;
Branch: 1 branch
BranchTrueFalseTotal
if $found 0 0 0
583  
584 # Package was not found in the Official/AUR repos.
585 {
586 0 my $pkg = "perl-$dist";
587  
588 0 $prereqs{$var}{$pkg} = {
589 missing => $module,
590 version => $version,
591 };
592 0 ▶ $prereqs{$var}{$pkg}{module} = $module if $var eq 'optdepends';
Branch: 1 branch
BranchTrueFalseTotal
if $var eq "optdepends" 0 0 0
593  
594 0 $seen_pkgs{$pkg} = { missing => $module };
595  
596 0 $self->_pdbg("$pkg does not exist in Arch's official/AUR repos\n");
597 }
598 }
599  
600 0 $self->_pdbg("\n\n");
601 }
602 }
603  
604 0 $self->_pdump( '%prereqs', \%prereqs, "\n" );
605 0 $self->_pdump( '%seen_pkgs', \%seen_pkgs, "\n" );
606  
607 0 return \%prereqs;
608 1 }
609  
610 # Post-process prerequisites into its final data for PKGBUILD generation.
611 0 ▶method _postproc_prereqs (%prereqs)
Subroutine _postproc_prereqs: not called CC=14 SCAR=53.5
612 {
613 0 $self->_psub;
614  
615 0 my %opts = $self->opts;
616 0 my %post_prereqs;
617  
618 0 foreach my ( $var, $deps ) (%prereqs) {
619 0 foreach my ( $pkg, $info ) ( $deps->%* ) {
620 0 my ( $flag_date, $failed, $missing, $version ) = $info->@{ qw< flag_date failed missing version > };
621 0 ▶ my $vertype = reftype $version // '';
Condition0%0/2
builtin::reftype($version) // ""
l!l
00
MC/DC0%0/1
builtin::reftype($version) // ""
builtin::reftype($version)
Truth table0%0/2
A
A= builtin::reftype($version)
Aresult
11
00
622  
623 # Do not require a version in Test::Simple because several dists have
624 # been merged into it, e.g. Test::More, Test2::*. A Test2 dependency
625 # with a minimum version requirement older than the merge will resolve
626 # to perl-test-simple with that version, which may not exist in the
627 # Test-Simple dist.
628 0 ▶ $version = 0 if $pkg eq 'perl-test-simple';
Branch: 1 branch
BranchTrueFalseTotal
if $pkg eq "perl-test-simple" 0 0 0
629  
630 # Skip version requirement for 0 versions and failed.
631 0 ▶ $pkg =
Branch: 1 branch
BranchTrueFalseTotal
$version eq '0' || defined $failed ? : 0 0 0
Condition0%0/3
$version eq 0 or defined $failed
l!l&&r!l&&!r
000
MC/DC0%0/2
$version eq 0 or defined $failed
$version eq 0 defined $failed
Truth table0%0/3
A or B
A= $version eq 0B= defined $failed
ABresult
1X1
011
000
632 $version eq '0' || defined $failed
633 ? $pkg
634 : "$pkg>=$version";
635  
636 0 ▶ my sub push_pkg ($p)
Subroutine push_pkg: not called CC=4 SCAR=30.0
637 {
638 # Flagged/Failed/Missing/Existing package
639 0 ▶ push $post_prereqs{$var}->@*,
Branch: 3 branches
BranchTrueFalseTotal
defined $flag_date ? : 0 0 0
defined $failed ? : 0 0 0
defined $missing ? : 0 0 0
640 defined $flag_date ? { $p => { flag_date => $flag_date } }
641 : defined $failed ? { $p => { failed => $failed, version => $version } }
642 : defined $missing ? { $p => { missing => $missing } }
643 : $p;
644 }
645  
646 # Add optdepends descriptions.
647 0 ▶ if ( $var eq 'optdepends' && !defined $failed ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($var eq "optdepends" and not defined $failed) 0 0 0
Condition0%0/3
$var eq "optdepends" and not defined $failed
!ll&&!rl&&r
000
MC/DC0%0/2
$var eq "optdepends" and not defined $failed
$var eq "optdepends" not defined $failed
Truth table0%0/3
A and not(B)
A= $var eq "optdepends"B= not defined $failed
ABresult
0X0
100
111
648 0 my %optionals = $self->optionals;
649 0 my $module = $info->{module};
650  
651 0 ▶ if ( exists $optionals{$module} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $optionals{$module}) 0 0 0
652 0 foreach my $desc ( $optionals{$module}->@* ) {
653 # Massage desc
654 # https://man.archlinux.org/man/alpm-package-relation.7.en#Optional_dependency:~:text=Note
655 0 $desc = trim($desc)
656 =~ s{\v}{; }gr
657 =~ s{'}{\\'}gr;
658  
659 0 my $opt = "$pkg: $desc";
660 0 push_pkg($opt);
661 }
662 0 next;
663 }
664 }
665  
666 0 push_pkg($pkg);
667 }
668 }
669  
670 0 $self->_pdump( '%post_prereqs', \%post_prereqs, "\n" );
671  
672 # Sort the variable dependencies with Schwartzian transform since they may
673 # contain mixed elements (scalars and hashrefs).
674 {
675 0 foreach my ( $var, $deps ) (%post_prereqs) {
676 push $_arch_prereqs{$var}->@*,
677 0 map { $_->[0] }
678 0 sort { $a->[1] cmp $b->[1] }
679 0 ▶ map { [ $_, defined reftype $_ && reftype $_ eq 'HASH' ? keys $_->%* : $_ ] } $deps->@*;
Branch: 1 branch
BranchTrueFalseTotal
defined builtin::reftype($_) && builtin::reftype($_) eq 'HASH' ? : 0 0 0
Condition0%0/3
defined builtin::reftype($_) and builtin::reftype($_) eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
defined builtin::reftype($_) and builtin::reftype($_) eq "HASH"
defined builtin::reftype($_) builtin::reftype($_) eq "HASH"
Truth table0%0/3
A and B
A= defined builtin::reftype($_)B= builtin::reftype($_) eq "HASH"
ABresult
0X0
100
111
680 }
681  
682 0 $self->_pdump( '%_arch_prereqs', \%_arch_prereqs, "\n" );
683 }
684  
685 0 return $self;
686 1 }
687  
688 0 ▶method _init_mua_arch ()
Subroutine _init_mua_arch: not called CC=1 SCAR=6.9
689 {
690 0 $self->_psub;
691  
692 0 $_mua_arch = $self->_get_mua('arch');
693  
694 0 return $self;
695 1 }
696  
697 0 ▶method _get_json ($url)
Subroutine _get_json: not called CC=5 SCAR=34.0
698 {
699 0 $self->_psub;
700  
701 0 my $prog = $self->prog;
702  
703 # Request JSON
704 0 my $res;
705 {
706 0 my $OK = 200;
707 0 my $get_err = "$prog: failed to request $url\n";
708  
709 0 $res = do {
710 0 try {
711 0 my %env = $self->env;
712 0 ▶ local $ENV{MUAC_NOCACHE} = true if $env{cache_ignore};
Branch: 1 branch
BranchTrueFalseTotal
if $env{"cache_ignore"} 0 0 0
713  
714 0 $_mua_arch->get($url)->result;
715 }
716 catch ($e) {
717 0 warn $e;
718 0 undef;
719 }
720 };
721  
722 0 ▶ if ( !defined $res ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $res) 0 0 0
723 0 warn $get_err;
724 0 return 1;
725 }
726  
727 0 ▶ if ( $res->code != $OK ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->code != $OK) 0 0 0
728 0 warn $res->body;
729 0 warn $get_err;
730  
731 0 return 1;
732 }
733 }
734  
735 # Decode JSON
736 0 my $json = do {
737 0 try {
738 0 $res->json;
739 }
740 catch ($e) {
741 0 warn $e;
742 0 undef;
743 }
744 };
745  
746 0 ▶ if ( !defined $json ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $json) 0 0 0
747 0 warn "$prog: failed to decode $url\n";
748 0 return 1;
749 }
750  
751 0 $self->_pdbg("\n");
752  
753 0 return $json;
754 1 }
755  
756 # Get a list of core modules from specific Perl version.
757 0 ▶method _get_corelist ($ver)
Subroutine _get_corelist: not called CC=5 SCAR=34.0
758 {
759 0 $self->_psub;
760  
761 0 my $prog = $self->prog;
762  
763 # NOTE:
764 # Ideally, M::CoreList should always support the current perl pkg version,
765 # but its min required version would have to be kept updated, so just fallback
766 # to the current perl version if perl pkg version is not found in M::CoreList.
767 # This might lead to the generated PKGBUILD miss core modules (Arch users
768 # will have latest perl anyways).
769 0 require Module::CoreList;
770  
771 0 my $perl_pkg_ver = do {
772 0 try {
773 0 version->parse($ver)->numify;
774 }
775 catch ($e) {
776 0 warn $e;
777 0 warn "$prog: failed to parse $ver version\n";
778  
779 0 return 1;
780 }
781 };
782  
783 0 my $perl_cur_ver = $];
784  
785 0 ▶ if ( $perl_pkg_ver > $perl_cur_ver ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($perl_pkg_ver > $perl_cur_ver) 0 0 0
786 0 $self->_pdbg("perl package version ($perl_pkg_ver) is newer than the current perl version ($perl_cur_ver)\n");
787 }
788  
789 0 my $core_modules = Module::CoreList->find_version($perl_pkg_ver);
790  
791 # Fallback
792 0 ▶ $core_modules = Module::CoreList->find_version($perl_cur_ver)
Branch: 1 branch
BranchTrueFalseTotal
unless defined $core_modules 0 0 0
793 unless defined $core_modules;
794  
795 #$self->_pdump('$core_modules', $core_modules, "\n");
796  
797 0 ▶ if ( !defined $core_modules ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $core_modules) 0 0 0
798 0 warn "$prog: failed to get Perl core modules list\n";
799 0 return 1;
800 }
801  
802 # Exclude core libs that MetaCPAN API cannot fetch.
803 {
804 0 my @EXCLUDED = (
805 qw<
806 Unicode
807 unicore::Name
808 meta_notation
809 >
810 );
811  
812 0 delete $core_modules->{$_} foreach (@EXCLUDED);
813 }
814  
815 0 return $core_modules;
816 }
817  
818 # Format/convert datetime to YYYY-MMM-DD.
819 0 ▶sub _fmt_date ( $date, $repo )
Subroutine _fmt_date: not called CC=4 SCAR=30.0
820 {
821 0 ▶ return undef unless defined $date;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $date 0 0 0
822  
823 0 require Time::Piece;
824  
825 0 ▶ return $repo eq 'official'
Branch: 2 branches
BranchTrueFalseTotal
$repo eq 'official' ? : 0 0 0
$repo eq 'aur' ? : 0 0 0
826 ? $date =~ s{T.+\z}{}r
827 : $repo eq 'aur' ? Time::Piece::localtime($date)->ymd # Epoch
828 : undef;
829 }
830  
831 =encoding UTF-8
832  
833 =for highlighter language=perl
834  
835 =head1 NAME
836  
837 App::cpan2arch::CheckPackages - check existence of Arch Linux packages
838  
839 =head1 SYNOPSIS
840  
841 use App::cpan2arch;
842  
843 my $cpan2arch = App::cpan2arch->new;
844  
845 ...
846  
847 =head1 DESCRIPTION
848  
849 This role handles analysis of whether prerequisite distributions exist as packages
850 in the Arch Linux Official/AUR repositories, checks flagged out-of-date packages,
851 and builds C<PKGBUILD> data.
852  
853 =head1 METHODS
854  
855 =head2 check_packages
856  
857 $cpan2arch->check_packages;
858  
859 Takes no arguments and returns C<0> on success.
860  
861 =head1 BUGS
862  
863 Report bugs at L<https://github.com/ryoskzypu/App-cpan2arch/issues>.
864  
865 =head1 AUTHOR
866  
867 ryoskzypu <ryoskzypu@proton.me>
868  
869 =head1 SEE ALSO
870  
871 =over 4
872  
873 =item *
874  
875 L<https://wiki.archlinux.org/title/Official_repositories_web_interface>
876  
877 =item *
878  
879 L<https://wiki.archlinux.org/title/Aurweb_RPC_interface>
880  
881 =back
882  
883 =head1 COPYRIGHT
884  
885 Copyright © 2026 ryoskzypu
886  
887 MIT-0 License. See LICENSE for details.
888  
889 =cut
↑ Summary cpan2arch/WritePkgbuild.pm »