I have written a small Perl script and now I would like to create a test suite for it. I thought it would be nice to be able to use
the script as a module, import t
Since I just wanted to test one sub, I used the hacky solution of extracting that sub into a module with a perl one-liner, which is easy to understand and doesn't require to install any modules (I extract the paragraph with the sub name which is of course brittle). So in my Makefile I have:
MyModule.pm: my_script.pl
perl -00 -lnE 'if(/^\s*sub my_sub \{/){say "package MyModule;";say;say "1;";}' my_script.pl >|MyModule.pm