forked from schweikert/mailgraph
-
Notifications
You must be signed in to change notification settings - Fork 0
/
embed.pl
executable file
·63 lines (57 loc) · 1.45 KB
/
embed.pl
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
#!/usr/bin/perl -w
use strict;
sub read_module($)
{
my $file = shift;
open(FILE, "<$file") or die "ERROR: can't open $file: $!\n";
my $code = '';
my ($name, $version);
my $in_pod = 0;
local $_;
while(<FILE>) {
# strip POD
if(/^=(head|item|back)/) { $in_pod = 1; next; }
if(/^=cut/) { $in_pod = 0; next; }
next if $in_pod;
# strip vim mode-lines
next if /^# vim?:/;
# strip empty lines
next if /^\s*$/;
# strip 1;
next if /^\s*1\s*;$/;
# strip __END__
next if /^__END__/;
# strip $VERSION
if(/\$VERSION\s*=\s*['"]?([^\s'"]+)/) {
$version = $1;
next;
}
# find out package name
if(/^package\s+([^\s;]*)/) {
$name = $1;
}
$code .= $_;
}
return ($name, $version, $code);
}
sub main
{
my $src = shift @ARGV;
defined $src > 0 or die "usage: embed.pl src\n";
open(SRC, "<$src") or die "ERROR: can't open $src: $!\n";
my %embedded = ();
while(<SRC>) {
if(/^## EMBED\((.*?)\)/) {
my ($name,$version,$code) = read_module($1);
print "######## $name $version (automatically embedded) ########\n";
print $code;
$embedded{$name}=1;
}
else {
next if /^use\s+([^\s;]+)/ and defined $embedded{$1};
print;
}
}
}
main;
# vi: sw=4 et