t/lib/Test/Cleanup.pm
raw| 1 | package Test::Cleanup; |
| 2 | |
| 3 | use strict; |
| 4 | use warnings; |
| 5 | use Exporter qw( import ); |
| 6 | use File::Path qw( rmtree ); |
| 7 | |
| 8 | our @EXPORT = qw( cleanup ); |
| 9 | |
| 10 | my @cleanup; |
| 11 | |
| 12 | sub cleanup |
| 13 | { |
| 14 | push @cleanup, @_; |
| 15 | } |
| 16 | |
| 17 | END |
| 18 | { |
| 19 | foreach my $item (@cleanup) |
| 20 | { |
| 21 | if(ref $item eq 'CODE') |
| 22 | { |
| 23 | $item->(); |
| 24 | } |
| 25 | else |
| 26 | { |
| 27 | rmtree("$item", { verbose => 0 }); |
| 28 | } |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | 1; |