2 eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
3 if $running_under_some_shell;
7 pl2pm - Rough tool to translate Perl4 .pl files to Perl5 .pm modules.
15 B<pl2pm> is a tool to aid in the conversion of Perl4-style .pl
16 library files to Perl5-style library modules. Usually, your old .pl
17 file will still work fine and you should only use this tool if you
18 plan to update your library to use some of the newer Perl 5 features,
23 It's just a first step, but it's usually a good first step.
27 Larry Wall <larry@wall.org>
45 $newname =~ s/\.pl$/.pm/ || next;
46 $newname =~ s
#(.*/)?(\w+)#$1\u$2#;
48 warn "Won't overwrite existing $newname\n";
55 s/\bstd(in|out|err)\b/\U$&/g;
56 s/(sub\s+)(\w+)(\s*\{[ \t]*\n)\s*package\s+$oldpack\s*;[ \t]*\n+/${1}main'$2$3/ig;
58 @export = m/sub\s+\w+'(\w+)/g;
59 s/(sub\s+)main'(\w+)/$1$2/g;
62 @export = m/sub\s+([A-Za-z]\w*)/g;
64 my @export_ok = grep($keyword{$_}, @export);
65 @export = grep(!$keyword{$_}, @export);
68 @export{@export} = (1) x
@export;
71 s/(#.*)require ['"]$oldpack\.pl['"]/$1use $newpack/;
72 s/(package\s*)($oldpack)\s*;[ \t]*\n+//ig;
73 s/([\$\@%&*])'(\w+)/&xlate($1,"",$2,$newpack,$oldpack,\%export)/eg;
74 s/([\$\@%&*]?)(\w+)'(\w+)/&xlate($1,$2,$3,$newpack,$oldpack,\%export)/eg;
75 if (!/\$\[\s*\)?\s*=\s*[^0\s]/) {
76 s/^\s*(local\s*\()?\s*\$\[\s*\)?\s*=\s*0\s*;[ \t]*\n//g;
81 s/open\s+(\w+)/open($1)/g;
87 if (s/\bdie\b/croak/g) {
88 $carp = "use Carp;\n";
89 s/croak "([^"]*)\\n"/croak "$1"/g;
93 $export_ok = "\@EXPORT_OK = qw(@export_ok);\n";
96 if ( open(PM
, ">$newname") ) {
102 \@ISA = qw(Exporter);
103 \
@EXPORT = qw(@export);
109 warn "Can't create $newname: $!\n";
114 my ($prefix, $pack, $ident,$newpack,$oldpack,$export) = @_;
117 if ($prefix eq '' && $ident =~ /^(t|s|m|d|ing|ll|ed|ve|re)$/) {
118 $xlated = "${pack}'$ident";
120 elsif ($pack eq '' || $pack eq 'main') {
121 if ($export->{$ident}) {
122 $xlated = "$prefix$ident";
125 $xlated = "$prefix${pack}::$ident";
128 elsif ($pack eq $oldpack) {
129 $xlated = "$prefix${newpack}::$ident";
132 $xlated = "$prefix${pack}::$ident";