Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Exporter question

by lindex (Friar)
on Aug 24, 2000 at 12:32 UTC ( [id://29382]=perlquestion: print w/replies, xml ) Need Help??

lindex has asked for the wisdom of the Perl Monks concerning the following question:

Ok I know this is a simple question and that its not a good idea.
But is there a way to get Exporter to export all sub's from a mod without
listing out every single sub in the mod in @EXPORT?

And agian, yes I know this is bad form :)



lindex
/****************************/ jason@gost.net, wh@ckz.org http://jason.gost.net /*****************************/

Replies are listed 'Best First'.
RE: Exporter question
by davorg (Chancellor) on Aug 24, 2000 at 12:49 UTC

    Here's some code adapted from my Sub::Approx module which builds a list of all of the subroutines in a given package:

    foreach (keys %{"${pkg}::"}) { my $glob = $::{$_}; $glob =~ s/^\*${pkg}:://; next unless defined &{"*${pkg}::$glob"}; push @subs, $glob; }

    I guess it would be possible to run code like this in a BEGIN block and build up your @EXPORT array that way.

    Update As tilly points out below, when a BEGIN block is executed none of the package's subroutines will have been defined. Therefore you should just put this code in the body of your package.

    --
    <http://www.dave.org.uk>

    European Perl Conference - Sept 22/24 2000, ICA, London
    <http://www.yapc.org/Europe/>
      The code is nice, but putting it in a BEGIN block probably won't work. Just put it in the body of the module.

      You want to have actually compiled your module before running that code (so the functions are defined), and run that before the person using your module imports stuff. Well the order of compilation is that they hit the use in their code, they call require, your code is compiled, your code is run, then they call import, then they continue compiling. So from their point of view, ordinary code in your module already is in a BEGIN block. :-)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://29382]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (4)
As of 2024-04-25 12:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found