App/lcpan/Cmd/copy_mod.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/scripts_from_same_dist.pm ↑ Summary App/lcpan/Cmd/copy_rel.pm »
1 package App::lcpan::Cmd::copy_mod;
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 module's latest release file to current directory",
19 args => {
20 %App::lcpan::common_args,
21 %App::lcpan::mod_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 $mod = $args{module};
35  
36 0 my $row = $dbh->selectrow_hashref("SELECT
37 file.cpanid cpanid,
38 file.name name
39 FROM module
40 LEFT JOIN file ON module.file_id=file.id
41 WHERE module.name=?
42 ORDER BY version_numified DESC
43 ", {}, $mod);
44  
45 0 ▶ return [404, "No release for module '$mod'"] unless $row;
Branch: 1 branch
BranchTrueFalseTotal
unless $row 0 0 0
46  
47 my $srcpath = App::lcpan::_fullpath(
48 0 $row->{name}, $state->{cpan}, $row->{cpanid});
49 0 my $targetpath = $row->{name};
50  
51 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
52  
53 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
54 0 return [412, "Refusing to overwrite existing file '$targetpath'"];
55 }
56  
57 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
58 or return [500, "Can't copy '$srcpath' to '$targetpath': $!"];
59  
60 0 [200, "OK", undef, {
61 'func.source_path'=>$srcpath,
62 'func.target_path'=>$targetpath,
63 }];
64 }
65  
66 1 1;
67 # ABSTRACT: Copy a module's latest release file to current directory
68  
69 __END__
« App/lcpan/Cmd/scripts_from_same_dist.pm ↑ Summary App/lcpan/Cmd/copy_rel.pm »