| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Alien::Build::Plugin::Cleanse::BuildDir; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 2 |  |  | 2 |  | 229004 | use strict; | 
|  | 2 |  |  |  |  | 10 |  | 
|  | 2 |  |  |  |  | 43 |  | 
| 4 | 2 |  |  | 2 |  | 9 | use warnings; | 
|  | 2 |  |  |  |  | 3 |  | 
|  | 2 |  |  |  |  | 36 |  | 
| 5 | 2 |  |  | 2 |  | 31 | use 5.008001; | 
|  | 2 |  |  |  |  | 6 |  | 
| 6 | 2 |  |  | 2 |  | 870 | use Alien::Build; | 
|  | 2 |  |  |  |  | 64753 |  | 
|  | 2 |  |  |  |  | 58 |  | 
| 7 | 2 |  |  | 2 |  | 760 | use Alien::Build::Plugin; | 
|  | 2 |  |  |  |  | 3786 |  | 
|  | 2 |  |  |  |  | 11 |  | 
| 8 | 2 |  |  | 2 |  | 163 | use File::Path qw /remove_tree/; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 76 |  | 
| 9 | 2 |  |  | 2 |  | 11 | use Cwd qw /getcwd/; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 61 |  | 
| 10 | 2 |  |  | 2 |  | 10 | use Path::Tiny qw /path/; | 
|  | 2 |  |  |  |  | 3 |  | 
|  | 2 |  |  |  |  | 434 |  | 
| 11 |  |  |  |  |  |  |  | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | our $VERSION = '0.05'; # VERSION | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  |  | 
| 16 |  |  |  |  |  |  | sub init { | 
| 17 | 1 |  |  | 1 | 1 | 12694 | my($self, $meta) = @_; | 
| 18 |  |  |  |  |  |  |  | 
| 19 |  |  |  |  |  |  | $meta->after_hook ( build => sub { | 
| 20 | 1 |  |  | 1 |  | 36817 | my($build) = @_; | 
| 21 |  |  |  |  |  |  |  | 
| 22 | 1 | 50 |  |  |  | 6 | return if $build->install_type ne 'share'; | 
| 23 | 1 | 50 |  |  |  | 15 | return if $build->meta_prop->{out_of_source}; | 
| 24 |  |  |  |  |  |  |  | 
| 25 | 1 |  |  |  |  | 20 | my $build_dir = path ($build->install_prop->{extract})->absolute; | 
| 26 |  |  |  |  |  |  |  | 
| 27 | 1 | 50 |  |  |  | 81 | if (!defined $build_dir) { | 
| 28 | 0 |  |  |  |  | 0 | $build->log ("Unable to determine build dir\n"); | 
| 29 | 0 |  |  |  |  | 0 | return; | 
| 30 |  |  |  |  |  |  | } | 
| 31 |  |  |  |  |  |  |  | 
| 32 |  |  |  |  |  |  | #  a spot of paranoia | 
| 33 |  |  |  |  |  |  | #return if $build_dir !~ /\b_alien\b/; | 
| 34 |  |  |  |  |  |  |  | 
| 35 | 1 |  |  |  |  | 6 | $build->log ("Going to delete $build_dir\n"); | 
| 36 | 1 |  |  |  |  | 139 | $build->log ("Currently in " . getcwd() . "\n"); | 
| 37 |  |  |  |  |  |  |  | 
| 38 | 1 |  |  |  |  | 33 | my $curdir = getcwd(); | 
| 39 | 1 | 50 |  |  |  | 6 | if (path($curdir)->subsumes ($build_dir)) { | 
| 40 | 0 |  |  |  |  | 0 | $build->log ("Going to parent of build directory\n"); | 
| 41 | 0 |  |  |  |  | 0 | chdir "$build_dir/.."; | 
| 42 |  |  |  |  |  |  | } | 
| 43 |  |  |  |  |  |  |  | 
| 44 | 1 |  | 50 |  |  | 192 | my $count = eval { | 
| 45 |  |  |  |  |  |  | remove_tree ($build_dir, { | 
| 46 |  |  |  |  |  |  | safe => 1, | 
| 47 |  |  |  |  |  |  | #verbose => 1, | 
| 48 |  |  |  |  |  |  | }); | 
| 49 |  |  |  |  |  |  | } || 0; | 
| 50 | 1 |  |  |  |  | 479 | $build->log ("Deleted $count items\n"); | 
| 51 | 1 |  |  |  |  | 15 | }); | 
| 52 |  |  |  |  |  |  |  | 
| 53 |  |  |  |  |  |  | } | 
| 54 |  |  |  |  |  |  |  | 
| 55 |  |  |  |  |  |  | 1; | 
| 56 |  |  |  |  |  |  |  | 
| 57 |  |  |  |  |  |  | __END__ |