App/lcpan/Cmd/extract_dist.pm

filter: Statementstmt 57.1% 16 / 28 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 75.0% 3 / 4 Podpod 100% 1 / 1 totaltotal 51.2% 20 / 39 CC 4 SCAR 24.7
CC
4
Cov
47%
handle_cmd
20.0
BEGIN
1.0
BEGIN
1.0
CRAP 11.9
« App/lcpan/Cmd/dist_mods.pm ↑ Summary App/lcpan/Cmd/extract_mod.pm »
1 package App::lcpan::Cmd::extract_dist;
2  
3 1 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 require App::lcpan;
8  
9 1 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
10 1 our $DATE = '2023-09-26'; # DATE
11 1 our $DIST = 'App-lcpan'; # DIST
12 1 our $VERSION = '1.074'; # VERSION
13  
14 1 our %SPEC;
15  
16 1 $SPEC{'handle_cmd'} = {
17 v => 1.1,
18 summary => "Extract a distribution's latest release file to current directory",
19 args => {
20 %App::lcpan::common_args,
21 %App::lcpan::dist_args,
22 },
23 tags => ['write-to-fs'],
24 };
25 0 ▶sub handle_cmd {
Subroutine handle_cmd: not called CC=4 SCAR=30.0
Pod documented
26 0 require Archive::Extract;
27  
28 0 my %args = @_;
29  
30 0 my $state = App::lcpan::_init(\%args, 'ro');
31 0 my $dbh = $state->{dbh};
32  
33 0 my $dist = $args{dist};
34  
35 0 my $row = $dbh->selectrow_hashref("SELECT
36 cpanid cpanid,
37 name name
38 FROM file
39 WHERE dist_name=? AND is_latest_dist=1
40 ORDER BY dist_version_numified DESC
41 ", {}, $dist);
42  
43 0 ▶ return [404, "No release for distribution '$dist'"] unless $row;
Branch: 1 branch
BranchTrueFalseTotal
unless $row 0 0 0
44  
45 my $path = App::lcpan::_fullpath(
46 0 $row->{name}, $state->{cpan}, $row->{cpanid});
47  
48 0 ▶ (-f $path) or return [404, "File not found: $path"];
Branch: 1 branch
BranchTrueFalseTotal
-f $path or return [404, "File not found: $path"] 0 0 0
49  
50 0 my $ae = Archive::Extract->new(archive => $path);
51 0 ▶ $ae->extract or return [500, "Can't extract: " . $ae->error];
Branch: 1 branch
BranchTrueFalseTotal
$ae->extract or return [500, q[Can't extract: ] . $ae->error] 0 0 0
52  
53 0 [200, "OK", undef, {'func.release_path'=>$path}];
54 }
55  
56 1 1;
57 # ABSTRACT: Extract a distribution's latest release file to current directory
58  
59 __END__
« App/lcpan/Cmd/dist_mods.pm ↑ Summary App/lcpan/Cmd/extract_mod.pm »