-
Notifications
You must be signed in to change notification settings - Fork 1
/
makepm
executable file
·80 lines (70 loc) · 1.96 KB
/
makepm
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/perl
use strict;
use warnings FATAL => 'all';
use YAML qw( LoadFile Dump );
use Template;
use B::Keywords;
use Getopt::Long;
GetOptions(
'debug' => \my $debug,
'nomake' => \my $do_makefile,
);
$_ = $_ ? 1 : 0 for $debug;
$_ = $_ ? 0 : 1 for $do_makefile;
sub load_fns
{
my @fns = <fns/*.fn>;
my %fns;
for my $file (@fns) {
warn "$file...\n" if $debug;
my $data = LoadFile( $file );
$data->{name} ||= do {
$file =~ m[/([^.]+)] and $1;
};
die "$data->{name} has no docs!" unless length $data->{docs};
$fns{$data->{name}} = $data;
}
return \%fns;
}
sub inject
{
my ( $data) = @_;
my %perl = map { ($_,1) } @B::Keywords::Functions;
my @values = @{$data}{sort keys %$data};
chomp( my @synopses = grep defined, map { $_->{synopsis} } @values );
s/^/ /mg for @synopses;
defined $_->{synopsis} and $_->{synopsis} =~ s/^/ /mg for @values;
my %requirements = map { %$_ } grep defined, map { $_->{requirements} } @values;
my @autoinstall;
for ( @values )
{
next unless $_->{requirements};
push @autoinstall, {
name => $_->{name},
requirements => $_->{requirements},
};
}
for ( values %$data ) {
$_->{exports} ||= [ $_->{name} ];
delete $_->{exports} if exists $perl{$_->{name}};
$_->{badegg} = !$_->{code} && $_->{exports};
}
my $injection = {
autoinstall => \@autoinstall,
synopses => \@synopses,
requirements => \%requirements,
fns => $data,
};
my $tt = Template->new() or die $Template::ERROR;
return sub {
my ($in, $out) = @_;
warn "Formatting $in...\n";
$tt->process( $in, $injection, $out ) or die $tt->error();
};
}
{
my $fns = load_fns();
my $formatter = inject( $fns );
$formatter->( 'Strings.tt', 'Strings.pm' );
$formatter->( 'Makefile.tt', 'Makefile.PL' ) if $do_makefile;
}