App/lcpan/Cmd/delete_rel.pm

filter: Statementstmt 61.2% 19 / 31 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 80.0% 4 / 5 Podpod 100% 1 / 1 totaltotal 58.5% 24 / 41 CC 3 SCAR 17.4
CC
3
Cov
54%
handle_cmd
12.0
BEGIN
1.0
BEGIN
1.0
CRAP 5.7
« App/lcpan/Cmd/author_rdeps.pm ↑ Summary App/lcpan/Cmd/inject.pm »
1 package App::lcpan::Cmd::delete_rel;
2  
3 1 ▶use 5.010001;
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 1 ▶use Log::ger;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 require App::lcpan;
9  
10 1 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
11 1 our $DATE = '2023-09-26'; # DATE
12 1 our $DIST = 'App-lcpan'; # DIST
13 1 our $VERSION = '1.074'; # VERSION
14  
15 1 our %SPEC;
16  
17 $SPEC{handle_cmd} = {
18 1 v => 1.1,
19 summary => 'Delete a release record in the database',
20 description => <<'_',
21  
22 Will delete records associated with a release in the database (including in the
23 `file` table, `module`, `dist`, `dep`, and so on). If `--delete-file` option is
24 specified, will also remove the file from the local mirror.
25  
26 But currently will not remove/update the `modules/02packages.details.txt.gz`
27 index.
28  
29 _
30 args => {
31 %App::lcpan::common_args,
32 %App::lcpan::rel_args,
33 delete_file => {
34 summary => 'Whether to delete the release file from the filesystem too',
35 schema => ['bool*', is=>1],
36 },
37 },
38 tags => ['write-to-db', 'write-to-fs'],
39 };
40 0 ▶sub handle_cmd {
Subroutine handle_cmd: not called CC=3 SCAR=24.8
Pod documented
41 0 my %args = @_;
42  
43 0 my $state = App::lcpan::_init(\%args, 'rw');
44 0 my $dbh = $state->{dbh};
45  
46 my $row = $dbh->selectrow_hashref("SELECT id,cpanid FROM file WHERE name=?", {}, $args{release})
47 0 ▶ or return [404, "No such release"];
Branch: 1 branch
BranchTrueFalseTotal
my $row = $dbh->selectrow_hashref("SELECT id,cpanid FROM file WHERE name=?", {}, $args{"release"}) or return [404, "No such release"] 0 0 0
48  
49 0 $dbh->begin_work;
50 0 App::lcpan::_delete_releases_records($dbh, $row->{id});
51 0 $dbh->commit;
52  
53 0 ▶ if ($args{delete_file}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"delete_file"}) 0 0 0
54 my $path = App::lcpan::_fullpath(
55 0 $args{release}, $state->{cpan}, $row->{cpanid});
56 0 log_info("Deleting file %s ...", $path);
57 0 unlink $path;
58 }
59  
60 0 [200, "OK"];
61 }
62  
63 1 1;
64 # ABSTRACT: Delete a release record in the database
65  
66 __END__
« App/lcpan/Cmd/author_rdeps.pm ↑ Summary App/lcpan/Cmd/inject.pm »