[Nh-pm] Help with Exporter?

Paul Lussier pll at lanminds.com
Wed Jan 29 08:32:41 CST 2003


In a message dated: 28 Jan 2003 17:23:00 EST
Kevin D. Clark said:

>What does your "use Foo" line look like, exactly?

Originally it was:

	use Foo;

But when I added the scalars, I changed that to:

	use Foo qw/:all/;

>Can you show us how you are invoking the Foo::print_header_table()
>method and accessing $Foo::Text (etc.).

Well for Foo::print_header_table(), I was just calling the function 
directly, like:

	print_header_table();

>What is the output when you include 
>
>        BEGIN { $Exporter::Verbose=1 }
>
>and then try to use the Foo module's scalars in your code?

Don't know, however, after looking at how Getopt::Long does it, and 
slightly modifying my code to match that, I also noticed that the vars 
I was trying to export were all my'd in the module.  Un-my'ing them 
suddenly popped them into existence in my program.

My module now looks like this:

    package Foo;

    use 5.008;
    use strict;
    use warnings;
    use CGI qw/:all/;

    require Exporter;
    use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);

    our @ISA = qw(Exporter);

    %EXPORT_TAGS = \
        ('all'=>[ qw(&print_header_table $TEXT $BGCOLOR $LINK $VLINK $ALINK)]);

    BEGIN {

        # Init immediately so their contents can be used
        # in the 'use vars' below.
         @EXPORT = qw(&print_header_table $TEXT $BGCOLOR $LINK $VLINK $ALINK);
         @EXPORT_OK = qw ();
    }

    our $VERSION = '0.02';

    # User visible variables.
    use vars @EXPORT, @EXPORT_OK;

    # WWW vars
    $TEXT       = "#FFFFBB";
    $BGCOLOR    = "#000000";
    $LINK       = "#FFFFBB";
    $VLINK      = "#00bbff";
    $ALINK      = "#FF0000";

    sub print_header_table {
    # a bunch of code here
    }

So, things *seem* to be working okay now.  Though I still don't 
completey grok the whole Exporter thing, nor completely understand 
why the Getopt::Long module does what it does.

Thanks!
-- 

Seeya,
Paul
--
Key fingerprint = 1660 FECC 5D21 D286 F853  E808 BB07 9239 53F1 28EE

	It may look like I'm just sitting here doing nothing,
   but I'm really actively waiting for all my problems to go away.

	 If you're not having fun, you're not doing it right!





More information about the Nh-pm mailing list