SPUG: Stupid Exporter Question

Doug Beaver doug at beaver.net
Thu Dec 19 00:04:40 CST 2002


On Wed, Dec 18, 2002 at 05:43:38PM -0800, Peter Darley wrote:
> I've been building an application for the last two years, and my main
> package is getting very big.  I have a file, Tools.pm, that has over
> 170 [s]ubs in it, and it's getting unwieldy, to put it mildly.  I
> would like to break it out into a Tools::whatever namespace, but I
> would like to still be able to use Tools and have it export all the
> [s]ubs from the different [s]ub-packages.  It looks like
> export_to_level can do this, but I'll be jiggered if I can figure out
> how to use it.  Any suggestions would be most appreciated.

hi peter, did you read the perldoc for Exporter?  it has an example of
this, although it's not that clear...

i'm guessing that you want Tools.pm to just have use statements for all
your submodules.  that would look like:

package Tools;

use strict;
use Tools::Dir;

1;

package Tools::Dir;
use strict;
use Exporter;

our @EXPORT = qw/tool_dir/;
our @ISA = qw/Exporter/;

sub import {
  __PACKAGE__->export_to_level(2, @_);
}

sub tool_dir { print "in tool_dir!\n" }

1;

now when you "use Tools;", tool_dir will automatically be exported into
main::.  you could add %EXPORT_TAGS support to Tools.pm so that it only
grabbed certain submodules for different functionality sets.  or you
could just export the whole kitchen sink, whatever you like.

doug

-- 
Space Ghost: Moltar, I have a giant brain that is able to reduce any
             complex machine into a simple yes or no answer.
     Moltar: Okay, but that's not the cd burner...
Space Ghost: Moltar! <pause> Yes!

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
      Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
 For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
     Seattle Perl Users Group (SPUG) Home Page: http://seattleperl.org




More information about the spug-list mailing list