CLI/Command/Remove.pm

filter: Statementstmt 35.7% 15 / 42 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 62.5% 5 / 8 Podpod 100% 3 / 3 totaltotal 32.8% 23 / 70 CC 10 SCAR 41.8
CC
10
Cov
26%
execute
110.0
abstract
2.0
opt_spec
2.0
CRAP 65.2
« CLI/Command/Search.pm ↑ Summary CLI/Command/Add.pm »
1 package Luv::CLI::Command::Remove;
2  
3 # ABSTRACT: remove a library dependency
4  
5 1 ▶use v5.38;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Object::Pad;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use App::Cmd::Setup -command;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use File::Path qw(remove_tree);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 ▶use Luv::CLI::Manifest;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 0 ▶sub abstract {
Subroutine abstract: not called CC=1 SCAR=6.9
Pod documented
14 0 "Removes a library dependency.";
15 }
16  
17 0 ▶sub opt_spec {
Subroutine opt_spec: not called CC=1 SCAR=6.9
Pod documented
18 0 return ( [ 'all|a' => 'remove all dependencies' ], );
19 }
20  
21 0 ▶sub execute ( $self, $opt, $args ) {
Subroutine execute: not called CC=10 SCAR=47.0
Pod documented
22 0 my $manifest_path = "luv.json";
23 0 ▶ die "No luv.json found — run 'luv init' first\n" unless -e $manifest_path;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $manifest_path 0 0 0
24  
25 0 my $manifest = Luv::CLI::Manifest->new( path => $manifest_path );
26 0 $manifest->load;
27  
28 0 ▶ if ( $opt->{all} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->{"all"}) 0 0 0
29 0 my $deps = $manifest->dependencies;
30 0 my $count = scalar keys %$deps;
31  
32 0 for my $key ( keys %$deps ) {
33 File::Path::remove_tree( $deps->{$key}{path} )
34 0 ▶ if -d $deps->{$key}{path};
Branch: 1 branch
BranchTrueFalseTotal
if -d $deps->{$key}{"path"} 0 0 0
35 }
36  
37 0 $manifest->clear_dependencies;
38 0 $manifest->save;
39 0 print "Removed all $count dependencies\n";
40 0 return;
41 }
42  
43 0 ▶ die "Usage: luv remove <library-name> [...] | --all\n" unless @$args;
Branch: 1 branch
BranchTrueFalseTotal
unless @$args 0 0 0
44  
45 0 for my $name (@$args) {
46 0 ▶ unless ( $manifest->has_dependency($name) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($manifest->has_dependency($name)) 0 0 0
47 0 warn "No such dependency: $name — skipping\n";
48 0 next;
49 }
50  
51 0 my $dep = $manifest->dependencies->{ lc $name };
52 0 ▶ File::Path::remove_tree( $dep->{path} ) if -d $dep->{path};
Branch: 1 branch
BranchTrueFalseTotal
if -d $dep->{"path"} 0 0 0
53 0 $manifest->remove_dependency($name);
54  
55 0 ▶ my $display_name = $dep->{name} // $name;
Condition0%0/3
$dep->{"name"} // $name
l!l&&r!l&&!r
000
MC/DC0%0/2
$dep->{"name"} // $name
$dep->{"name"} $name
Truth table0%0/3
A // B
A= $dep->{"name"}B= $name
ABresult
1X1
011
000
56 0 print "Removed '$display_name'\n";
57 }
58  
59 0 $manifest->save;
60 0 return;
61 }
62  
63 1 1;
64  
65 __END__
« CLI/Command/Search.pm ↑ Summary CLI/Command/Add.pm »