1package MakeMaker::Test::Setup::BFD;
2use strict;
3
4our @ISA = qw(Exporter);
5require Exporter;
6our @EXPORT = qw(setup_recurs teardown_recurs);
7
8use File::Path;
9use File::Basename;
10use MakeMaker::Test::Utils;
11
12my %Files = (
13             'Big-Dummy/lib/Big/Dummy.pm'     => <<'END',
14package Big::Dummy;
15
16$VERSION = 0.02;
17
18=head1 NAME
19
20Big::Dummy - Try "our" hot dog's
21
22=cut
23
241;
25END
26
27             'Big-Dummy/Makefile.PL'          => <<'END',
28use ExtUtils::MakeMaker;
29
30# This will interfere with the PREREQ_PRINT tests.
31printf "Current package is: %s\n", __PACKAGE__ unless "@ARGV" =~ /PREREQ/;
32
33WriteMakefile(
34    NAME          => 'Big::Dummy',
35    VERSION_FROM  => 'lib/Big/Dummy.pm',
36    EXE_FILES     => [qw(bin/program)],
37    PREREQ_PM     => { strict => 0 },
38    BUILD_REQUIRES => { warnings => 0 },
39    ABSTRACT_FROM => 'lib/Big/Dummy.pm',
40    AUTHOR        => 'Michael G Schwern <schwern@pobox.com>',
41);
42END
43
44             'Big-Dummy/bin/program'          => <<'END',
45#!/usr/bin/perl -w
46
47=head1 NAME
48
49program - this is a program
50
51=cut
52
531;
54END
55
56             'Big-Dummy/t/compile.t'          => <<'END',
57print "1..2\n";
58
59print eval "use Big::Dummy; 1;" ? "ok 1\n" : "not ok 1\n";
60print "ok 2 - TEST_VERBOSE\n";
61END
62
63             'Big-Dummy/Liar/t/sanity.t'      => <<'END',
64print "1..3\n";
65
66print eval "use Big::Dummy; 1;" ? "ok 1\n" : "not ok 1\n";
67print eval "use Big::Liar; 1;" ? "ok 2\n" : "not ok 2\n";
68print "ok 3 - TEST_VERBOSE\n";
69END
70
71             'Big-Dummy/Liar/lib/Big/Liar.pm' => <<'END',
72package Big::Liar;
73
74$VERSION = 0.01;
75
761;
77END
78
79             'Big-Dummy/Liar/Makefile.PL'     => <<'END',
80use ExtUtils::MakeMaker;
81
82my $mm = WriteMakefile(
83              NAME => 'Big::Liar',
84              VERSION_FROM => 'lib/Big/Liar.pm',
85              _KEEP_AFTER_FLUSH => 1
86             );
87
88print "Big::Liar's vars\n";
89foreach my $key (qw(INST_LIB INST_ARCHLIB)) {
90    print "$key = $mm->{$key}\n";
91}
92END
93
94             'Big-Dummy/lib/Dummy/Split.pm'     => <<'END',
95package Dummy::Split;
96$VERSION = 0.02;
97use AutoLoader 'AUTOLOAD';
98
99__END__
100
101sub split { print "split\n"; }
102
1031;
104END
105
106            );
107
108my $tmpdir;
109
110# if given args, those are inserted as components in resulting path, eg:
111# setup_recurs('dir') means instead of creating Big-Dummy/*, dir/Big-Dummy/*
112sub setup_recurs {
113    my @chrs = ( "A" .. "Z", 0 .. 9 );
114    # annoyingly we cant use File::Temp here as it drags in XS code
115    # and we run under blocks to prevent XS code loads. This is a minimal
116    # patch to fix the issue.
117    $tmpdir = join "", "./temp-$$-", map { $chrs[rand(@chrs)] } 1..8;
118    mkdir($tmpdir) or die "Failed to create '$tmpdir': $!";
119    chdir($tmpdir) or die "Failed to chdir '$tmpdir': $!";
120    foreach my $file (sort keys %Files) {
121        my $text = $Files{$file};
122        # Convert to a relative, native file path.
123        $file = File::Spec->catfile(File::Spec->curdir, @_, split m{\/}, $file);
124        $file = File::Spec->rel2abs($file);
125
126        my $dir = dirname($file);
127        mkpath $dir;
128        open(FILE, ">$file") || die "Can't create $file: $!";
129        print FILE $text;
130        close FILE;
131
132        # ensure file at least 1 second old for makes that assume
133        # files with the same time are out of date.
134        my $time = calibrate_mtime();
135        utime $time, $time - 1, $file;
136    }
137
138    return 1;
139}
140
141sub teardown_recurs {
142    foreach my $file (keys %Files) {
143        my $dir = dirname($file);
144        if( -e $dir ) {
145            rmtree($dir) or next;
146        }
147    }
148    chdir("..");
149    rmtree($tmpdir);
150    return 1;
151}
152
153
1541;
155