I do this all the time. Nearly all my modules have the skeleton:
#! perl -slw
package MyPackage;
...
return 1 if caller;
package main;
use Devel::StealthDebug;
our $ITERS ||= 10;
our $OTHER ||= 'default';
## run test code here
That allows me to embed the unit test code for the module directly into the module itself, keeping it all together.
The testcode then also serves as sample code for users (should any of my half-baked ideas ever get refined enough that I feel able to let it loose on the world :).
Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
"Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side." - tachyon