This isn't mine, but I thought it useful enough that, by permission, I post it here. Please only ++ the original nodes.

This snippet goes at the end of a module which (for whatever reason) has a changing population of functions, so you don't have to keep forgetting to add them to @EXPORT when you alter the module.
no strict 'refs'; our @EXPORT = grep {defined *{${__PACKAGE__.'::'}{$_}}{CODE} } keys %{ +__PACKAGE__.'::'};

Replies are listed 'Best First'.
Re: Export All Functions from a Module
by grinder (Bishop) on Dec 23, 2001 at 16:50 UTC
    That will also show your private parts, which is something that ordinarily one should never do in public. Assuming your package follows the naming convention of prepending an underscore to internal functions, one only has to further check that the first character of the function is not an underscore.

    our @EXPORT = grep { defined *{${__PACKAGE__.'::'}{$_}}{CODE} and substr($_,0,1) ne '_' } keys %{__PACKAGE__.'::'};
    --
    g r i n d e r
    just another bofh

    print@_{sort keys %_},$/if%_=split//,'= & *a?b:e\f/h^h!j+n,o@o;r$s-t%t#u';
      A handy twist. My original desire was for something to use in a module I only used for development, which had a floating population of subroutines, all of which ultimately found their homes in more decorous locations, where their private parts were modestly covered. But I like this scheme: wouldn't want to frighten the horses inadvertently.

      § George Sherston