home *** CD-ROM | disk | FTP | other *** search
/ Chip: Windows 2000 Professional Resource Kit / W2KPRK.iso / apps / perl / ActivePerl.exe / data.z / pl2pm.bat < prev    next >
Encoding:
DOS Batch File  |  1999-10-16  |  4.8 KB  |  365 lines

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