4 use File::Basename qw(&basename &dirname);
7 # List explicitly here the variables you want Configure to
8 # generate. Metaconfig only looks for shell variables, so you
9 # have to mention them as if they were shell variables, not
10 # %Config entries. Thus you write
12 # to ensure Configure will look for $Config{startperl}.
14 # This forces PL files to create target in same directory as PL file.
15 # This is so that make depend always knows where to find PL derivatives.
18 $file = basename($0, '.PL');
19 $file .= '.com' if $^O eq 'VMS';
21 open OUT,">$file" or die "Can't create $file: $!";
23 print "Extracting $file (with variable substitutions)\n";
25 # In this section, perl variables will be expanded during extraction.
26 # You can use $Config{...} to use Configure variables.
28 print OUT <<"!GROK!THIS!";
30 eval 'exec $Config{perlpath} -S \$0 \${1+"\$@"}'
31 if \$running_under_some_shell;
34 # In the following, perl variables are not expanded during extraction.
36 print OUT <<'!NO!SUBS!';
40 pl2pm - Rough tool to translate Perl4 .pl files to Perl5 .pm modules.
48 B<pl2pm> is a tool to aid in the conversion of Perl4-style .pl
49 library files to Perl5-style library modules. Usually, your old .pl
50 file will still work fine and you should only use this tool if you
51 plan to update your library to use some of the newer Perl 5 features,
56 It's just a first step, but it's usually a good first step.
60 Larry Wall <larry@wall.org>
78 $newname =~ s/\.pl$/.pm/ || next;
79 $newname =~ s#(.*/)?(\w+)#$1\u$2#;
81 warn "Won't overwrite existing $newname\n";
88 s/\bstd(in|out|err)\b/\U$&/g;
89 s/(sub\s+)(\w+)(\s*\{[ \t]*\n)\s*package\s+$oldpack\s*;[ \t]*\n+/${1}main'$2$3/ig;
91 @export = m/sub\s+\w+'(\w+)/g;
92 s/(sub\s+)main'(\w+)/$1$2/g;
95 @export = m/sub\s+([A-Za-z]\w*)/g;
97 my @export_ok = grep($keyword{$_}, @export);
98 @export = grep(!$keyword{$_}, @export);
101 @export{@export} = (1) x @export;
104 s/(#.*)require ['"]$oldpack\.pl['"]/$1use $newpack/;
105 s/(package\s*)($oldpack)\s*;[ \t]*\n+//ig;
106 s/([\$\@%&*])'(\w+)/&xlate($1,"",$2,$newpack,$oldpack,\%export)/eg;
107 s/([\$\@%&*]?)(\w+)'(\w+)/&xlate($1,$2,$3,$newpack,$oldpack,\%export)/eg;
108 if (!/\$\[\s*\)?\s*=\s*[^0\s]/) {
109 s/^\s*(local\s*\()?\s*\$\[\s*\)?\s*=\s*0\s*;[ \t]*\n//g;
114 s/open\s+(\w+)/open($1)/g;
119 if (s/\bdie\b/croak/g) {
120 $carp = "use Carp;\n";
121 s/croak "([^"]*)\\n"/croak "$1"/g;
125 $export_ok = "\@EXPORT_OK = qw(@export_ok);\n";
128 if ( open(PM, ">$newname") ) {
134 \@ISA = qw(Exporter);
135 \@EXPORT = qw(@export);
141 warn "Can't create $newname: $!\n";
146 my ($prefix, $pack, $ident,$newpack,$oldpack,$export) = @_;
149 if ($prefix eq '' && $ident =~ /^(t|s|m|d|ing|ll|ed|ve|re)$/) {
150 $xlated = "${pack}'$ident";
152 elsif ($pack eq '' || $pack eq 'main') {
153 if ($export->{$ident}) {
154 $xlated = "$prefix$ident";
157 $xlated = "$prefix${pack}::$ident";
160 elsif ($pack eq $oldpack) {
161 $xlated = "$prefix${newpack}::$ident";
164 $xlated = "$prefix${pack}::$ident";
413 close OUT or die "Can't close $file: $!";
414 chmod 0755, $file or die "Can't reset permissions for $file: $!\n";
415 exec("$Config{'eunicefix'} $file") if $Config{'eunicefix'} ne ':';