File Coverage

blib/lib/Shipwright/Script/Delete.pm
Criterion Covered Total %
statement 15 41 36.5
branch 0 16 0.0
condition 0 9 0.0
subroutine 5 7 71.4
pod 0 2 0.0
total 20 75 26.6


line stmt bran cond sub pod time code
1             package Shipwright::Script::Delete;
2              
3 1     1   654 use strict;
  1         2  
  1         23  
4 1     1   5 use warnings;
  1         1  
  1         24  
5              
6 1     1   5 use base qw/App::CLI::Command Shipwright::Base Shipwright::Script/;
  1         2  
  1         142  
7             __PACKAGE__->mk_accessors(qw/unreferenced check_only/);
8              
9 1     1   6 use Shipwright;
  1         2  
  1         5  
10 1     1   22 use Shipwright::Util;
  1         2  
  1         352  
11              
12             sub options {
13             (
14 0     0 0   'unreferenced' => 'unreferenced',
15             'C|check-only' => 'check_only',
16             );
17             }
18              
19             sub run {
20 0     0 0   my $self = shift;
21 0           my @sources = @_;
22              
23 0 0 0       unless ( @sources || $self->unreferenced ) {
24 0           confess_or_die "need name arg or --unreferenced\n";
25             }
26              
27 0 0 0       if ( @sources && $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 0         if (@sources) {
35 0           for my $name (@sources) {
36 0           my $map = $shipwright->backend->map;
37 0 0 0       if ( $map && $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 0         if ($refs) {
51 0           for my $name ( keys %$refs ) {
52 0 0         next if $name eq $order->[-1];
53 0 0         push @names, $name unless $refs->{$name};
54             }
55             }
56             }
57              
58 0 0         if ( $self->check_only ) {
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;
71              
72             __END__