| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | 0 | for my $name (@$args) { | |||||||||||||||||||
| 46 | 0 | ▶ | unless ( $manifest->has_dependency($name) ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 53 | 0 | $manifest->remove_dependency($name); | |||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | 0 | ▶ | my $display_name = $dep->{name} // $name; | ||||||||||||||||||
|
Condition0%0/3
$dep->{"name"} // $name
MC/DC0%0/2
$dep->{"name"} // $name
$dep->{"name"}
$name
Truth table0%0/3
A // B
A= $dep->{"name"}B= $name
| |||||||||||||||||||||
| 56 | 0 | print "Removed '$display_name'\n"; | |||||||||||||||||||
| 57 | } | ||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | 0 | $manifest->save; | |||||||||||||||||||
| 60 | 0 | return; | |||||||||||||||||||
| 61 | } | ||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | 1 | 1; | |||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | __END__ | ||||||||||||||||||||