This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
c2e9e16cda51d15b1d6e1167c44dcfab1120204e
[perl5.git] / cpan / Module-Metadata / t / lib / GeneratePackage.pm
1 use strict;
2 use warnings;
3 package GeneratePackage;
4 # vim:ts=8:sw=2:et:sta:sts=2
5
6 use base 'Exporter';
7 our @EXPORT = qw(tmpdir generate_file);
8
9 use Cwd;
10 use File::Spec;
11 use File::Path;
12 use File::Temp;
13 use IO::File;
14
15 sub tmpdir {
16   File::Temp::tempdir(
17     'MMD-XXXXXXXX',
18     CLEANUP => 0,
19     DIR => ($ENV{PERL_CORE} ? File::Spec->rel2abs(Cwd::cwd) : File::Spec->tmpdir),
20   );
21 }
22
23 sub generate_file {
24   my ($dir, $rel_filename, $content) = @_;
25
26   File::Path::mkpath($dir) or die "failed to create '$dir'";
27   my $abs_filename = File::Spec->catfile($dir, $rel_filename);
28
29   Test::More::note("working on $abs_filename");
30
31   my $fh = IO::File->new(">$abs_filename") or die "Can't write '$abs_filename'\n";
32   print $fh $content;
33   close $fh;
34
35   return $abs_filename;
36 }
37
38 1;