File: boilerplate.pl

package info (click to toggle)
libproc-fork-perl 0.806-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 140 kB
  • sloc: perl: 164; makefile: 2
file content (57 lines) | stat: -rw-r--r-- 1,563 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use strict; use warnings;

use CPAN::Meta;
use Software::LicenseUtils;
use Pod::Readme::Brief;

sub slurp { open my $fh, '<', $_[0] or die "Couldn't open $_[0] to read: $!\n"; readline $fh }

chdir $ARGV[0] or die "Cannot chdir to $ARGV[0]: $!\n";

my %file;

my $meta = CPAN::Meta->load_file( 'META.json' );

my $license = do {
	my @key = ( $meta->license, $meta->meta_spec_version );
	my ( $class, @ambiguous ) = Software::LicenseUtils->guess_license_from_meta_key( @key );
	die if @ambiguous;
	$class->new( $meta->custom( 'x_copyright' ) );
};

$file{'LICENSE'} = $license->fulltext;

my @source = slurp 'lib/Proc/Fork.pm';

my $i = -1;
while ( ++$i <= $#source ) {
	$source[$i] =~ /^=for eg (.*)/ or next;
	my $fn = "eg/$1";
	splice @source, $i, 2;
	mkdir 'eg';
	my @eg;
	while ( $i <= $#source ) {
		$source[$i] =~ /^(?:$| )/ or last;
		push @eg, $source[$i];
		s/^ //, s/\G {4}/\t/g for $eg[-1];
		++$i;
	}
	( $file{ $fn } = join '', @eg ) =~ s/\n+\z/\n/;
}

splice @source, -2, 0, "\n", $license->notice;
$file{'lib/Proc/Fork.pm'} = join '', @source;

die unless -e 'Makefile.PL';
$file{'README'} = Pod::Readme::Brief->new( @source )->render( installer => 'eumm' );

my @manifest = slurp 'MANIFEST';
my %manifest = map /\A([^\s#]+)()/, @manifest;
$file{'MANIFEST'} = join '', sort @manifest, map "$_\n", grep !exists $manifest{ $_ }, keys %file;

for my $fn ( sort keys %file ) {
	unlink $fn if -e $fn;
	open my $fh, '>', $fn or die "Couldn't open $fn to write: $!\n";
	print $fh $file{ $fn };
	close $fh or die "Couldn't close $fn after writing: $!\n";
}