Upgrade to ExtUtils::MakeMaker 6.19
[p5sagit/p5-mst-13.2.git] / t / lib / MakeMaker / Test / Setup / Problem.pm
1 package MakeMaker::Test::Setup::Problem;
2
3 @ISA = qw(Exporter);
4 require Exporter;
5 @EXPORT = qw(setup_recurs teardown_recurs);
6
7 use strict;
8 use File::Path;
9 use File::Basename;
10
11 my %Files = (
12              'Problem-Module/Makefile.PL'   => <<'END',
13 use ExtUtils::MakeMaker;
14
15 WriteMakefile(
16     NAME    => 'Problem::Module',
17 );
18 END
19
20              'Problem-Module/subdir/Makefile.PL'    => <<'END',
21 printf "\@INC %s .\n", (grep { $_ eq '.' } @INC) ? "has" : "doesn't have";
22
23 warn "I think I'm going to be sick\n";
24 die "YYYAaaaakkk\n";
25 END
26
27 );
28
29
30 sub setup_recurs {
31     while(my($file, $text) = each %Files) {
32         # Convert to a relative, native file path.
33         $file = File::Spec->catfile(File::Spec->curdir, split m{\/}, $file);
34
35         my $dir = dirname($file);
36         mkpath $dir;
37         open(FILE, ">$file") || die "Can't create $file: $!";
38         print FILE $text;
39         close FILE;
40     }
41
42     return 1;
43 }
44
45 sub teardown_recurs { 
46     foreach my $file (keys %Files) {
47         my $dir = dirname($file);
48         if( -e $dir ) {
49             rmtree($dir) || return;
50         }
51     }
52     return 1;
53 }
54
55
56 1;