| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 0 | ▶ | if ((-f $targetpath) && !$args{overwrite}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
-f $targetpath and not $args{"overwrite"}
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"}
| |||||||||||||||||||||||||||||
| 54 | 0 | return [412, "Refusing to overwrite existing file '$targetpath'"]; | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 0 | ▶ | File::Copy::syscopy($srcpath, $targetpath) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||