| 1 | package Shipwright::Script::Delete; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use base qw/App::CLI::Command Shipwright::Base Shipwright::Script/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | __PACKAGE__->mk_accessors(qw/unreferenced check_only/); | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Shipwright; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Shipwright::Util; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 0 | ▶ | sub options { | ||||||||||||||||||||||||||
|
Subroutine
options: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 13 | ( | ||||||||||||||||||||||||||||
| 14 | 0 | 'unreferenced' => 'unreferenced', | |||||||||||||||||||||||||||
| 15 | 'C|check-only' => 'check_only', | ||||||||||||||||||||||||||||
| 16 | ); | ||||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 0 | ▶ | sub run { | ||||||||||||||||||||||||||
|
Subroutine
run: not called CC=15 SCAR=54.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 20 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 21 | 0 | my @sources = @_; | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 0 | ▶ | unless ( @sources || $self->unreferenced ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@sources or $self->unreferenced
MC/DC0%0/2
@sources or $self->unreferenced
@sources
$self->unreferenced
Truth table0%0/3
A or B
A= @sourcesB= $self->unreferenced
| |||||||||||||||||||||||||||||
| 24 | 0 | confess_or_die "need name arg or --unreferenced\n"; | |||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 0 | ▶ | if ( @sources && $self->unreferenced ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@sources and $self->unreferenced
MC/DC0%0/2
@sources and $self->unreferenced
@sources
$self->unreferenced
Truth table0%0/3
A and B
A= @sourcesB= $self->unreferenced
| |||||||||||||||||||||||||||||
| 28 | 0 | confess_or_die "please choose only one thing: a dist name or --unreferenced"; | |||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 0 | my $shipwright = Shipwright->new( repository => $self->repository, ); | |||||||||||||||||||||||||||
| 32 | 0 | my @names; | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 0 | ▶ | if (@sources) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | 0 | for my $name (@sources) { | |||||||||||||||||||||||||||
| 36 | 0 | my $map = $shipwright->backend->map; | |||||||||||||||||||||||||||
| 37 | 0 | ▶ | if ( $map && $map->{$name} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$map and $map->{$name}
MC/DC0%0/2
$map and $map->{$name}
$map
$map->{$name}
Truth table0%0/3
A and B
A= $mapB= $map->{$name}
| |||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | # it's a cpan module | ||||||||||||||||||||||||||||
| 40 | 0 | $name = $map->{$name}; | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | 0 | push @names, $name; | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | else { | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | # unreferenced dists except the last one | ||||||||||||||||||||||||||||
| 48 | 0 | my $refs = $shipwright->backend->refs; | |||||||||||||||||||||||||||
| 49 | 0 | my $order = $shipwright->backend->order; | |||||||||||||||||||||||||||
| 50 | 0 | ▶ | if ($refs) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 0 | for my $name ( keys %$refs ) { | |||||||||||||||||||||||||||
| 52 | 0 | ▶ | next if $name eq $order->[-1]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | 0 | ▶ | push @names, $name unless $refs->{$name}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 0 | ▶ | if ( $self->check_only ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | 0 | $self->log->fatal( "dists to be deleted are: @names" ); | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | else { | ||||||||||||||||||||||||||||
| 62 | 0 | for my $name (@names) { | |||||||||||||||||||||||||||
| 63 | 0 | $shipwright->backend->trim( name => $name ); | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | 0 | $self->log->fatal( "successfully deleted @names" ); | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 1 | 1; | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | __END__ | ||||||||||||||||||||||||||||