File: make_manifest.pl

package info (click to toggle)
libdigest-jhash-perl 0.10-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 172 kB
  • sloc: perl: 297; makefile: 3
file content (244 lines) | stat: -rw-r--r-- 5,869 bytes parent folder | download | duplicates (4)
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
#!/usr/bin/perl -w

# make_manifest.pl - get ready to tarball a module for CPAN
# It makes really clean, writes  a /html dir from the .pm pod,
# writes an accurate manifest and then fixes up all the line endings.

use strict;
use Pod::Html;
use Cwd;

chdir ".." if cwd =~ m/misc$/;

my $backup = 0;
my $root = shift @ARGV || '.'; #'../;
$root =~ tr|\\|/|;
$root = "$root/" unless $root =~ m|/$|;

write_file("SIGNATURE");
write_file("META.yml");
make_clean($root);
my $htmldir = $root."html/";
mkdir $htmldir, 0777;      # make the html dir
unlink <$htmldir*>;        # make sure it is empty

# write license file
require Software::License::Artistic_2_0;
unless ($@) {
    my $license = Software::License::Artistic_2_0->new({holder => 'James Freeman',});
    open F, ">../LICENSE" or die "Can't write LICENSE $!\n";
    print F $license->fulltext;
    close F;
}

my ( $dirs, $files ) = recurse_tree($root);
my @files;
# erase any undesirable files ie .bak, .pbp
for (@$files) {
    unlink, next if m/\.(?:pbp|bak|gz)$/;
    push @files, $_; # add files that we don't erase
}

# write the HTML
write_file( $htmldir."docs.css", (join'',<DATA>) ); # write the css
push @files, $htmldir."docs.css";
for my $pm (grep { m/\.pm$/  } @files ) {
    my $name = make_html($pm);
    push @files, $htmldir.$name;
}

# clean up after pod2html!
unlink <./pod2htm*>;

# write the MANIFEST;
unshift @files, $root.'MANIFEST';
write_file( $root."MANIFEST", (join"\n", map{ m/\Q$root\E(.*)/o ;$1 }@files) );

# fix line endings
fix_line_endings($_) for @files;

# remove all the makefile/make rubbish
sub make_clean {
    my $root = shift;
    my ($dirs, $files) = recurse_tree( $root."blib/" );
    my @dirs  = @$dirs;
    my @files = @$files;
    unlink for @files;
    # need to do longest dir paths first - must be deepest
    rmdir for sort {length $b <=> length $a }@dirs;
    my @makefiles = grep { /makefile(?!\.PL)/i } <$root*>;
    unlink for ( @makefiles, $root.'&1', $root.'pm_to_blib', $root.'MANIFEST', $root.'manifest' );
    unlink <${root}pod2htm*>;
}

# recurse the directory tree
sub recurse_tree {
    my $root = shift;
    my @files;
    my @dirs = ($root);
    for my $dir (@dirs) {
        opendir DIR, $dir or next;
        while (my $file = readdir DIR) {
          next if $file eq '.' or $file eq '..';
          next if  -l "$dir$file";
            if ( -d "$dir$file" ) {
                push @dirs,  "$dir$file/";
            }
            elsif ( -f "$dir$file" ) {
                push @files, "$dir$file";
            }
        }
        closedir DIR;
    }
  return \@dirs, \@files;
}

# clean windows line ending away
sub fix_line_endings {
    my $file = shift;
    return if $file =~ m/.bat$/;
    local $/;
    open my $fh, "+<$file" or die "Can't open $file for R/W $!\n";
    binmode $fh;
    my $data = <$fh>;
    write_file( "$file.bak" , $data ) if $backup;
    $data =~ s/\015\012/\012/g;
    $data =~ s/ +\012/\012/g;
    $data =~ s/\t/    /g;
    seek $fh, 0, 0;
    truncate $fh, 0;
    print $fh $data;
    close $fh;
    $file =~ s/\Q$root\E//o;
    print "Processed $file\n";
}

# make HTML from the pod
sub make_html {
    my $file = shift;
    (my $name) = $file =~ m/([^\/\\]+)\.pm$/;
    print "Writing html/$name.html\n";
    pod2html(   "--infile=$file",
                "--header",
                "--title=$name.pm",
                "--css=${htmldir}docs.css",
                "--outfile=$htmldir$name.html",
                "--quiet" );
  return "$name.html";
}

sub write_file {
    my $file = shift;
    open F, ">$file" or die "Can't write $file: $!\n";
    print F for @_;
    close F;
}

__DATA__
BODY {
    font: small verdana, arial, helvetica, sans-serif;
    color: black;
    background-color: white;
}

A:link    {color: #0000FF}
A:visited     {color: #666666}
A:active     {color: #FF0000}

H1 {
    font: bold large verdana, arial, helvetica, sans-serif;
    color: black;
}
H2 {
    font: bold large verdana, arial, helvetica, sans-serif;
    color: maroon;
}
H3 {
    font: bold medium verdana, arial, helvetica, sans-serif;
        color: blue;
}
H4 {
    font: bold small verdana, arial, helvetica, sans-serif;
        color: maroon;
}
H5 {
    font: bold small verdana, arial, helvetica, sans-serif;
        color: blue;
}
H6 {
    font: bold small verdana, arial, helvetica, sans-serif;
        color: black;
}
UL {
    font: small verdana, arial, helvetica, sans-serif;
        color: black;
}
OL {
    font: small verdana, arial, helvetica, sans-serif;
        color: black;
}
LI {
    font: small verdana, arial, helvetica, sans-serif;
    color: black;
}
TH {
    font: small verdana, arial, helvetica, sans-serif;
    color: black;
}
TD {
    font: small verdana, arial, helvetica, sans-serif;
    color: black;
}
TD.foot {
     font: medium sans-serif;
     color: #eeeeee;
    background-color="#cc0066"
}
DL {
    font: small verdana, arial, helvetica, sans-serif;
    color: black;
}
DD {
    font: small verdana, arial, helvetica, sans-serif;
    color: black;
}
DT {
    font: small verdana, arial, helvetica, sans-serif;
        color: black;
}
CODE {
    font: Courier, monospace;
}
PRE {
    font: Courier, monospace;
}
P.indent {
    font: small verdana, arial, helvetica, sans-serif;
    color: black;
    background-color: white;
    list-style-type : circle;
    list-style-position : inside;
    margin-left : 16.0pt;
}
PRE.programlisting
{
    font-size : 9.0pt;
    list-style-type : disc;
    margin-left : 16.0pt;
    margin-top : -14.0pt;
}
INPUT {
    font: bold small verdana, arial, helvetica, sans-serif;
    color: black;
    background-color: white;
}
TEXTAREA {
    font: bold small verdana, arial, helvetica, sans-serif;
    color: black;
    background-color: white;
}
.BANNER {
    background-color: "#cccccc";
    font: bold medium verdana, arial, helvetica, sans-serif;
}