home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / perl / 5291 < prev    next >
Encoding:
Internet Message Format  |  1992-08-12  |  22.1 KB

  1. Path: sparky!uunet!eiffel!eiffel.com
  2. From: ram@eiffel.com (Raphael Manfredi)
  3. Newsgroups: comp.lang.perl
  4. Subject: Updated perload script for data/auto loading
  5. Summary: Added option -o for optimized dataloading
  6. Keywords: perl, autoloading, dataloading, speed
  7. Message-ID: <113@eiffel.eiffel.com>
  8. Date: 13 Aug 92 04:17:31 GMT
  9. Sender: ram@eiffel.com
  10. Organization: Interactive Software Engineering, Santa Barbara CA
  11. Lines: 650
  12.  
  13. Here is an updated version of my 'perload' script, which takes an arbitrary
  14. perl script and produces an equivalent one set up for dataloading and/or
  15. autoloading.
  16.  
  17. This new version takes advantage of the feedback I got from Wayne Scott.
  18. Wayne took care of optimizing the function fetching the code within
  19. the data section by removing unneeded strings operations. The new option
  20. -o (also from Wayne) will build an offset table right at the beginning
  21. of the dataloaded section. This speeds up the initial loading of the functions
  22. by skipping the parsing of the data section to locate subroutine definitions.
  23.  
  24. Enjoy!
  25. --
  26. Raphael Manfredi <ram@eiffel.com>
  27. Interactive Software Engineering Inc.
  28. 270 Storke Road, Suite #7                      / Tel +1 (805) 685-1006 \
  29. Goleta, California 93117, USA                  \ Fax +1 (805) 685-6869 /
  30.  
  31. #! /bin/sh
  32. # This is a shell archive.  Remove anything before this line, then feed it
  33. # into a shell via "sh file" or similar.  To overwrite existing files,
  34. # type "sh file -c".
  35. # The tool that generated this appeared in the comp.sources.unix newsgroup;
  36. # send mail to comp-sources-unix@uunet.uu.net if you want that tool.
  37. # Contents:  perload
  38. # Wrapped by ram@lyon on Wed Aug 12 21:21:21 1992
  39. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  40. echo If this archive is complete, you will see the following message:
  41. echo '          "shar: End of archive."'
  42. if test -f 'perload' -a "${1}" != "-c" ; then 
  43.   echo shar: Will not clobber existing file \"'perload'\"
  44. else
  45.   echo shar: Extracting \"'perload'\" \(19802 characters\)
  46.   sed "s/^X//" >'perload' <<'END_OF_FILE'
  47. X# feed this into perl
  48. X'/bin/true' && eval 'exec perl -S $0 "$@"'
  49. X    if $running_under_some_shell;
  50. X'di';
  51. X'ig00';
  52. X
  53. X#
  54. X# This perl script is its own manual page [generated by wrapman]
  55. X#
  56. X
  57. X# $Id: perload,v 2.9.1.1 92/08/02 16:25:43 ram Exp Locker: ram $
  58. X#
  59. X#  Copyright (c) 1992, Raphael Manfredi
  60. X#
  61. X#  You may redistribute only under the terms of the GNU General Public
  62. X#  Licence as specified in the README file that comes with dist.
  63. X#
  64. X# $Log:    perload,v $
  65. X# Revision 2.9.1.1  92/08/02  16:25:43  ram
  66. X# patch2: dataloading routines now fully operate in perload package
  67. X# 
  68. X# Revision 2.9  92/07/14  16:53:40  ram
  69. X# 3.0 beta baseline.
  70. X# 
  71. X
  72. X# Replace each function definition in a loading section by two stubs and
  73. X# reject the definition into the DATA part of the script if in a dataload
  74. X# section or into a FILE if in an autoload section.
  75. X
  76. X$in_load = 0;                    # In a loading section
  77. X$autoload = '';                    # Name of autoloaded file
  78. X$has_invocation_stub = 0;        # True if we detect a #! stub
  79. X$current_package = 'main';        # Current package
  80. X$init_emitted = 0;                # True when dataloading stamp was emitted
  81. X$in_function = 0;
  82. X
  83. Xrequire 'getopt.pl';
  84. X&Getopt;
  85. X
  86. Xwhile (<>) {
  87. X    if ($. == 1 && /^#.*perl/) {    # Invocation stub
  88. X        $has_invocation_stub = 1;
  89. X        print;
  90. X        next;
  91. X    }
  92. X    if ($. <= 3 && $has_invocation_stub) {
  93. X        print;
  94. X        next;
  95. X    }
  96. X    if (/^\s*$/) {
  97. X        &flush_comment;
  98. X        print unless $in_function;
  99. X        print if $in_function && !$in_load;
  100. X        if ($in_function && $in_load) {
  101. X            push(@Data, "\n") unless $autoload;
  102. X            $Auto{$autoload} .= "\n" if $autoload;
  103. X        }
  104. X        next;
  105. X    }
  106. X    if (/^\s*#/) {
  107. X        if (/^#\s*perload on/i) {        # Enter a loading section
  108. X            print unless /:$/;
  109. X            $in_load = 1;
  110. X            next;
  111. X        }
  112. X        if (/^#\s*perload off/i) {        # End a loading section
  113. X            print unless /:$/;
  114. X            $in_load = 0;
  115. X            next;
  116. X        }
  117. X        if (/^#\s*autoload (\S+)/i) {    # Enter autoloading section
  118. X            print unless /:$/;
  119. X            push(@autoload, $autoload);    # Directives may be nested
  120. X            $autoload = $1;
  121. X            $in_load += 2;
  122. X            next;
  123. X        }
  124. X        if (/^#\s*offload/i) {            # End autoloading section
  125. X            print unless /:$/;
  126. X            $autoload = pop(@autoload);    # Revert to previously active file
  127. X            $in_load -= 2;
  128. X            next;
  129. X        }
  130. X        &emit_init unless $init_emitted;
  131. X        push(@Comment, $_) unless $in_function;
  132. X        print if $in_function && !$in_load;
  133. X        next unless $in_function;
  134. X        push(@Data, $_) unless $autoload;
  135. X        $Auto{$autoload} .= $_ if $autoload;
  136. X        next;
  137. X    }
  138. X    &emit_init unless $init_emitted;
  139. X    /^package (\S+)\s*;/ && ($current_package = $1);
  140. X    unless ($in_load) {
  141. X        &flush_comment;
  142. X        print;
  143. X        next;
  144. X    }
  145. X    # We are in a loading section
  146. X    if (/^sub\s+([\w']+)\s*\{(.*)/) {
  147. X        die "line $.: function $1 defined within another function.\n"
  148. X            if $in_function;
  149. X        # Silently ignore one-line functions
  150. X        if (/\}/) {
  151. X            print;
  152. X            next;
  153. X        }
  154. X        $comment = $2;
  155. X        $in_function = 1;
  156. X        $function = $1;
  157. X        ($fn_package, $fn_basename) = $function =~ /^(\w+)'(\w+)/;
  158. X        unless ($fn_package) {
  159. X            $fn_package = $current_package;
  160. X            $fn_basename = $function;
  161. X        }
  162. X        # Keep leading function comment
  163. X        foreach (@Comment) {
  164. X            push(@Data, $_) unless $autoload;
  165. X            $Auto{$autoload} .= $_ if $autoload;
  166. X        }
  167. X        @Comment = ();
  168. X        # Change package context for correct compilation: the name is visible
  169. X        # within the original function package while the body of the function
  170. X        # is compiled within the current package.
  171. X        $declaration = "sub $fn_package" . "'load_$fn_basename {$comment\n";
  172. X        $package_context = "\tpackage $current_package;\n";
  173. X        if ($autoload) {
  174. X            $Auto{$autoload} .= $declaration . $package_context;
  175. X        } else {
  176. X            push(@Data, $declaration, $package_context);
  177. X        }
  178. X        # Emit stubs
  179. X        print "sub $fn_package", "'$fn_basename";
  180. X        print " { &auto_$fn_package", "'$fn_basename; }\n";
  181. X        print "sub auto_$fn_package", "'$fn_basename { ";
  182. X        print '&main\'dataload' unless $autoload;
  183. X        print '&main\'autoload(' . "'$autoload'" . ', @_)' if $autoload;
  184. X        print "; }\n";
  185. X        next;
  186. X    }
  187. X    unless ($in_function) {
  188. X        &flush_comment;
  189. X        print;
  190. X        next;
  191. X    }
  192. X    # We are in a loading section and inside a function body
  193. X    push(@Data, $_) unless $autoload;
  194. X    $Auto{$autoload} .= $_ if $autoload;
  195. X    $in_function = 0 if /^\}/;
  196. X    if (/^\}/) {
  197. X        push(@Data, "\n") unless $autoload;
  198. X        $Auto{$autoload} .= "\n" if $autoload;
  199. X    }
  200. X}
  201. X
  202. X@auto = keys %Auto;
  203. Xprint &q(<<'EOC') if @auto > 0;
  204. X:# Load the calling function from file and call it. This function is called
  205. X:# only once per file to be loaded.
  206. X:sub main'autoload {
  207. X:    local($__file__) = shift(@_);
  208. X:    local($__packname__) = (caller(1))[3];
  209. X:    local($__rpackname__) = $__packname__;
  210. X:    local($__saved__) = $@;
  211. X:    $__rpackname__ =~ s/^auto_//;
  212. X:    &perload'load_from_file($__file__);
  213. X:    $__rpackname__ =~ s/'/'load_/;
  214. X:    $@ = $__saved__;        # Restore value $@ had on entrance
  215. X:    &$__rpackname__(@_);    # Call newly loaded function
  216. X:}
  217. X:
  218. X:# Load file and compile it, substituing the second stub function with the
  219. X:# loaded ones. Location of the file uses the @AUTO array.
  220. X:sub perload'load_from_file {
  221. X:    package perload;
  222. X:    local($file) = @_;                # File to be loaded
  223. X:    local($body) = ' ' x 1024;        # Pre-extent
  224. X:    local($load) = ' ' x 256;        # Loading operations
  225. X:    # Avoid side effects by protecting special variables which will be
  226. X:    # changed by the autoloading operation.
  227. X:    local($., $_, $@);
  228. X:    $body = '';
  229. X:    $load = '';
  230. X:    &init_auto unless defined(@'AUTO);    # Make sure we have a suitable @AUTO
  231. X:    &locate_file unless -f "$file";        # Locate file if relative path
  232. X:    open(FILE, $file) ||
  233. X:        die "Can't load $'__rpackname__ from $file: $!\n";
  234. X:    while (<FILE>) {
  235. X:        $load .= '*auto_' . $1 . '\'' . $2 . '= *' . $1 . '\'' . "load_$2;\n"
  236. X:            if (/^sub\s+(\w+)'load_(\w+)\s*\{/);
  237. X:        $body .= $_;
  238. X:    }
  239. X:    close FILE;
  240. X:    eval $body . $load;
  241. X:    chop($@) && die "$@, while parsing code of $file.\n";
  242. X:}
  243. X:
  244. X:# Initialize the @AUTO array. Attempt defining it by using the AUTOLIB
  245. X:# environment variable if set, otherwise look in auto/ first, then in the
  246. X:# current directory.
  247. X:sub perload'init_auto {
  248. X:    if (defined $ENV{'AUTOLIB'} && $ENV{'AUTOLIB'}) {
  249. X:        @AUTO = split(':', $ENV{'AUTOLIB'});
  250. X:    } else {
  251. X:        @AUTO = ('auto', '.');
  252. X:    }
  253. X:}
  254. X:
  255. X:# Locate to-be-loaded file held in $file by looking through the @AUTO array.
  256. X:# This variable, defined in 'load_from_file', is modified as a side effect.
  257. X:sub perload'locate_file {
  258. X:    package perload;
  259. X:    local($fullpath);
  260. X:    foreach $dir (@'AUTO) {
  261. X:        $fullpath = $dir . '/' . $file;
  262. X:        last if -f "$fullpath";
  263. X:        $fullpath = '';
  264. X:    }
  265. X:    $file = $fullpath if $fullpath;        # Update var from 'load_from_file'
  266. X:}
  267. X:
  268. XEOC
  269. X
  270. Xprint &q(<<'EOC') if @Data > 0;
  271. X:# Load the calling function from DATA segment and call it. This function is
  272. X:# called only once per routine to be loaded.
  273. X:sub main'dataload {
  274. X:    local($__packname__) = (caller(1))[3];
  275. X:    local($__rpackname__) = $__packname__;
  276. X:    local($__at__) = $@;
  277. X:    $__rpackname__ =~ s/^auto_//;
  278. X:    &perload'load_from_data($__rpackname__);
  279. X:    local($__fun__) = "$__rpackname__";
  280. X:    $__fun__ =~ s/'/'load_/;
  281. X:    eval "*$__packname__ = *$__fun__;";    # Change symbol table entry
  282. X:    die $@ if $@;        # Should not happen
  283. X:    $@ = $__at__;        # Restore value $@ had on entrance
  284. X:    &$__fun__;            # Call newly loaded function
  285. X:}
  286. X:
  287. X:# Load function name given as argument, fatal error if not existent
  288. X:sub perload'load_from_data {
  289. X:    package perload;
  290. X:    local($pos) = $Datapos{$_[0]};            # Offset within DATA
  291. X:    # Avoid side effects by protecting special variables which will be changed
  292. X:    # by the dataloading operation.
  293. X:    local($., $_, $@);
  294. X:    $pos = &fetch_function_code unless $pos;
  295. X:    die "Function $_[0] not found in data section.\n" unless $pos;
  296. X:    die "Cannot seek to $pos into data section.\n"
  297. X:        unless seek(main'DATA, $pos, 0);
  298. X:    local($/) = "\n}";
  299. X:    local($body) = scalar(<main'DATA>);
  300. X:    local($*) = 1;
  301. X:    die "End of file found while loading $_[0].\n" unless $body =~ /^\}$/;
  302. X:    eval $body;        # Load function into perl space
  303. X:    chop($@) && die "$@, while parsing code of $_[0].\n";
  304. X:}
  305. X:
  306. XEOC
  307. X
  308. Xif (@Data > 0) {
  309. X    print &q(<<'EOC') unless $opt_o;
  310. X:# Parse text after the END token and record defined loadable functions (i.e.
  311. X:# those whose name starts with load_) into the %Datapos array. Such function
  312. X:# definitions must be left adjusted. Stop as soon as the function we want
  313. X:# has been found.
  314. X:sub perload'fetch_function_code {
  315. X:    package perload;
  316. X:    local($pos) = tell main'DATA;
  317. X:    local($in_function) = 0;
  318. X:    local($func_name);
  319. X:    local($., $_);
  320. X:    while (<main'DATA>) {
  321. X:        if (/^sub\s+(\w+)'load_(\w+)\s*\{/) {
  322. X:            die "DATA line $.: function $1'$2 defined within $func_name.\n"
  323. X:                if $in_function;
  324. X:            $func_name = $1 . '\'' . $2;
  325. X:            $Datapos{$func_name} = $pos;
  326. X:            $in_function = 1;
  327. X:            next;
  328. X:        }
  329. X:        $in_function = 0 if /^\}/;
  330. X:        next if $in_function;
  331. X:        return $pos if $func_name eq $_[0];
  332. X:        $pos = tell main'DATA;
  333. X:    }
  334. X:    0;        # Function not found
  335. X:}
  336. X:
  337. XEOC
  338. X    print &q(<<'EOC') if $opt_o;
  339. X:# This function is called only once, and fills in the %Datapos array with
  340. X:# the offset of each of the dataloaded routines held in the data section.
  341. X:sub perload'fetch_function_code {
  342. X:    package perload;
  343. X:    local($start) = 0;
  344. X:    local($., $_);
  345. X:    while (<main'DATA>) {            # First move to start of offset table
  346. X:        next if /^#/;
  347. X:        last if /^$/ && ++$start > 2;    # Skip two blank line after end token
  348. X:    }
  349. X:    $start = tell(main'DATA);        # Offsets in table are relative to here
  350. X:    local($key, $value);
  351. X:    while (<main'DATA>) {            # Load the offset table
  352. X:        last if /^$/;                # Ends with a single blank line
  353. X:        ($key, $value) = split(' ');
  354. X:        $Datapos{$key} = $value + $start;
  355. X:    }
  356. X:    $Datapos{$_[0]};        # All that pain to get this offset...
  357. X:}
  358. X:
  359. XEOC
  360. X    print &q(<<'EOC');
  361. X:#
  362. X:# The perl compiler stops here.
  363. X:#
  364. X:
  365. X:__END__
  366. X:
  367. X:#
  368. X:# Beyond this point lie functions we may never compile.
  369. X:#
  370. X:
  371. XEOC
  372. X    # Option -o directs us to optimize the function location by emitting an
  373. X    # offset table, which lists all the position within DATA for each possible
  374. X    # dataloaded routine.
  375. X    if ($opt_o) {
  376. X        print &q(<<'EOC');
  377. X:#
  378. X:# DO NOT CHANGE A IOTA BEYOND THIS COMMENT!
  379. X:# The following table lists offsets of functions within the data section.
  380. X:# Should modifications be needed, change original code and rerun perload
  381. X:# with the -o option to regenerate a proper offset table.
  382. X:#
  383. X:
  384. XEOC
  385. X        $trailing_message = &q(<<'EOC');
  386. X:
  387. X:#
  388. X:# End of offset table and beginning of dataloading section.
  389. X:#
  390. X:
  391. XEOC
  392. X        $pos = 0;            # Offset relative to this point (start of table)
  393. X        foreach (@Data) {
  394. X            $Datapos{"$1\'$2"} = $pos - $now
  395. X                if /^sub\s+(\w+)'load_(\w+)\s*\{/;    # } for vi
  396. X            $pos += length;
  397. X        }
  398. X        @poskeys = keys %Datapos;    # Array of routine names (fully qualified)
  399. X
  400. X        # Write out a formatted table, each entry stored on $entry bytes and
  401. X        # formatted with the $format string.
  402. X        ($entry, $format) = &get_format(*poskeys);
  403. X
  404. X        # The total size occupied by the table is the size of one item times
  405. X        # the number of items plus the final trailing message at the end of
  406. X        # the table.
  407. X        $table_size = $entry * @poskeys + length($trailing_message);
  408. X
  409. X        # Output formatted table
  410. X        foreach (sort @poskeys) {
  411. X            printf($format, $_, $table_size + $Datapos{$_});
  412. X        }
  413. X        print $trailing_message;
  414. X    }
  415. X
  416. X    # Output code for each dataloaded function
  417. X    foreach (@Data) {
  418. X        print;
  419. X    }
  420. X    print &q(<<'EOC');
  421. X:#
  422. X:# End of dataloading section.
  423. X:#
  424. X:
  425. XEOC
  426. X}
  427. X
  428. Xif (@auto > 0) {
  429. X    mkdir('auto',0755) unless -d 'auto';
  430. X    foreach $file (@auto) {
  431. X        unless (open(AUTO, ">auto/$file")) {
  432. X            warn "Can't create auto/$file: $!\n";
  433. X            next;
  434. X        }
  435. X        print AUTO &q(<<'EOC');
  436. X:# This file was generated by perload
  437. X:
  438. XEOC
  439. X        print AUTO $Auto{$file};
  440. X        close AUTO;
  441. X    }
  442. X}
  443. X
  444. X# Compute optimum format for routine offset table, returning both the size of
  445. X# each entry and the formating string for printf.
  446. Xsub get_format {
  447. X    local(*names) = @_;
  448. X    local($name_len) = 0;
  449. X    local($max_len) = 0;
  450. X    foreach (@names) {
  451. X        $name_len = length;
  452. X        $max_len = $name_len if $name_len > $max_len;
  453. X    }
  454. X    # The size of each entry (preceded by one tab, followed by 12 chars)
  455. X    $name_len = $max_len + 1 + 12;
  456. X    ($name_len, "\t%${max_len}s %10d\n");
  457. X}
  458. X
  459. Xsub emit_init {
  460. X    print &q(<<'EOC');
  461. X:#
  462. X:# This perl program uses dynamic loading [generated by perload]
  463. X:#
  464. X:
  465. XEOC
  466. X    $init_emitted = 1;
  467. X}
  468. X
  469. Xsub flush_comment {
  470. X    print @Comment if @Comment > 0;
  471. X    @Comment = ();
  472. X}
  473. X
  474. Xsub q {
  475. X    local($_) = @_;
  476. X    local($*) = 1;
  477. X    s/^://g;
  478. X    $_;
  479. X}
  480. X
  481. X#
  482. X# These next few lines are legal in both perl and nroff.
  483. X#
  484. X
  485. X.00;        # finish .ig
  486. X'di            \" finish diversion--previous line must be blank
  487. X.nr nl 0-1    \" fake up transition to first page again
  488. X.nr % 0        \" start at page 1
  489. X'; __END__    \" the perl compiler stops here
  490. X
  491. X'''
  492. X''' From here on it's a standard manual page.
  493. X'''
  494. X
  495. X.TH PERLOAD 1 "June 20, 1992"
  496. X.AT 3
  497. X.SH NAME
  498. Xperload \- builds up autoloaded and dataloaded perl scripts
  499. X.SH SYNOPSIS
  500. X.B perload
  501. X[ \fB\-o\fR ]
  502. X[ \fIfile\fR ]
  503. X.SH DESCRIPTION
  504. X.I Perload
  505. Xtakes a perl script as argument (or from stdin if no argument is supplied)
  506. Xand prints out on stdout an equivalent script set-up to perform autoloading
  507. Xor dataloading. The translation is directed by special comments within the
  508. Xoriginal script. Using dynamic loading can drastically improve start-up
  509. Xperformances, both in time and in memory, as perl does not need to compile
  510. Xthe whole script nor store its whole compiled form in memory.
  511. X.PP
  512. X.I Autoloading
  513. Xdelays compilation of some functions until they are needed. The code for these
  514. Xfunctions is loaded dynamically at run-time. The atomicity of loading is a
  515. Xfile, which means that putting more than one function into a file will cause
  516. Xall these functions to be loaded and compiled as soon as one among them is
  517. Xneeded.
  518. X.PP
  519. X.I Dataloading
  520. Xis a form of autoloading where no extra file are needed. The script carries
  521. Xall the functions whose compilation is to be delayed in its data segment
  522. X(in the \fIperl\fR sense, i.e. they are accessible via the DATA filehandle).
  523. XThe scripts parses the data segment and extracts only the code for the needed
  524. Xsubroutine, which means granularity is better than with autloading.
  525. X.PP
  526. XIt is possible for a single script to use both autoloading and dataloading at
  527. Xthe same time. However, it should be noted that a script using only dataloading
  528. Xis self contained and can be moved or shared accross different platforms without
  529. Xfear. On the contrary, a script using only autoloading relies on some externally
  530. Xprovided files. Sharing this script among different platforms requires sharing
  531. Xof these external files. The script itself cannot be redistributed without
  532. Xalso giving the extra files holding the autoloaded functions.
  533. X.PP
  534. XThe major drawback with dataloading is that the DATA filehandle cannot be used
  535. Xfor anything else and may result in code duplication when two scripts could
  536. Xshare the same pieces of code. Autoloading appears as the perfect solution in
  537. Xthis case since two scripts may freely share the same functions without
  538. Xactually duplicating them on the disk (hence saving some precious disk blocks
  539. X:-).
  540. X.SH CRITERIA
  541. XFunctions to be dataloaded or autoloaded must meet the following layout
  542. Xcriteria:
  543. X.TP 5
  544. X\-
  545. XThey must not be one-line functions like \fIsub sorter { $a <=> $b }\fR.
  546. XThose functions are simply output verbatim, as they are already so
  547. Xsmall that it would not be worth to dynamically load them,
  548. X.TP
  549. X\-
  550. XThe first line must be of the form \fIsub routine_name {\fR, with an optional
  551. Xcomment allowed after the '{'.
  552. X.TP
  553. X\-
  554. XThe function definition must end with a single '}' character left aligned.
  555. X.TP
  556. X\-
  557. XPackage directives outside any function must be left aligned.
  558. X.PP
  559. XAll the above restrictions should not be source of a problem if "standard"
  560. Xwriting style is used. There are also some name restrictions: the package
  561. Xname \fIperload\fR is reserved, as is the \fI@AUTO\fR array when autoloading
  562. Xis used. Packages must not start with \fIauto_\fR, as this is prepended to
  563. Xuser's package names when building the stubs. Furthermore, the subroutines
  564. Xnames \fImain'autoload\fR and
  565. X\fImain'dataload\fR must not be used by the original script. Again, these
  566. Xshould not cause any grief.
  567. X.SH DIRECTIVES
  568. XThe translation performed by
  569. X.I Perload
  570. Xis driven by some special comment directives placed directly within the code.
  571. XEnding those directives with a ':' character will actually prevent them from
  572. Xbeing output into the produced script. Case is irrelevant for all the directives
  573. Xand the comment need not be left-aligned, although it must be the first
  574. Xnon-space item on the line.
  575. X.PP
  576. XThe following directives are available:
  577. X.TP 10
  578. X# Perload ON
  579. XTurns on the \fIperload\fR processing. Any function definition which meets
  580. Xthe criteria listed in the previous section will be replaced by two stubs and
  581. Xits actual definition will be reject into the data segment (default) or a file
  582. Xwhen inside an autoloading section.
  583. X.TP
  584. X# Perload OFF
  585. XTurns off any processing. The script is written as-is on the standard output.
  586. X.TP
  587. X# Autoload \fIpath\fR
  588. XRequests autoloading from file \fIpath\fR, which may be an absolute path or
  589. Xa relative path. The file will be located at run-time using the @AUTO array
  590. Xif a non-absolute path is supplied or if the file does not exist as listed.
  591. XAutoloading directives may be nested.
  592. X.TP
  593. X# Offload \fIpath\fR
  594. XThe argument is not required. The directive ends the previous autoloading
  595. Xdirective (the inmost one). This does not turn off the \fIperload\fR processing
  596. Xthough. The \fIpath\fR name is optional here (in fact, it has only a comment
  597. Xvalue).
  598. X.SH OPTION
  599. XPerload accepts only one option, \fB\-o\fR, which is meaningful only when
  600. Xdataloading is used. It outputs an offset table which lists the relative
  601. Xoffset of the dataloaded functions within the data section. This will spare
  602. Xperl the run-time parsing needed to locate the function, and results in an good
  603. Xspeed gain. However, it has one major drawback: it prevents people from
  604. Xactually modifying the source beyond the start of the table. But anything
  605. Xbefore can be freely edited, which is particulary useful when tailoring the
  606. Xscript.
  607. X.PP
  608. XThis option should not be used when editing of functions within the data
  609. Xsection is necessary for whatever reason. When \fB\-o\fR is used, any
  610. Xchange in the dataloaded function must be committed by re-running perload
  611. Xon the original script.
  612. X.SH FILES
  613. X.TP 10
  614. Xauto
  615. Xthe subdirectory where all produced autoloaded files are written.
  616. X.SH ENVIRONMENT
  617. XNo environment variables are used by \fIperload\fR. However, the autoloaded
  618. Xversion of the script pays attention to the \fIAUTOLIB\fR variable as a colon
  619. Xseparated set of directories where the to-be-loaded files are to be found
  620. Xwhen a non-absolute path was specified. If the \fIAUTOLIB\fR variable is not
  621. Xset, the default value 'auto:.' is used (i.e. look first in the auto/
  622. Xsubdirectory, then in the current directory.
  623. X.SH CAVEAT
  624. XSpecial care is required when using an autoloading script, especially when
  625. Xexecuted by the super-user: it would be very easy for someone to leave a
  626. Xspecial version of a routine to be loaded, in the hope the super-user (or
  627. Xanother suitable target) executes the autoloaded version of the script with
  628. Xsome \fIad hoc\fR changes...
  629. X.PP
  630. XThe directory holding the to-be-loaded files should therefore be protected
  631. Xagainst unauthorized access, and no file should have write permission on them.
  632. XThe directory itself should not be world-writable either, or someone might
  633. Xsubstitute his own version.
  634. XIt should also be considered wise to manually set the @AUTO variable to a
  635. Xsuitable value within the script itself.
  636. X.PP
  637. XThe \fB\-o\fR option uses \fIperl\fR's special variable \fI$/\fR with a
  638. Xmulti-character value. I suspect this did not work with versions of \fIperl\fR
  639. Xprior to 4.0, so any script using this optimized form of dataloading will not
  640. Xbe 100% backward compatible.
  641. X.SH AUTHOR
  642. XRaphael Manfredi <ram@eiffel.com>
  643. X.SH CREDITS
  644. XValuable input came from Wayne H. Scott <wscott@ecn.purdue.edu>. He is
  645. Xmerely the author of the optimizing offset table (\fB\-o\fR option).
  646. X.PP
  647. X.I Perload
  648. Xis based on an article from Tom Christiansen <tchrist@convex.com>,
  649. X.I Autoloading in Perl,
  650. Xexplaining the concept of dataloading and giving a basic implementation.
  651. X.SH "SEE ALSO"
  652. Xperl(1).
  653. END_OF_FILE
  654.   if test 19802 -ne `wc -c <'perload'`; then
  655.     echo shar: \"'perload'\" unpacked with wrong size!
  656.   fi
  657.   chmod +x 'perload'
  658.   # end of 'perload'
  659. fi
  660. echo shar: End of archive.
  661. exit 0
  662.