Grabbed from www.makemaker.org.
Jarkko Hietaniemi [Thu, 24 Jul 2003 14:49:25 +0000 (14:49 +0000)]
p4raw-id: //depot/perl@20213

MANIFEST
t/lib/MakeMaker/Test/Setup/Recurs.pm [new file with mode: 0644]

index 5318778..e68ad81 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -2557,6 +2557,7 @@ t/lib/h2ph.pht                    Generated output from h2ph.h by h2ph, for comparison
 t/lib/locale/latin1            Part of locale.t in Latin 1
 t/lib/locale/utf8              Part of locale.t in UTF8
 t/lib/MakeMaker/Test/Utils.pm  MakeMaker test utilities
+t/lib/MakeMaker/Test/Setup/Recurs.pm MakeMaker test utilities
 t/lib/Math/BigFloat/Subclass.pm        Empty subclass of BigFloat for test
 t/lib/Math/BigInt/BareCalc.pm  Bigint's simulation of Calc
 t/lib/Math/BigInt/Subclass.pm  Empty subclass of BigInt for test
diff --git a/t/lib/MakeMaker/Test/Setup/Recurs.pm b/t/lib/MakeMaker/Test/Setup/Recurs.pm
new file mode 100644 (file)
index 0000000..affd870
--- /dev/null
@@ -0,0 +1,54 @@
+package MakeMaker::Test::Setup::Recurs;
+
+@ISA = qw(Exporter);
+require Exporter;
+@EXPORT = qw(setup_recurs teardown_recurs);
+
+use strict;
+use File::Path;
+use File::Basename;
+
+my %Files = (
+             'Recurs/Makefile.PL'          => <<'END',
+use ExtUtils::MakeMaker;
+
+WriteMakefile(
+    NAME          => 'Recurs',
+    VERSION       => 1.00,
+);
+END
+
+             'Recurs/prj2/Makefile.PL'     => <<'END',
+use ExtUtils::MakeMaker;
+
+WriteMakefile(
+    NAME => 'Recurs::prj2',
+    VERSION => 1.00,
+);
+END
+            );
+
+sub setup_recurs {
+    while(my($file, $text) = each %Files) {
+        # Convert to a relative, native file path.
+        $file = File::Spec->catfile(File::Spec->curdir, split m{\/}, $file);
+
+        my $dir = dirname($file);
+        mkpath $dir;
+        open(FILE, ">$file") || die "Can't create $file: $!";
+        print FILE $text;
+        close FILE;
+    }
+
+    return 1;
+}
+
+sub teardown_recurs { 
+    foreach my $file (keys %Files) {
+        my $dir = dirname($file);
+        if( -e $dir ) {
+            rmtree($dir) || return;
+        }
+    }
+    return 1;
+}