App/lcpan/Cmd/copy_rel.pm

filter: Statementstmt 53.3% 16 / 30 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 75.0% 3 / 4 Podpod 100% 1 / 1 totaltotal 41.6% 20 / 48 CC 6 SCAR 33.4
CC
6
Cov
39%
handle_cmd
42.0
BEGIN
1.0
BEGIN
1.0
CRAP 28.3
« App/lcpan/Cmd/copy_mod.pm ↑ Summary App/lcpan/Cmd/dist_meta.pm »
1 package App::lcpan::Cmd::copy_rel;
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 => "Copy a release file to current directory",
19 args => {
20 %App::lcpan::common_args,
21 %App::lcpan::rel_args,
22 %App::lcpan::overwrite_args,
23 },
24 tags => ['write-to-fs'],
25 };
26 0 ▶sub handle_cmd {
Subroutine handle_cmd: not called CC=6 SCAR=37.4
Pod documented
27 0 require File::Copy;
28  
29 0 my %args = @_;
30  
31 0 my $state = App::lcpan::_init(\%args, 'ro');
32 0 my $dbh = $state->{dbh};
33  
34 0 my $rel = $args{release};
35  
36 0 my $row = $dbh->selectrow_hashref("SELECT
37 cpanid,
38 name
39 FROM file
40 WHERE name=?
41 ", {}, $rel);
42  
43 0 ▶ return [404, "No such release"] unless $row;
Branch: 1 branch
BranchTrueFalseTotal
unless $row 0 0 0
44  
45 my $srcpath = App::lcpan::_fullpath(
46 0 $row->{name}, $state->{cpan}, $row->{cpanid});
47 0 my $targetpath = $row->{name};
48  
49 0 ▶ (-f $srcpath) or return [404, "File not found: $srcpath"];
Branch: 1 branch
BranchTrueFalseTotal
-f $srcpath or return [404, "File not found: $srcpath"] 0 0 0
50  
51 0 ▶ if ((-f $targetpath) && !$args{overwrite}) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $targetpath and not $args{"overwrite"}) 0 0 0
Condition0%0/3
-f $targetpath and not $args{"overwrite"}
!ll&&!rl&&r
000
MC/DC0%0/2
-f $targetpath and not $args{"overwrite"}
-f $targetpath not $args{"overwrite"}
Truth table0%0/3
A and not(B)
A= -f $targetpathB= not $args{"overwrite"}
ABresult
0X0
100
111
52 0 return [412, "Refusing to overwrite existing file '$targetpath'"];
53 }
54  
55 0 ▶ File::Copy::syscopy($srcpath, $targetpath)
Branch: 1 branch
BranchTrueFalseTotal
File::Copy::syscopy($srcpath, $targetpath) or return [500, "Can't copy '${srcpath}' to '${targetpath}': $!"] 0 0 0
56 or return [500, "Can't copy '$srcpath' to '$targetpath': $!"];
57  
58 0 [200, "OK", undef, {
59 'func.source_path'=>$srcpath,
60 'func.target_path'=>$targetpath,
61 }];
62 }
63  
64 1 1;
65 # ABSTRACT: Copy a release file to current directory
66  
67 __END__
« App/lcpan/Cmd/copy_mod.pm ↑ Summary App/lcpan/Cmd/dist_meta.pm »