Frequently I notice in test suites that authors aren't always checking that their functions have been exported correctly to their namespace. Having a function exported accidentally can wreak havoc if you redefine a function. Below shows one way of testing this, though you will need to customize it to your situation.

use Test::More 'no_plan'; + use_ok('CGI'); ok(! defined *::param{CODE}, '&param is not exported to our namespace' +); # in another test file, verifying that you can import: # (though in this example you can run these in one test file) use_ok('CGI', ':standard') or die; can_ok(__PACKAGE__, 'param'); + # or, if you prefer symmetry with the "not exported" test: + ok(defined *::param{CODE}, '&param is exported to namespace');

Replies are listed 'Best First'.
Re: Testing that functions are imported
by kappa (Chaplain) on Oct 05, 2004 at 18:05 UTC
    Most of modern exports are done via Exporter, so this is just testing whether Exporter works, isn't it?

      No. Even if you're doing your exporting via Exporter, you still might have accidentally put a function in @EXPORT instead of @EXPORT_OK. Or maybe you misspelled the function name, or maybe you set up the export tag incorrectly. Or maybe you miswrote your own export function. There are plenty of ways that exporting can go wrong, so testing this is a Good Thing.

      Cheers,
      Ovid

      New address of my CGI Course.

Re: Testing that functions are imported
by PodMaster (Abbot) on Oct 06, 2004 at 13:42 UTC
    I see no reason to mess with globs :)
    C:\>more 2 sub FORWARD_DECLARATION; BEGIN { print 'glob ', defined *::FORWARD_DECLARATION{CODE}; print 'defined & ', defined &FORWARD_DECLARATION; print 'exists & ', exists &FORWARD_DECLARATION; } sub FORWARD_DECLARATION { 5 } print 'glob ', defined *::FORWARD_DECLARATION{CODE}; print 'defined & ', defined &FORWARD_DECLARATION; C:\>perl -l 2 glob 1 defined & exists & 1 glob 1 defined & 1 C:\>

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.