|XP is just a number|
RFC: Runnable test code integrated into Modules.by BrowserUk (Pope)
|on Jan 30, 2003 at 11:06 UTC||Need Help??|
I've recently been trying to put together a module for distribution and it struck me that in the same way that using POD keeps the documentation together with the module, it would be useful if you could do the same thing with a test suite/program. It would also be useful if the test program was useable directly for install time verification.
I thought about various schemes of having a test function or method that could be invoked, which would be okay, but still require another script--even if it is only a -e one-liner to invoke the test code.
Then inspiration hit me and I remembered 2 things I had seen recently.
Putting the two together took a little experimentation, but the result is that you can construct a .pm file that acts in every way that I have tried as a normal module when invoked via either a use my::module; statement or a require 'my::module'; or even a one-liner using the -m switch.
However, if the module is run as a program using the -x switch, it will execute the embedded program, load itself as a module and function as a 'normal' script would.
A trivial example
Is this a useful idea? Stupid?
Examine what is said, not who speaks.
The 7th Rule of perl club is -- pearl clubs are easily damaged. Use a diamond club instead.