summaryrefslogtreecommitdiff
path: root/pod/perlmod.pod
diff options
context:
space:
mode:
authorGurusamy Sarathy <gsar@cpan.org>1999-11-04 17:28:29 +0000
committerGurusamy Sarathy <gsar@cpan.org>1999-11-04 17:28:29 +0000
commit4f25aa189c4a92535547c706ad37c13b7caee387 (patch)
tree08af6df6000b2bd878b1b2e5e05cd48a1db0464b /pod/perlmod.pod
parent0e950d832564d240b1bebd0a01f04f9f5d57cc79 (diff)
downloadperl-4f25aa189c4a92535547c706ad37c13b7caee387.tar.gz
implement STOP blocks and fix compiler to use them (minimally
tested) p4raw-id: //depot/perl@4515
Diffstat (limited to 'pod/perlmod.pod')
-rw-r--r--pod/perlmod.pod35
1 files changed, 21 insertions, 14 deletions
diff --git a/pod/perlmod.pod b/pod/perlmod.pod
index fc81fdfaae..45a82ad7a2 100644
--- a/pod/perlmod.pod
+++ b/pod/perlmod.pod
@@ -213,8 +213,8 @@ This also has implications for the use of the SUPER:: qualifier
=head2 Package Constructors and Destructors
Three special subroutines act as package
-constructors and destructors. These are the C<BEGIN>, C<INIT>, and
-C<END> routines. The C<sub> is optional for these routines.
+constructors and destructors. These are the C<BEGIN>, C<STOP>, C<INIT>,
+and C<END> routines. The C<sub> is optional for these routines.
A C<BEGIN> subroutine is executed as soon as possible, that is, the moment
it is completely defined, even before the rest of the containing file
@@ -225,24 +225,31 @@ files in time to be visible to the rest of the file. Once a C<BEGIN>
has run, it is immediately undefined and any code it used is returned to
Perl's memory pool. This means you can't ever explicitly call a C<BEGIN>.
-Similar to C<BEGIN> blocks, C<INIT> blocks are run just before the
-Perl runtime begins execution. For example, the code generators
-documented in L<perlcc> make use of C<INIT> blocks to initialize
-and resolve pointers to XSUBs.
-
-An C<END> subroutine is executed as late as possible, that is, when
-the interpreter is being exited, even if it is exiting as a result of
-a die() function. (But not if it's polymorphing into another program
-via C<exec>, or being blown out of the water by a signal--you have to
-trap that yourself (if you can).) You may have multiple C<END> blocks
-within a file--they will execute in reverse order of definition; that is:
-last in, first out (LIFO).
+An C<END> subroutine is executed as late as possible, that is, after
+perl has finished running the program and just before the interpreter
+is being exited, even if it is exiting as a result of a die() function.
+(But not if it's polymorphing into another program via C<exec>, or
+being blown out of the water by a signal--you have to trap that yourself
+(if you can).) You may have multiple C<END> blocks within a file--they
+will execute in reverse order of definition; that is: last in, first
+out (LIFO). C<END> blocks are not executed when you run perl with the
+C<-c> switch.
Inside an C<END> subroutine, C<$?> contains the value that the program is
going to pass to C<exit()>. You can modify C<$?> to change the exit
value of the program. Beware of changing C<$?> by accident (e.g. by
running something via C<system>).
+Similar to C<BEGIN> blocks, C<INIT> blocks are run just before the
+Perl runtime begins execution, in "first in, first out" (FIFO) order.
+For example, the code generators documented in L<perlcc> make use of
+C<INIT> blocks to initialize and resolve pointers to XSUBs.
+
+Similar to C<END> blocks, C<STOP> blocks are run just after the
+Perl compile phase ends and before the run time begins, in
+LIFO order. C<STOP> blocks are again useful in the Perl compiler
+suite to save the compiled state of the program.
+
When you use the B<-n> and B<-p> switches to Perl, C<BEGIN> and
C<END> work just as they do in B<awk>, as a degenerate case. As currently
implemented (and subject to change, since its inconvenient at best),