| 1 |
#!/usr/bin/env perl |
| 2 |
# |
| 3 |
# This file is part of Dist-Metadata |
| 4 |
# |
| 5 |
# This software is copyright (c) 2011 by Randy Stauner. |
| 6 |
# |
| 7 |
# This is free software; you can redistribute it and/or modify it under |
| 8 |
# the same terms as the Perl 5 programming language system itself. |
| 9 |
# |
| 10 |
|
| 11 |
# This script is used for generating test data when the dist is built |
| 12 |
|
| 13 |
use strict; |
| 14 |
use warnings; |
| 15 |
use FindBin; # core |
| 16 |
use Archive::Any::Create; |
| 17 |
use File::Find; # core |
| 18 |
use Path::Class 0.24; |
| 19 |
use IO::File; # core |
| 20 |
use Data::Dumper (); # core |
| 21 |
|
| 22 |
my $work_dir = $FindBin::Bin; |
| 23 |
my $structs; |
| 24 |
my $dists = { |
| 25 |
metafile => { |
| 26 |
dir => 'Dist-Metadata-Test-MetaFile-2.2', |
| 27 |
}, |
| 28 |
metafile_incomplete => { |
| 29 |
dir => 'Dist-Metadata-Test-MetaFile-Incomplete-2.1', |
| 30 |
}, |
| 31 |
nometafile => { |
| 32 |
dir => 'Dist-Metadata-Test-NoMetaFile-0.1', |
| 33 |
}, |
| 34 |
nometafile_dev_release => { |
| 35 |
dir => 'Dist-Metadata-Test-NoMetaFile-DevRelease-0.1_1', |
| 36 |
}, |
| 37 |
index_like_pause => { |
| 38 |
dir => 'Dist-Metadata-Test-LikePause-0.1', |
| 39 |
}, |
| 40 |
subdir => { |
| 41 |
dir => 'Dist-Metadata-Test-SubDir-1.5', |
| 42 |
cd => 'subdir', |
| 43 |
}, |
| 44 |
noroot => { |
| 45 |
dir => '.', |
| 46 |
cd => 'noroot', |
| 47 |
file => 'noroot', |
| 48 |
}, |
| 49 |
}; |
| 50 |
|
| 51 |
while( my ($name, $dist) = each %$dists ){ |
| 52 |
my $archive = Archive::Any::Create->new; |
| 53 |
my $struct = {}; |
| 54 |
|
| 55 |
my $wd = $dist->{cd} |
| 56 |
? dir( $work_dir, $dist->{cd} ) |
| 57 |
: $work_dir; |
| 58 |
my $fd = dir( $wd, $dist->{dir} ); |
| 59 |
|
| 60 |
my @files; |
| 61 |
find({ |
| 62 |
wanted => sub { |
| 63 |
push @files, $_ |
| 64 |
if -f $_; |
| 65 |
}, |
| 66 |
no_chdir => 1, |
| 67 |
}, |
| 68 |
$fd |
| 69 |
); |
| 70 |
|
| 71 |
foreach my $file ( @files ){ |
| 72 |
my $rel = file($file)->relative($wd); |
| 73 |
my $content = slurp($file); |
| 74 |
$archive->add_file( $rel => $content ); |
| 75 |
# convert relative file path from Native to Unix since DM Struct defaults to Unix. |
| 76 |
$struct->{ $rel->as_foreign('Unix') } = $content; |
| 77 |
} |
| 78 |
|
| 79 |
my $base = $dist->{file} || $dist->{dir}; |
| 80 |
$archive->write_file(file($work_dir, "$base.$_")->stringify) |
| 81 |
for qw(tar.gz zip); |
| 82 |
$structs->{$name} = $struct; |
| 83 |
} |
| 84 |
|
| 85 |
{ |
| 86 |
local $Data::Dumper::Indent = 1; |
| 87 |
spit( |
| 88 |
file($work_dir, 'structs.pl'), |
| 89 |
Data::Dumper->Dump( [$structs], ['Dist::Metadata::Test::Structs'] ) |
| 90 |
); |
| 91 |
} |
| 92 |
|
| 93 |
sub slurp { local $/; IO::File->new($_[0], 'r')->getline } |
| 94 |
sub spit { IO::File->new($_[0], 'w')->print($_[1]) } |