4 use File::Basename qw(&basename &dirname);
6 # List explicitly here the variables you want Configure to
7 # generate. Metaconfig only looks for shell variables, so you
8 # have to mention them as if they were shell variables, not
9 # %Config entries. Thus you write
11 # to ensure Configure will look for $Config{startperl}.
13 # This forces PL files to create target in same directory as PL file.
14 # This is so that make depend always knows where to find PL derivatives.
16 $file = basename($0, '.PL');
18 open OUT,">$file" or die "Can't create $file: $!";
20 print "Extracting $file (with variable substitutions)\n";
22 # In this section, perl variables will be expanded during extraction.
23 # You can use $Config{...} to use Configure variables.
25 print OUT <<"!GROK!THIS!";
27 eval 'exec $Config{perlpath} -S \$0 \${1+"\$@"}'
28 if \$running_under_some_shell;
31 # In the following, perl variables are not expanded during extraction.
33 print OUT <<'!NO!SUBS!';
37 pl2pm - Rough tool to translate Perl4 .pl files to Perl5 .pm modules.
45 B<pl2pm> is a tool to aid in the conversion of Perl4-style .pl
46 library files to Perl5-style library modules. Usually, your old .pl
47 file will still work fine and you should only use this tool if you
48 plan to update your library to use some of the newer Perl 5 features,
53 It's just a first step, but it's usually a good first step.
57 Larry Wall <larry@wall.org>
70 $newname =~ s/\.pl$/.pm/ || next;
71 $newname =~ s#(.*/)?(\w+)#$1\u$2#;
73 warn "Won't overwrite existing $newname\n";
79 print "$oldpack => $newpack\n" if $verbose;
81 s/\bstd(in|out|err)\b/\U$&/g;
82 s/(sub\s+)(\w+)(\s*\{[ \t]*\n)\s*package\s+$oldpack\s*;[ \t]*\n+/${1}main'$2$3/ig;
84 @export = m/sub\s+main'(\w+)/g;
85 s/(sub\s+)main'(\w+)/$1$2/g;
88 @export = m/sub\s+([A-Za-z]\w*)/g;
90 @export_ok = grep($keyword{$_}, @export);
91 @export = grep(!$keyword{$_}, @export);
92 @export{@export} = (1) x @export;
94 s/(#.*)require ['"]$oldpack\.pl['"]/$1use $newpack/;
95 s/(package\s*)($oldpack)\s*;[ \t]*\n+//ig;
96 s/([\$\@%&*])'(\w+)/&xlate($1,"",$2)/eg;
97 s/([\$\@%&*]?)(\w+)'(\w+)/&xlate($1,$2,$3)/eg;
98 if (!/\$\[\s*\)?\s*=\s*[^0\s]/) {
99 s/^\s*(local\s*\()?\s*\$\[\s*\)?\s*=\s*0\s*;[ \t]*\n//g;
104 s/open\s+(\w+)/open($1)/g;
106 if (s/\bdie\b/croak/g) {
107 $carp = "use Carp;\n";
108 s/croak "([^"]*)\\n"/croak "$1"/g;
114 $export_ok = "\@EXPORT_OK = qw(@export_ok);\n";
120 open(PM, ">$newname") || warn "Can't create $newname: $!\n";
126 \@ISA = qw(Exporter);
127 \@EXPORT = qw(@export);
134 local($prefix, $pack, $ident) = @_;
135 if ($prefix eq '' && $ident =~ /^(t|s|m|d|ing|ll|ed|ve|re)$/) {
138 elsif ($pack eq "" || $pack eq "main") {
139 if ($export{$ident}) {
143 "$prefix${pack}::$ident";
146 elsif ($pack eq $oldpack) {
147 "$prefix${newpack}::$ident";
150 "$prefix${pack}::$ident";
383 close OUT or die "Can't close $file: $!";
384 chmod 0755, $file or die "Can't reset permissions for $file: $!\n";
385 exec("$Config{'eunicefix'} $file") if $Config{'eunicefix'} ne ':';