File: encode_append.pl

package info (click to toggle)
libpar-packer-perl 1.063-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,380 kB
  • sloc: perl: 12,859; ansic: 1,486; makefile: 30; sh: 5
file content (56 lines) | stat: -rw-r--r-- 1,212 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
#!perl

use strict;
use warnings;
# Used in myldr/Makefile.PL / myldr/Makefile.
# This script appends the uuencoded contents of $ARGV[0] to the file
# specified as $ARGV[1] as __DATA__ section. Any previous _DATA_ is replaced.
# section.
#
# copyright 2006-2009, Steffen Mueller

$/ = undef;

my $usage = <<HERE;
Usage: $0 IN-FILE FILE-TO-ENCODE OUT-FILE
HERE

my $infile = shift @ARGV;
die $usage if not defined $infile or not -f $infile;

my $encfile = shift @ARGV;
die $usage if not defined $encfile or not -f $encfile;

my $outfile = shift @ARGV;
die $usage if not defined $outfile;

open my $in, '<', $infile or die $!;
binmode $in;
my $contents = <$in>;
close $in;

$contents =~ s/^__DATA__\r?\n.*\z//ms;

# cf. Config.pm
$contents .= sprintf <<'...', ($^V) x 2;
$^V eq %vd 
    or die sprintf("Perl (%%s) version (%%vd) doesn't match the version (%vd) ".
                   "that PAR::Packer was built with; please rebuild PAR::Packer", 
                   $^X, $^V);

1;
...


open my $enc, '<', $encfile or die $!;
binmode $enc;

unlink $outfile;
open my $out, '>', $outfile or die $!;
binmode $out;
print $out $contents;
print $out "\n__DATA__\n";
print $out pack 'u', <$enc>;
close $out;

close $enc;