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

The module you want to look at is Exporter. In general, if you create your modules using 'h2xs -X', all of this will be set up for you. You can export constants just like functions (because really, thats all they are)

require Exporter; our @ISA = qw(Exporter); # Items to export into callers namespace by default. Note: do not expo +rt # names by default without a very good reason. Use EXPORT_OK instead. # Do not simply export all your public functions/methods/constants. # This allows declaration use My::Module ':all'; # If you do not need this, moving things directly into @EXPORT or @EXP +ORT_OK # will save memory. our %EXPORT_TAGS = ( 'all' => [ qw( ) ] ); our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); our @EXPORT = qw( );

Replies are listed 'Best First'.
Re^2: How do I export methods and constants from a package module?
by tadman (Prior) on Apr 17, 2002 at 23:08 UTC
    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?

      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.