lib/App/FuguBench/Fetch.pm

filter: Statementstmt 60.6% 20 / 33 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 70.0% 7 / 10 Podpod 100% 2 / 2 totaltotal 54.7% 29 / 53 CC 5 SCAR 19.8
CC
5
Cov
49%
_run
20.0
check_url
6.0
__ANON__
2.0
CRAP 7.2
« lib/App/FuguBench/Worktree.pm ↑ Summary lib/App/FuguBench/Checkout.pm »
1 # ex:ts=8 sw=4:
2 # $OpenBSD$
3 #
4 # Copyright (c) 2026 Dick Olsson <hi@senzilla.io>
5 #
6 # Permission to use, copy, modify, and distribute this software for any
7 # purpose with or without fee is hereby granted, provided that the above
8 # copyright notice and this permission notice appear in all copies.
9 #
10 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  
18 package App::FuguBench::Fetch;
19 117 our $VERSION = '0.1.1';
20  
21 117 ▶use v5.34;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 117 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 117 ▶use experimental 'signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
24 117 ▶no feature qw(indirect multidimensional bareword_filehandles);
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 117 ▶use Fugu::CLI qw(EXIT_SUCCESS EXIT_ERROR);
Subroutine BEGIN: called CC=1 SCAR=0.0
27 117 ▶use Fugu::Curl;
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 # App::FuguBench::Fetch - the fetch verb.
30 #
31 # The verb downloads one URL to one file through Fugu::Curl, which
32 # runs curl, wget, or ftp (DEPS-FETCH-1). It takes the argument order
33 # of the ftp helper of Tooling: the file first, and the URL after it
34 # (DEPS-FETCH-2). A make recipe that called the helper calls the verb,
35 # and the deps verb names it in the trace of a download.
36 #
37 # The verb reads no checkout (CLI-CHECKOUT-5), so it runs in a tree
38 # with no .toolingrc.
39 #
40 # The URL reaches the downloader as one argument, with no '--'
41 # separator ahead of it, so it takes a shape check first
42 # (DEPS-FETCH-4). check_url holds that check, and the deps verb calls
43 # it over each manifest URL.
44 #
45 # Fugu::Curl writes the bytes beside the destination and renames the
46 # file on success, so a failed download leaves no file. The verb
47 # reports the reason of a failure and returns 1.
48  
49 # App::FuguBench::Fetch->command($verb):
50 # The entry of the Fugu::CLI table. The module holds one verb,
51 # so it ignores the name.
52 117 ▶sub command ( $, $ )
Subroutine command: called CC=1 SCAR=1.2
Pod documented
53 {
54 return {
55 summary => 'download one URL to one file',
56 usage => '<file> <url>',
57 0 ▶ run => sub ( $app, @argv ) { return _run( $app, @argv ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
58 117 };
59 }
60  
61 # App::FuguBench::Fetch::check_url($app, $url, $where):
62 # Hold one URL to the shape that the downloader allows
63 # (DEPS-FETCH-4). Fugu::Curl places the URL last and builds no
64 # '--' separator, so a URL that starts with a dash reaches the
65 # downloader as an option. A scheme starts with a letter, so the
66 # scheme rule covers the dash as well.
67 #
68 # $where names the source of the URL in the message. The
69 # function returns 1 for a URL that passes, and 0 for one that
70 # does not, which it reports. The deps verb runs this check over
71 # each manifest URL, so one check serves both (CLI-PROGRAM-6).
72 0 ▶sub check_url ( $app, $url, $where )
Subroutine check_url: not called CC=2 SCAR=17.9
Pod documented
73 {
74 0 ▶ return 1 if $url =~ m{\A[a-z][a-z0-9+.-]*://}i;
Branch: 1 branch
BranchTrueFalseTotal
if $url =~ m[\A[a-z][a-z0-9+.-]*://]iu 0 0 0
75  
76 0 $app->cli->log->error(
77 '%s: the URL must start with a scheme, because the'
78 . ' downloader takes no -- separator: %s',
79 $where, $url
80 );
81  
82 0 return 0;
83 }
84  
85 # _run($app, @argv):
86 # The body of the verb. The arguments are the destination file
87 # and the URL, in that order, and every other command line is a
88 # usage error. A URL of the wrong shape is one as well, so the
89 # verb names the fault and then prints the usage (CLI-PROGRAM-3).
90 0 ▶sub _run ( $app, @argv )
Subroutine _run: not called CC=4 SCAR=30.0
91 {
92 0 my $cli = $app->cli;
93  
94 0 ▶ return $cli->command_usage_error('fetch') if @argv != 2;
Branch: 1 branch
BranchTrueFalseTotal
if @argv != 2 0 0 0
95 0 my ( $file, $url ) = @argv;
96  
97 0 ▶ return $cli->command_usage_error('fetch')
Branch: 1 branch
BranchTrueFalseTotal
unless check_url($app, $url, "the command line") 0 0 0
98 unless check_url( $app, $url, 'the command line' );
99  
100 # Fugu::Curl reports an absent downloader as a failed fetch,
101 # so one branch covers it and every other failure.
102 0 my $curl = Fugu::Curl->new;
103 0 ▶ unless ( $curl->fetch( $url, $file ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($curl->fetch($url, $file)) 0 0 0
104 0 $cli->log->error( '%s', $curl->error );
105 0 return EXIT_ERROR;
106 }
107  
108 0 return EXIT_SUCCESS;
109 }
110  
111 117 1;
« lib/App/FuguBench/Worktree.pm ↑ Summary lib/App/FuguBench/Checkout.pm »