in reply to Re: How do I export methods and constants from a package module?
in thread How do I export methods and constants from a package module?

Yikes! What's with the require?
use base 'Exporter'; our @EXPORT = qw[ functionA $variableB %mutantX ];
You can forcibly export things with @EXPORT, or optionally with @EXPORT_OK. Then, when you import you have to ask for them, which is really the nice way to do it.
package Foo; use Bar qw[ functionA ]; functionA($something);
Simple enough, no?

Replies are listed 'Best First'.
Re: Re^2: How do I export methods and constants from a package module?
by ehdonhon (Curate) on Apr 17, 2002 at 23:16 UTC

    Yes, There is more than one way to do it. The code I posted was the standard output from h2xs. IMO, using h2xs is the most convenient way for a beginner to get things right.

      h2xs...for beginners? That's induction by fire, if you ask me. h2xs seems like a giant hairball, somewhere between make and m4, that, if you understand it completely, then it will make your life easier.

      You do realise that there is so little documentation on h2xs that it's almost comedic. If someone wrote h2xs For Dummies, I would need to read it.
        Using h2xs to create XS extensions for perl might be difficult; I don't know, I've never done it before.

        However, using h2xs to create empty module templates for modules you'll be writing is extremely easy.

        Example:

        % h2xs -X -n This::Is::A::Test
        This creates a directory tree for module This::Is::A::Test under This/. Directory This/Is/A/Test contains Test.pm, Makefile.PL, MANIFEST, Changes, and test.pl (a test script, unrelated to the naming of Test.pm). Next, edit Test.pm to make it do what you want. To do a complete build and install, do the following in the Test directory:

        perl Makefile.PL; make; make test; make install
        For more information on this, please check out perldoc ExtUtils::MakeMaker. This gives lots of information about tweaking a Makefile.PL file created by h2xs, as well as how to start from scratch if you really want to.

        The .pm file created by h2xs starts out with a standard pod template, Autoloader, and Exporter. If you have the most recent h2xs, it'll build a .pm file which follows the most recent recommendations on the use of Exporter and Autoloader.

        I use this technique so regularly now, that I don't know what I ever did without it.

        Alan