source: for-distributions/trunk/bin/windows/perl/bin/pl2pm.bat@ 14489

Last change on this file since 14489 was 14489, checked in by oranfry, 17 years ago

upgrading to perl 5.8

File size: 4.8 KB
Line 
1@rem = '--*-Perl-*--
2@echo off
3if "%OS%" == "Windows_NT" goto WinNT
4perl -x -S "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9
5goto endofperl
6:WinNT
7perl -x -S %0 %*
8if NOT "%COMSPEC%" == "%SystemRoot%\system32\cmd.exe" goto endofperl
9if %errorlevel% == 9009 echo You do not have Perl in your PATH.
10if errorlevel 1 goto script_failed_so_exit_with_non_zero_val 2>nul
11goto endofperl
12@rem ';
13#!perl
14#line 15
15 eval 'exec c:\shaoqunWu\perl\bin\perl.exe -S $0 ${1+"$@"}'
16 if $running_under_some_shell;
17
18=head1 NAME
19
20pl2pm - Rough tool to translate Perl4 .pl files to Perl5 .pm modules.
21
22=head1 SYNOPSIS
23
24B<pl2pm> F<files>
25
26=head1 DESCRIPTION
27
28B<pl2pm> is a tool to aid in the conversion of Perl4-style .pl
29library files to Perl5-style library modules. Usually, your old .pl
30file will still work fine and you should only use this tool if you
31plan to update your library to use some of the newer Perl 5 features,
32such as AutoLoading.
33
34=head1 LIMITATIONS
35
36It's just a first step, but it's usually a good first step.
37
38=head1 AUTHOR
39
40Larry Wall <[email protected]>
41
42=cut
43
44use strict;
45use warnings;
46
47my %keyword = ();
48
49while (<DATA>) {
50 chomp;
51 $keyword{$_} = 1;
52}
53
54local $/;
55
56while (<>) {
57 my $newname = $ARGV;
58 $newname =~ s/\.pl$/.pm/ || next;
59 $newname =~ s#(.*/)?(\w+)#$1\u$2#;
60 if (-f $newname) {
61 warn "Won't overwrite existing $newname\n";
62 next;
63 }
64 my $oldpack = $2;
65 my $newpack = "\u$2";
66 my @export = ();
67
68 s/\bstd(in|out|err)\b/\U$&/g;
69 s/(sub\s+)(\w+)(\s*\{[ \t]*\n)\s*package\s+$oldpack\s*;[ \t]*\n+/${1}main'$2$3/ig;
70 if (/sub\s+\w+'/) {
71 @export = m/sub\s+\w+'(\w+)/g;
72 s/(sub\s+)main'(\w+)/$1$2/g;
73 }
74 else {
75 @export = m/sub\s+([A-Za-z]\w*)/g;
76 }
77 my @export_ok = grep($keyword{$_}, @export);
78 @export = grep(!$keyword{$_}, @export);
79
80 my %export = ();
81 @export{@export} = (1) x @export;
82
83 s/(^\s*);#/$1#/g;
84 s/(#.*)require ['"]$oldpack\.pl['"]/$1use $newpack/;
85 s/(package\s*)($oldpack)\s*;[ \t]*\n+//ig;
86 s/([\$\@%&*])'(\w+)/&xlate($1,"",$2,$newpack,$oldpack,\%export)/eg;
87 s/([\$\@%&*]?)(\w+)'(\w+)/&xlate($1,$2,$3,$newpack,$oldpack,\%export)/eg;
88 if (!/\$\[\s*\)?\s*=\s*[^0\s]/) {
89 s/^\s*(local\s*\()?\s*\$\[\s*\)?\s*=\s*0\s*;[ \t]*\n//g;
90 s/\$\[\s*\+\s*//g;
91 s/\s*\+\s*\$\[//g;
92 s/\$\[/0/g;
93 }
94 s/open\s+(\w+)/open($1)/g;
95
96 my $export_ok = '';
97 my $carp ='';
98
99
100 if (s/\bdie\b/croak/g) {
101 $carp = "use Carp;\n";
102 s/croak "([^"]*)\\n"/croak "$1"/g;
103 }
104
105 if (@export_ok) {
106 $export_ok = "\@EXPORT_OK = qw(@export_ok);\n";
107 }
108
109 if ( open(PM, ">$newname") ) {
110 print PM <<"END";
111package $newpack;
112use 5.006;
113require Exporter;
114$carp
115\@ISA = qw(Exporter);
116\@EXPORT = qw(@export);
117$export_ok
118$_
119END
120 }
121 else {
122 warn "Can't create $newname: $!\n";
123 }
124}
125
126sub xlate {
127 my ($prefix, $pack, $ident,$newpack,$oldpack,$export) = @_;
128
129 my $xlated ;
130 if ($prefix eq '' && $ident =~ /^(t|s|m|d|ing|ll|ed|ve|re)$/) {
131 $xlated = "${pack}'$ident";
132 }
133 elsif ($pack eq '' || $pack eq 'main') {
134 if ($export->{$ident}) {
135 $xlated = "$prefix$ident";
136 }
137 else {
138 $xlated = "$prefix${pack}::$ident";
139 }
140 }
141 elsif ($pack eq $oldpack) {
142 $xlated = "$prefix${newpack}::$ident";
143 }
144 else {
145 $xlated = "$prefix${pack}::$ident";
146 }
147
148 return $xlated;
149}
150__END__
151AUTOLOAD
152BEGIN
153CORE
154DESTROY
155END
156INIT
157CHECK
158abs
159accept
160alarm
161and
162atan2
163bind
164binmode
165bless
166caller
167chdir
168chmod
169chomp
170chop
171chown
172chr
173chroot
174close
175closedir
176cmp
177connect
178continue
179cos
180crypt
181dbmclose
182dbmopen
183defined
184delete
185die
186do
187dump
188each
189else
190elsif
191endgrent
192endhostent
193endnetent
194endprotoent
195endpwent
196endservent
197eof
198eq
199eval
200exec
201exists
202exit
203exp
204fcntl
205fileno
206flock
207for
208foreach
209fork
210format
211formline
212ge
213getc
214getgrent
215getgrgid
216getgrnam
217gethostbyaddr
218gethostbyname
219gethostent
220getlogin
221getnetbyaddr
222getnetbyname
223getnetent
224getpeername
225getpgrp
226getppid
227getpriority
228getprotobyname
229getprotobynumber
230getprotoent
231getpwent
232getpwnam
233getpwuid
234getservbyname
235getservbyport
236getservent
237getsockname
238getsockopt
239glob
240gmtime
241goto
242grep
243gt
244hex
245if
246index
247int
248ioctl
249join
250keys
251kill
252last
253lc
254lcfirst
255le
256length
257link
258listen
259local
260localtime
261lock
262log
263lstat
264lt
265m
266map
267mkdir
268msgctl
269msgget
270msgrcv
271msgsnd
272my
273ne
274next
275no
276not
277oct
278open
279opendir
280or
281ord
282our
283pack
284package
285pipe
286pop
287pos
288print
289printf
290prototype
291push
292q
293qq
294qr
295quotemeta
296qw
297qx
298rand
299read
300readdir
301readline
302readlink
303readpipe
304recv
305redo
306ref
307rename
308require
309reset
310return
311reverse
312rewinddir
313rindex
314rmdir
315s
316scalar
317seek
318seekdir
319select
320semctl
321semget
322semop
323send
324setgrent
325sethostent
326setnetent
327setpgrp
328setpriority
329setprotoent
330setpwent
331setservent
332setsockopt
333shift
334shmctl
335shmget
336shmread
337shmwrite
338shutdown
339sin
340sleep
341socket
342socketpair
343sort
344splice
345split
346sprintf
347sqrt
348srand
349stat
350study
351sub
352substr
353symlink
354syscall
355sysopen
356sysread
357sysseek
358system
359syswrite
360tell
361telldir
362tie
363tied
364time
365times
366tr
367truncate
368uc
369ucfirst
370umask
371undef
372unless
373unlink
374unpack
375unshift
376untie
377until
378use
379utime
380values
381vec
382wait
383waitpid
384wantarray
385warn
386while
387write
388x
389xor
390y
391
392__END__
393:endofperl
Note: See TracBrowser for help on using the repository browser.