4
4
5
5
use strict;
6
6
use warnings;
7
+ use 5.010001;
8
+
9
+ exit main();
7
10
8
11
# ############################
9
12
# Custom packer that will only pack Text::PerlPP and Getopt::Long.
@@ -16,72 +19,112 @@ use warnings;
16
19
17
20
use parent ' App::FatPacker' ;
18
21
22
+ # sub trace {
23
+ # my $self = shift;
24
+ # say STDERR "Entering trace(); \@INC contains:\n", join("\n", @INC);
25
+ # $self->SUPER::trace(@_);
26
+ # }
27
+
19
28
sub collect_files {
20
29
my ($self , $dir , $files ) = @_ ;
21
30
22
31
my %innerfiles ;
23
32
$self -> SUPER::collect_files($dir , \%innerfiles );
24
33
my @filenames = grep { m { Text/PerlPP} || m { Getopt/Long} } keys %innerfiles ;
25
34
@{$files }{@filenames } = @innerfiles {@filenames };
26
- }
35
+ } # MyPacker::collect_files()
27
36
28
37
# ############################
29
- # Main routine
30
38
31
39
package main ;
32
40
33
- my $packer = MyPacker-> new;
34
- my $packed ;
41
+ sub update_environment {
42
+ # Make sure PERL5LIB has everything in @INC - somehow the lib directory
43
+ # is getting lost on perl 5.10.1 (perlbrew, cygwin x86).
44
+ # say STDERR "\@INC contains:\n", join("\n", @INC);
45
+ # say STDERR "PERL5LIB is ", $ENV{PERL5LIB} // "<<undef>>";
46
+
47
+ my $path_sep ;
48
+ my $separ = qx{ $^X -V:path_sep} ;
49
+ $separ =~ s / ^\$ ?/ \$ / ;
50
+ eval $separ ; # updates $path_sep
51
+
52
+ my $paths = join ($path_sep , @INC );
53
+ unless ($ENV {PERL5LIB }) {
54
+ $ENV {PERL5LIB } = $paths ;
55
+ } else {
56
+ $ENV {PERL5LIB } =~ s / $path_sep?$/ $path_sep$paths / ;
57
+ }
58
+ # say STDERR "PERL5LIB is now $ENV{PERL5LIB}";
59
+ } # update_environment()
60
+
61
+ # ############################
62
+ # Main routine
35
63
36
- do {
37
- open my $savedstdout , ' >&' , STDOUT or die $! ; # save stdout
38
- close STDOUT ;
64
+ sub main {
65
+ update_environment;
39
66
40
- open STDOUT , ' >>' , \$packed ; # capture packed text on stdout
41
- $packer -> script_command_pack([' bin/perlpp' ]);
42
- close STDOUT ;
67
+ my $packer = MyPacker-> new;
68
+ my $packed ;
43
69
44
- open STDOUT , ' >&' , $savedstdout ; # restore stdout
45
- };
70
+ say STDERR " Packing..." ;
71
+ do {
72
+ open my $savedstdout , ' >&' , STDOUT or die $! ; # save stdout
73
+ close STDOUT ;
46
74
47
- # Clean up, and move the Text::PerlPP pod where pod2usage can find it
75
+ open STDOUT , ' >>' , \$packed ; # capture packed text on stdout
76
+ $packer -> script_command_pack([' bin/perlpp' ]);
77
+ close STDOUT ;
48
78
49
- my @lines ; # For the source
50
- my @podlines ; # For the POD we're going to move
79
+ open STDOUT , ' >&' , $savedstdout ; # restore stdout
80
+ };
81
+ say STDERR " ...done" ;
51
82
52
- my ($in_getopt , $in_text , $in_doc );
53
- open my $iter , ' <' , \$packed ;
83
+ # Clean up, and move the Text::PerlPP pod where pod2usage can find it
54
84
55
- while (<$iter >) {
56
- chomp ;
57
- s /\s +$// ;
85
+ my @lines ; # For the source
86
+ my @podlines ; # For the POD we're going to move
58
87
59
- $in_getopt = m { fatpacked\S +Getopt/Long} .. m { ^GETOPT_LONG} ;
60
- $in_text = m { fatpacked\S +Text/PerlPP} .. m { ^TEXT_PERLPP} ;
61
- $in_doc = /^ =head1 NAME/ .. /^ =cut/;
62
- # have to test indentation level because the POD for Getopt::Long
63
- # includes a quoted POD sample
88
+ my ($in_getopt , $in_text , $in_doc );
64
89
65
- # print STDERR "$in_getopt\t$in_text\t$in_doc\t$_\n";
90
+ say STDERR " Cleanup..." ;
91
+ open my $iter , ' <' , \$packed ;
66
92
67
- next if $in_getopt && $in_doc ; # no POD for Getopt::Long
68
- if ($in_text && $in_doc && ($in_text !~ / E0$ / )) {
69
- s / ^ // ;
70
- push @podlines , $_ ;
71
- } else {
72
- push @lines , $_ if $_ ;
93
+ while (<$iter >) {
94
+ chomp ;
95
+ s /\s +$// ;
96
+
97
+ $in_getopt = m { fatpacked\S +Getopt/Long} .. m { ^GETOPT_LONG} ;
98
+ $in_text = m { fatpacked\S +Text/PerlPP} .. m { ^TEXT_PERLPP} ;
99
+ $in_doc = /^ =head1 NAME/ .. /^ =cut/;
100
+ # have to test indentation level because the POD for Getopt::Long
101
+ # includes a quoted POD sample
102
+
103
+ # print STDERR "$in_getopt\t$in_text\t$in_doc\t$_\n";
104
+
105
+ next if $in_getopt && $in_doc ; # no POD for Getopt::Long
106
+ if ($in_text && $in_doc && ($in_text !~ / E0$ / )) {
107
+ s / ^ // ;
108
+ push @podlines , $_ ;
109
+ } else {
110
+ push @lines , $_ if $_ ;
111
+ }
73
112
}
74
- }
75
- close $iter ;
76
- undef $packed ;
77
-
78
- # Output in the appropriate order
79
- open my $fh , ' >' , ' blib/perlpp' ;
80
- print $fh " $_ \n " for @lines ;
81
- print $fh " __END__\n =pod\n\n " ;
82
- print $fh " $_ \n " for @podlines ;
83
- close $fh ;
84
-
85
- print STDERR " Done packing\n " ;
113
+ close $iter ;
114
+ undef $packed ;
115
+ say STDERR " ...done" ;
116
+
117
+ # Output in the appropriate order
118
+ say STDERR " Generating blib/perlpp..." ;
119
+ open my $fh , ' >' , ' blib/perlpp' ;
120
+ print $fh " $_ \n " for @lines ;
121
+ print $fh " __END__\n =pod\n\n " ;
122
+ print $fh " $_ \n " for @podlines ;
123
+ close $fh ;
124
+
125
+ print STDERR " Done packing\n " ;
126
+
127
+ return 0;
128
+ } # main()
86
129
87
130
# vi: set ts=4 sts=4 sw=4 et ai: #
0 commit comments