in reply to test case for private function in module

Add the last bit of the following to your script:
package Foo::Bar; my $privateFunc1 = sub { ... } my $privateFunc2 = sub { ... } my $privateFunc3 = sub { ... } if (our $TESTING) { # Expose private functions for testing. *_privateFunc1 = $privateFunc1; *_privateFunc2 = $privateFunc2; *_privateFunc3 = $privateFunc3; }

By setting var $TESTING in your module's package to something true, you can now perform testing on your private functions.

BEGIN { $Foo::Bar::TESTING = 1; } use Foo::Bar; is( Foo::Bar::_privateFunc1($val), $expect, 'privateFunc1' );

Replies are listed 'Best First'.
Re^2: test case for private function in module
by ack (Deacon) on Apr 08, 2009 at 21:54 UTC

    Awesome! I have been stewing for several weeks over the almost exactly the same dilema...but was trying (probably too obsessively) to solve it on my own.

    I got frustrated but just decided to shelve it until I learned more.

    This is almost uncanny. Thanks to both minhtuanht and ikegami. Some days things just seem to rock!

    ack Albuquerque, NM