cpan2arch.pm

filter: Statementstmt 26.4% 45 / 170 Branchbran 0.0% 0 / 34 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 33.3% 11 / 33 Podpod 28.5% 2 / 7 totaltotal 23.4% 58 / 247 CC 21 SCAR 31.4
CC
21
Cov
22%
_process_env
90.0
_process_opts
42.0
_comp_vers
20.0
CRAP 23.2
« cpan2arch/GetMetadata.pm ↑ Summary
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; # For toolchain compatibility.
10 class App::cpan2arch
11 :does(App::cpan2arch::GetMetadata)
12 :does(App::cpan2arch::MergePrereqs)
13 :does(App::cpan2arch::CheckPackages)
14 1 ▶ :does(App::cpan2arch::WritePkgbuild);
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 1 ▶use File::Basename qw< basename >;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use version;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 1 our $VERSION = 'v1.1.2';
20  
21 field %_env :reader :writer = (
22 0 user_agent => "App::cpan2arch/$VERSION",
23 cache_mcpan_path => '/tmp/mcpan_cache',
24 cache_arch_path => '/tmp/arch_cache',
25 cache_expiration => '1d',
26 );
27 0 ▶field $_prog :reader = basename($0);
Subroutine env: not called CC=1 SCAR=4.1
Subroutine set_env: not called CC=1 SCAR=4.1
Pod undocumented
Pod undocumented
28 0 ▶field %_opts :reader;
Subroutine opts: not called CC=1 SCAR=2.0
Subroutine prog: not called CC=1 SCAR=2.0
Pod undocumented
Pod undocumented
29 0 ▶field %_args :reader;
Subroutine args: not called CC=1 SCAR=2.6
Pod undocumented
30  
31 0 ▶method init (@argv)
Subroutine init: not called CC=1 SCAR=6.9
Pod documented
32 {
33 0 _exit( $self->_process_env->_process_opts( \@argv ) );
34  
35 0 return $self;
36 1 }
37  
38 0 ▶method run ()
Subroutine run: not called CC=2 SCAR=17.9
Pod documented
39 {
40 0 $self->_psub;
41  
42 # Non-interactive TTY must not display this.
43 0 ▶ print STDERR "Generating PKGBUILD...\n" if -t STDOUT;
Branch: 1 branch
BranchTrueFalseTotal
if -t STDOUT 0 0 0
44  
45 0 _exit( $self->get_metadata );
46 0 _exit( $self->merge_prereqs );
47 0 _exit( $self->check_packages );
48 0 _exit( $self->generate_pkgbuild->write_pkgbuild );
49  
50 0 return 0;
51 1 }
52  
53 # Process environment variables.
54 0 ▶method _process_env ()
Subroutine _process_env: not called CC=9 SCAR=45.0
55 {
56 0 ▶ $_env{packager} = $ENV{PACKAGER} // 'Your Name <email@domain.tld>';
Condition0%0/2
$ENV{"PACKAGER"} // "Your Name <email\@domain.tld>"
l!l
00
MC/DC0%0/1
$ENV{"PACKAGER"} // "Your Name <email\@domain.tld>"
$ENV{"PACKAGER"}
Truth table0%0/2
A
A= $ENV{"PACKAGER"}
Aresult
11
00
57 0 ▶ $_env{user_agent} = $ENV{C2A_USER_AGENT} if defined $ENV{C2A_USER_AGENT};
Branch: 1 branch
BranchTrueFalseTotal
if defined $ENV{"C2A_USER_AGENT"} 0 0 0
58 0 ▶ $_env{cache_mcpan_path} = $ENV{C2A_CACHE_MCPAN_PATH} if defined $ENV{C2A_CACHE_MCPAN_PATH};
Branch: 1 branch
BranchTrueFalseTotal
if defined $ENV{"C2A_CACHE_MCPAN_PATH"} 0 0 0
59 0 ▶ $_env{cache_arch_path} = $ENV{C2A_CACHE_ARCH_PATH} if defined $ENV{C2A_CACHE_ARCH_PATH};
Branch: 1 branch
BranchTrueFalseTotal
if defined $ENV{"C2A_CACHE_ARCH_PATH"} 0 0 0
60 0 ▶ $_env{cache_expiration} = $ENV{C2A_CACHE_EXPIRATION} if defined $ENV{C2A_CACHE_EXPIRATION};
Branch: 1 branch
BranchTrueFalseTotal
if defined $ENV{"C2A_CACHE_EXPIRATION"} 0 0 0
61 0 ▶ $_env{cache_ignore} = $ENV{C2A_CACHE_IGNORE} ? true : false;
Branch: 1 branch
BranchTrueFalseTotal
$ENV{'C2A_CACHE_IGNORE'} ? : 0 0 0
62 0 ▶ $_env{debug} = $ENV{C2A_DEBUG} ? true : false;
Branch: 1 branch
BranchTrueFalseTotal
$ENV{'C2A_DEBUG'} ? : 0 0 0
63  
64 0 try {
65 0 ▶ if ( $_env{debug} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_env{"debug"}) 0 0 0
66 0 require Data::Printer;
67 0 Data::Printer->VERSION('1.002001');
68 }
69 }
70 catch ($e) {
71 0 warn $e;
72 0 warn "$_prog: Data::Printer is required to display debug information\n";
73  
74 0 exit 1;
75 }
76  
77 0 $self->_psub;
78 0 $self->_pdump( '%_env', \%_env, "\n" );
79  
80 0 return $self;
81 1 }
82  
83 # Process options and its arguments.
84 0 ▶method _process_opts ( $argv = undef )
Subroutine _process_opts: not called CC=6 SCAR=37.4
85 {
86 0 $self->_psub;
87  
88 0 ▶ return 0 unless defined $argv;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $argv 0 0 0
89  
90 # Transform Getopt::Long error warns.
91 0 ▶ local $SIG{__WARN__} = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
92 0 chomp( my $msg = shift );
93  
94 0 $msg =~ tr{"}{'};
95 0 $msg = lcfirst $msg;
96  
97 0 warn "$_prog: $msg\n";
98 0 };
99  
100 # Bash completion
101 0 try {
102 0 require Getopt::Long::More;
103  
104 0 Getopt::Long::More->VERSION('0.007');
105 0 Getopt::Long::More->import( qw< GetOptionsFromArray > );
106  
107 0 Getopt::Long::More::Configure(
108 qw<
109 default
110 gnu_getopt
111 no_ignore_case
112 >
113 );
114 }
115 catch ($e) {
116 # Use Getopt::Long as fallback.
117 0 require Getopt::Long;
118  
119 0 Getopt::Long->import(
120 qw<
121 GetOptionsFromArray
122 :config
123 default
124 gnu_getopt
125 no_ignore_case
126 >
127 );
128 }
129  
130 GetOptionsFromArray(
131 $argv,
132 'w|write' => \$_opts{write},
133 'force' => \$_opts{force},
134 'u|update' => \$_opts{update},
135 'c|clear' => \$_opts{clear},
136 'clear-mcpan' => \$_opts{clear_mcpan},
137 'clear-arch' => \$_opts{clear_arch},
138 0 ▶ 'h|help' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
139 0 require Pod::Usage;
140 0 Pod::Usage::pod2usage( -exitval => 0, -verbose => 0 );
141 },
142 0 ▶ 'v|version' => sub { print "$_prog $VERSION\n"; exit 0 },
Subroutine __ANON__: not called CC=1 SCAR=6.9
143  
144 0 ▶ ) or return 2;
Branch: 1 branch
BranchTrueFalseTotal
GetOptionsFromArray($argv, "w|write", \$_opts{"write"}, "force", \$_opts{"force"}, "u|update", \$_opts{"update"}, "c|clear", \$_opts{"clear"}, "clear-mcpan", \$_opts{"clear_mcpan"}, "clear-arch", \$_opts{"clear_arch"}, "h|help", sub { require Pod::Usage; Pod::Usage::pod2usage("-exitval", 0, "-verbose", 0); } , "v|version", sub { print "$_prog $VERSION\n"; exit 0; } ) or return 2 0 0 0
145  
146 0 $_args{module} = shift $argv->@*;
147 0 $_args{version} = shift $argv->@*;
148  
149 0 $self->_pdump( '%_opts', \%_opts, "\n" );
150 0 $self->_pdump( '%_args', \%_args, "\n" );
151 0 $self->_pdump( '$self', $self, "\n" );
152  
153 0 ▶ if ( !defined $_args{module} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $_args{"module"}) 0 0 0
154 0 warn "missing module name\n";
155 0 return 2;
156 }
157  
158 0 ▶ if ( $_args{module} eq 'perl' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_args{"module"} eq "perl") 0 0 0
159 0 warn "perl interpreter is not a module\n";
160 0 return 2;
161 }
162  
163 0 return 0;
164 1 }
165  
166 # Print debug message.
167 0 ▶method _pdbg ($msg)
Subroutine _pdbg: not called CC=2 SCAR=17.9
168 {
169 0 ▶ return undef unless $_env{debug};
Branch: 1 branch
BranchTrueFalseTotal
unless $_env{"debug"} 0 0 0
170  
171 0 print STDERR $msg;
172 1 }
173  
174 # Print debug the caller sub/method name.
175 0 ▶method _psub ()
Subroutine _psub: not called CC=1 SCAR=6.9
176 {
177 0 $self->_pdbg( ( caller 1 )[3] . "\n\n" );
178 1 }
179  
180 # Print variable dump.
181 0 ▶method _pdump ( $prefix, $var_ref, $suffix )
Subroutine _pdump: not called CC=2 SCAR=17.9
182 {
183 0 ▶ return undef unless $_env{debug};
Branch: 1 branch
BranchTrueFalseTotal
unless $_env{"debug"} 0 0 0
184  
185 0 my $dump = join(
186 '',
187 "$prefix = ",
188 Data::Printer::np($var_ref),
189 "\n",
190 $suffix,
191 );
192  
193 0 print STDERR $dump;
194 1 }
195  
196 # Compare Perl distribution versions.
197 0 ▶method _comp_vers ( $ver_a, $ver_b, $op )
Subroutine _comp_vers: not called CC=4 SCAR=30.0
198 {
199 0 my %vers = (
200 a_parsed => $ver_a,
201 b_parsed => $ver_b,
202 );
203  
204 0 foreach my ( $k, $ver ) (%vers) {
205 0 try {
206 0 $vers{$k} = version->parse($ver);
207 }
208 catch ($e) {
209 0 warn $e;
210 0 warn "$_prog: failed to parse $ver version\n";
211  
212 0 return 1;
213 }
214 }
215  
216 0 $self->_pdump( '$vers{a_parsed}', $vers{a_parsed}, '' );
217 0 $self->_pdump( '$vers{b_parsed}', $vers{b_parsed}, "\n" );
218  
219 my %ops = (
220 0 ▶ '<' => sub { $_[0] < $_[1] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
221 0 ▶ '<=' => sub { $_[0] <= $_[1] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
222 0 ▶ '==' => sub { $_[0] == $_[1] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
223 0 ▶ '>' => sub { $_[0] > $_[1] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
224 0 ▶ '>=' => sub { $_[0] >= $_[1] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
225 0 );
226  
227 0 ▶ if ( defined $ops{$op} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ops{$op}) 0 0 0
228 0 ▶ return 0 if $ops{$op}->( $vers{a_parsed}, $vers{b_parsed} );
Branch: 1 branch
BranchTrueFalseTotal
if $ops{$op}->($vers{"a_parsed"}, $vers{"b_parsed"}) 0 0 0
229 }
230  
231 0 return undef;
232 }
233  
234 0 ▶sub _exit ($code)
Subroutine _exit: not called CC=2 SCAR=17.9
235 {
236 0 ▶ exit $code if $code > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $code > 0 0 0 0
237 }
238  
239 =encoding UTF-8
240  
241 =for highlighter language=perl
242  
243 =head1 NAME
244  
245 App::cpan2arch - generate PKGBUILD from CPAN metadata
246  
247 =head1 SYNOPSIS
248  
249 use App::cpan2arch;
250  
251 App::cpan2arch->new->init(@ARGV)->run;
252  
253 =head1 DESCRIPTION
254  
255 B<App::cpan2arch> provides the logic behind the L<cpan2arch> wrapper script,
256 handling processing of environment variables and options, HTTP requests for
257 CPAN metadata and Arch Linux package information, translating dependencies
258 between CPAN and C<PKGBUILD>, and generating and outputting the C<PKGBUILD>.
259 See L<cpan2arch/DESCRIPTION> for details.
260  
261 =head1 METHODS
262  
263 =head2 new
264  
265 my $cpan2arch = App::cpan2arch->new;
266  
267 Constructs and returns a new B<App::cpan2arch> instance. Takes no arguments.
268  
269 =head2 init
270  
271 $cpan2arch->init(@ARGV);
272  
273 Reads environment variables and parses the list given (typically from C<@ARGV>)
274 for options. Returns C<self>.
275  
276 =head2 run
277  
278 $cpan2arch->run;
279  
280 Performs the program actions:
281  
282 =over 4
283  
284 =item *
285  
286 Fetches module/distribution metadata from L<MetaCPAN's|https://github.com/metacpan/metacpan-api>
287 API.
288  
289 =item *
290  
291 Merges L<CPAN prerequisites|https://metacpan.org/pod/CPAN::Meta::Spec#PREREQUISITES>
292 to L<PKGBUILD dependencies|https://man.archlinux.org/man/alpm-package-relation.7>.
293  
294 =item *
295  
296 Checks whether prerequisite distributions exist as packages on Arch's Official/AUR
297 repositories to build C<PKGBUILD> data.
298  
299 =item *
300  
301 Generates the C<PKGBUILD> to write to C<STDOUT> or file.
302  
303 =back
304  
305 Takes no arguments and returns C<0> on success.
306  
307 =head1 ERRORS
308  
309 This module reports errors to C<STDERR> and exits with a non-zero status in the
310 following:
311  
312 =over 4
313  
314 =item *
315  
316 Missing runtime dependencies (L<Data::Printer>, L<vercmp|https://man.archlinux.org/man/vercmp.8>)
317  
318 =item *
319  
320 Invalid command-line options
321  
322 =item *
323  
324 Network/JSON issues
325  
326 =item *
327  
328 MetaCPAN/Arch API issues
329  
330 =item *
331  
332 Dist tarball issues
333  
334 =item *
335  
336 C<perl> version issues
337  
338 =item *
339  
340 L<Module::CoreList> issues
341  
342 =item *
343  
344 File access/permission/metadata issues
345  
346 =back
347  
348 See L<cpan2arch/EXIT-STATUS> for exit code details.
349  
350 =head1 BUGS
351  
352 Report bugs at L<https://github.com/ryoskzypu/App-cpan2arch/issues>.
353  
354 =head1 AUTHOR
355  
356 ryoskzypu <ryoskzypu@proton.me>
357  
358 =head1 SEE ALSO
359  
360 =over 4
361  
362 =item *
363  
364 L<App::cpan2arch::GetMetadata>
365  
366 =item *
367  
368 L<App::cpan2arch::MergePrereqs>
369  
370 =item *
371  
372 L<App::cpan2arch::CheckPackages>
373  
374 =item *
375  
376 L<App::cpan2arch::WritePkgbuild>
377  
378 =back
379  
380 =head1 COPYRIGHT
381  
382 Copyright © 2026 ryoskzypu
383  
384 MIT-0 License. See LICENSE for details.
385  
386 =cut
« cpan2arch/GetMetadata.pm ↑ Summary