| 1 | package CPAN::Maker::Bootstrapper::Role::Uninstall; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | |||
| 6 | use CLI::Simple::Constants qw(:booleans); | ||
| 7 | use English qw(-no_match_vars); | ||
| 8 | use ExtUtils::Install (); | ||
| 9 | use ExtUtils::Installed (); | ||
| 10 | |||
| 11 | use Role::Tiny; | ||
| 12 | |||
| 13 | ######################################################################## | ||
| 14 | sub cmd_uninstall { | ||
| 15 | ######################################################################## | ||
| 16 | my ($self) = @_; | ||
| 17 | |||
| 18 | my $distribution = 'CPAN::Maker::Bootstrapper'; | ||
| 19 | |||
| 20 | my $installed = ExtUtils::Installed->new( skip_cwd => 1 ); | ||
| 21 | my $packlist = eval { $installed->packlist($distribution) }; | ||
| 22 | |||
| 23 | die "ERROR: installation packlist not found for $distribution\n" | ||
| 24 | if !$packlist; | ||
| 25 | |||
| 26 | my $packfile = $packlist->packlist_file; | ||
| 27 | |||
| 28 | die "ERROR: installation packlist not found for $distribution\n" | ||
| 29 | if !$packfile || !-f $packfile; | ||
| 30 | |||
| 31 | my @files = sort keys %{$packlist}; | ||
| 32 | |||
| 33 | die "ERROR: refusing to use an empty packlist\n" | ||
| 34 | if !@files; | ||
| 35 | |||
| 36 | for my $file (@files) { | ||
| 37 | die "ERROR: nonabsolute path in packlist: $file\n" | ||
| 38 | if $file !~ m{^/}; | ||
| 39 | } | ||
| 40 | |||
| 41 | $self->get_logger->info("Distribution: $distribution"); | ||
| 42 | $self->get_logger->info("Packlist: $packfile"); | ||
| 43 | $self->get_logger->info( "Recorded files: ", scalar(@files) ); | ||
| 44 | $self->get_logger->info( join "\n", @files ); | ||
| 45 | $self->get_logger->info("$packfile (packlist)"); | ||
| 46 | |||
| 47 | if ( $self->get_dry_run || !$self->get_force ) { | ||
| 48 | $self->get_logger->error("\nPreview only. Use --force to uninstall."); | ||
| 49 | return $SUCCESS; | ||
| 50 | } | ||
| 51 | |||
| 52 | # ExtUtils::Install::uninstall expects the packlist *filename*, not the object. | ||
| 53 | ExtUtils::Install::uninstall( $packfile, 1, 0 ); | ||
| 54 | |||
| 55 | my @remaining = grep { -e $_ || -l $_ } @files; | ||
| 56 | push @remaining, $packfile | ||
| 57 | if -e $packfile || -l $packfile; | ||
| 58 | |||
| 59 | if (@remaining) { | ||
| 60 | $self->get_logger->warn( "files remain after uninstall:", map {" $_\n"} @remaining ); | ||
| 61 | return $FAILURE; | ||
| 62 | } | ||
| 63 | |||
| 64 | $self->get_logger->info("Uninstall completed; all recorded files were removed."); | ||
| 65 | return $SUCCESS; | ||
| 66 | } | ||
| 67 | |||
| 68 | 1; |