forked from vti/bootylicious
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsquash
executable file
·88 lines (71 loc) · 1.74 KB
/
squash
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
81
82
83
84
85
86
87
88
#!/usr/bin/env perl
use warnings;
use strict;
use File::Spec;
my $COMMENT = <<'COMMENT';
# This file is generated when building a
# distribution. DO NOT EDIT or send patches
# for it.
#
# If you found an error, fix files in lib/
# directory, then generate bootylicious script
# and make sure it works and then send a patch
# that fixes appropriate lib/ files.
#
# See source code at
# http://github.com/vti/bootylicious
#
COMMENT
my @code;
my @data;
my @pod;
my @files = @ARGV;
while (@files) {
my $file = shift @files;
if (-f $file) {
my $content = _read_file($file);
if ($file =~ m/\.pm/) {
$content =~ s/^package.*?\n//;
$content =~ s/^1;$//m;
if ($content =~ s/__DATA__(.*?)(?=__END__)//s) {
push @data, $1;
}
if ($content =~ s/__END__(.*)//s) {
push @pod, $1;
}
push @code, $content;
}
}
elsif (-d $file) {
push @files, _read_dir($file);
}
else {
warn "Unknown file: $file";
}
}
print "#!/usr/bin/env perl\n\n";
print $COMMENT;
print $_ for @code;
print q/shagadelic(@ARGV ? @ARGV : $config{'server'});/, "\n";
print "1;\n";
print "__DATA__\n\n";
print $_ for @data;
print "__END__\n\n";
print $_ for @pod;
sub _read_file {
my $file = shift;
warn "Reading file $file";
open FILE, "< $file" or die "Can't read file: $file: $!";
my $content;
$content = do { local $/; <FILE> };
close FILE;
return $content;
}
sub _read_dir {
my $dir = shift;
warn "Reading dir $dir";
opendir DIR, $dir or die "Can't open dir: $dir: $!";
my @files = grep {/^[^\.]/} readdir DIR;
closedir DIR;
return map { File::Spec->catfile($dir, $_) } @files;
}