Exported vars and functions of a module

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
How do I list the exported variables and functions of a module (by default)?

Many thanks.

Re: Exported vars and functions of a module

Quoted text here. Click to load it

The question is somewhat unclear. If the Exporter import method is being
used, everything which is exported by default should be in the @EXPORT
array of the exporting module, eg,

print('exports ', join(', ', @the::module:EXPORT));

Re: Exported vars and functions of a module

El 19/02/15 a las 02:04, James escribió:
Quoted text here. Click to load it

Here's the template for your module:

---------- 8< --------------
package Some::Module;  # assumes Some/Module.pm

use strict;
use warnings;

     use 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;

     @ISA         = qw(Exporter);
     @EXPORT      = qw(&func1 &func2 &func4);
     %EXPORT_TAGS = ( );     # eg: TAG => [ qw!name1 name2! ],

     # your exported package globals go here,
     # as well as any optionally exported functions
     @EXPORT_OK   = qw($Var1 %Hashit &func3);


# exported package globals go here
our $Var1;
our %Hashit;

# non-exported package globals go here
our @more;
our $stuff;

# initialize package globals, first exported ones
$Var1   = '';
%Hashit = ();

# 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
my $priv_var    = '';
my %secret_hash = ();

# here's a file-private function as a closure,
# callable as &$priv_func;  it cannot be prototyped.
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

END { }       # module clean-up code here (global destructor)


1;  # don't forget to return a true value from the file

-------------- >8 -------------------

This was taken from Perl docs, but I don't remember the version.

The generation of random numbers is too important to be left to chance

Site Timeline