7 use File::Basename qw(&basename &dirname);
10 # List explicitly here the variables you want Configure to
11 # generate. Metaconfig only looks for shell variables, so you
12 # have to mention them as if they were shell variables, not
13 # %Config entries. Thus you write
15 # to ensure Configure will look for $Config{startperl}.
17 # This forces PL files to create target in same directory as PL file.
18 # This is so that make depend always knows where to find PL derivatives.
21 my $file = basename($0, '.PL');
22 $file .= '.com' if $^O eq 'VMS';
24 open OUT, ">", $file or die "Can't create $file: $!";
26 print "Extracting $file (with variable substitutions)\n";
28 # In this section, perl variables will be expanded during extraction.
29 # You can use $Config{...} to use Configure variables.
31 print OUT <<"!GROK!THIS!";
33 eval 'exec $Config{perlpath} -S \$0 \${1+"\$@"}'
34 if 0; # ^ Run only under a shell
37 # In the following, perl variables are not expanded during extraction.
39 print OUT <<'!NO!SUBS!';
43 pl2pm - Rough tool to translate Perl4 .pl files to Perl5 .pm modules.
51 B<pl2pm> is a tool to aid in the conversion of Perl4-style .pl
52 library files to Perl5-style library modules. Usually, your old .pl
53 file will still work fine and you should only use this tool if you
54 plan to update your library to use some of the newer Perl 5 features,
59 It's just a first step, but it's usually a good first step.
63 Larry Wall <larry@wall.org>
81 $newname =~ s/\.pl$/.pm/ || next;
82 $newname =~ s#(.*/)?(\w+)#$1\u$2#;
84 warn "Won't overwrite existing $newname\n";
91 s/\bstd(in|out|err)\b/\U$&/g;
92 s/(sub\s+)(\w+)(\s*\{[ \t]*\n)\s*package\s+$oldpack\s*;[ \t]*\n+/${1}main'$2$3/ig;
94 @export = m/sub\s+\w+'(\w+)/g;
95 s/(sub\s+)main'(\w+)/$1$2/g;
98 @export = m/sub\s+([A-Za-z]\w*)/g;
100 my @export_ok = grep($keyword{$_}, @export);
101 @export = grep(!$keyword{$_}, @export);
104 @export{@export} = (1) x @export;
107 s/(#.*)require ['"]$oldpack\.pl['"]/$1use $newpack/;
108 s/(package\s*)($oldpack)\s*;[ \t]*\n+//ig;
109 s/([\$\@%&*])'(\w+)/&xlate($1,"",$2,$newpack,$oldpack,\%export)/eg;
110 s/([\$\@%&*]?)(\w+)'(\w+)/&xlate($1,$2,$3,$newpack,$oldpack,\%export)/eg;
111 if (!/\$\[\s*\)?\s*=\s*[^0\s]/) {
112 s/^\s*(local\s*\()?\s*\$\[\s*\)?\s*=\s*0\s*;[ \t]*\n//g;
117 s/open\s+(\w+)/open($1)/g;
123 if (s/\bdie\b/croak/g) {
124 $carp = "use Carp;\n";
125 s/croak "([^"]*)\\n"/croak "$1"/g;
129 $export_ok = "\@EXPORT_OK = qw(@export_ok);\n";
132 if ( open(PM, ">", $newname) ) {
138 \@ISA = qw(Exporter);
139 \@EXPORT = qw(@export);
145 warn "Can't create $newname: $!\n";
150 my ($prefix, $pack, $ident,$newpack,$oldpack,$export) = @_;
153 if ($prefix eq '' && $ident =~ /^(t|s|m|d|ing|ll|ed|ve|re)$/) {
154 $xlated = "${pack}'$ident";
156 elsif ($pack eq '' || $pack eq 'main') {
157 if ($export->{$ident}) {
158 $xlated = "$prefix$ident";
161 $xlated = "$prefix${pack}::$ident";
164 elsif ($pack eq $oldpack) {
165 $xlated = "$prefix${newpack}::$ident";
168 $xlated = "$prefix${pack}::$ident";
417 close OUT or die "Can't close $file: $!";
418 chmod 0755, $file or die "Can't reset permissions for $file: $!\n";
419 exec("$Config{'eunicefix'} $file") if $Config{'eunicefix'} ne ':';