diff options
Diffstat (limited to 'Master/tlpkg/tlperl/lib/pods/perlmod.pod')
-rw-r--r-- | Master/tlpkg/tlperl/lib/pods/perlmod.pod | 79 |
1 files changed, 34 insertions, 45 deletions
diff --git a/Master/tlpkg/tlperl/lib/pods/perlmod.pod b/Master/tlpkg/tlperl/lib/pods/perlmod.pod index 5266f199df0..33f098d0228 100644 --- a/Master/tlpkg/tlperl/lib/pods/perlmod.pod +++ b/Master/tlpkg/tlperl/lib/pods/perlmod.pod @@ -102,6 +102,10 @@ You can use this to print out all the variables in a package, for instance. The standard but antiquated F<dumpvar.pl> library and the CPAN module Devel::Symdump make use of this. +The results of creating new symbol table entries directly or modifying any +entries that are not already typeglobs are undefined and subject to change +between releases of perl. + Assignment to a typeglob performs an aliasing operation, i.e., *dick = *richard; @@ -377,7 +381,7 @@ package may also derive some of its methods from another class (package) by listing the other package name(s) in its global @ISA array (which must be a package global, not a lexical). -For more on this, see L<perltoot> and L<perlobj>. +For more on this, see L<perlootut> and L<perlobj>. =head2 Perl Modules X<module> @@ -400,65 +404,50 @@ create a file called F<Some/Module.pm> and start with this template: use warnings; BEGIN { - use Exporter (); - our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS); + require Exporter; # set the version for version checking - $VERSION = 1.00; - # if using RCS/CVS, this may be preferred - $VERSION = sprintf "%d.%03d", q$Revision: 1.1 $ =~ /(\d+)/g; + our $VERSION = 1.00; + + # Inherit from Exporter to export functions and variables + our @ISA = qw(Exporter); - @ISA = qw(Exporter); - @EXPORT = qw(&func1 &func2 &func4); - %EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ], + # Functions and variables which are exported by default + our @EXPORT = qw(func1 func2); - # your exported package globals go here, - # as well as any optionally exported functions - @EXPORT_OK = qw($Var1 %Hashit &func3); + # Functions and variables which can be optionally exported + our @EXPORT_OK = qw($Var1 %Hashit func3); } - our @EXPORT_OK; # exported package globals go here - our $Var1; - our %Hashit; + our $Var1 = ''; + our %Hashit = (); # non-exported package globals go here - our @more; - our $stuff; - - # initialize package globals, first exported ones - $Var1 = ''; - %Hashit = (); + # (they are still accessible as $Some::Module::stuff) + our @more = (); + our $stuff = ''; - # then the others (which are still accessible as $Some::Module::stuff) - $stuff = ''; - @more = (); - - # all file-scoped lexicals must be created before - # the functions below that use them. - - # file-private lexicals go here + # file-private lexicals go here, before any functions which use them my $priv_var = ''; my %secret_hash = (); # here's a file-private function as a closure, - # callable as &$priv_func; it cannot be prototyped. + # callable as $priv_func->(); my $priv_func = sub { - # stuff goes here. + ... }; # make all your functions, whether exported or not; # remember to put something interesting in the {} stubs - sub func1 {} # no prototype - sub func2() {} # proto'd void - sub func3($$) {} # proto'd to 2 scalars - - # this one isn't exported, but could be called! - sub func4(\%) {} # proto'd to 1 hash ref + sub func1 { ... } + sub func2 { ... } - END { } # module clean-up code here (global destructor) + # this one isn't exported, but could be called directly + # as Some::Module::func3() + sub func3 { ... } - ## YOUR CODE GOES HERE + END { ... } # module clean-up code here (global destructor) 1; # don't forget to return a true value from the file @@ -476,11 +465,11 @@ or This is exactly equivalent to - BEGIN { require Module; import Module; } + BEGIN { require 'Module.pm'; 'Module'->import; } or - BEGIN { require Module; import Module LIST; } + BEGIN { require 'Module.pm'; 'Module'->import( LIST ); } As a special case @@ -488,7 +477,7 @@ As a special case is exactly equivalent to - BEGIN { require Module; } + BEGIN { require 'Module.pm'; } All Perl module files have the extension F<.pm>. The C<use> operator assumes this so you don't have to spell out "F<Module.pm>" in quotes. @@ -571,7 +560,7 @@ like for example handle the cloning of non-Perl data, if necessary. C<CLONE> will be called once as a class method for every package that has it defined (or inherits it). It will be called in the context of the new thread, so all modifications are made in the new area. Currently CLONE is called with -no parameters other than the invocand package name, but code should not assume +no parameters other than the invocant package name, but code should not assume that this will remain unchanged, as it is likely that in future extra parameters will be passed in to give more information about the state of cloning. @@ -593,7 +582,7 @@ to make use of the objects, then a more sophisticated approach is needed. Like C<CLONE>, C<CLONE_SKIP> is currently called with no parameters other -than the invocand package name, although that may change. Similarly, to +than the invocant package name, although that may change. Similarly, to allow for future expansion, the return value should be a single C<0> or C<1> value. @@ -602,7 +591,7 @@ C<1> value. See L<perlmodlib> for general style issues related to building Perl modules and classes, as well as descriptions of the standard library and CPAN, L<Exporter> for how Perl's standard import/export mechanism -works, L<perltoot> and L<perltooc> for an in-depth tutorial on +works, L<perlootut> and L<perlobj> for in-depth information on creating classes, L<perlobj> for a hard-core reference document on objects, L<perlsub> for an explanation of functions and scoping, and L<perlxstut> and L<perlguts> for more information on writing |