|Do you know where your variables are?|
Re^3: How to write testable command line script?by davido (Cardinal)
|on Nov 24, 2018 at 16:47 UTC||Need Help??|
Each subroutine should be tested individually. Consider this contrived and silly example:
Here we've tested (minimally) all the components individually, and then tested the thing that uses the components.
How to deploy? A really simple way is to use the features of ExtUtils::MakeMaker. It can place your modules where modules live, and your executables where they're supposed to live on a given system. And the user is able to specify alternate locations based on environment settings and on how Perl was compiled and where it lives. You'll have a Makefile.PL that generates a makefile customized for your specific needs. The makefile will create the proper make directives, and you'll have 90% of what goes into a CPAN distribution when you're done. Consider any module on CPAN that bundles an executable script as part of the distribution as prior art. I haven't looked recently, but Carton, App::cpanoutdated, App::cpanminus, Devel::NYTProf, Perl::Critic, and Perl::Tidy are all examples of CPAN modules that bundle executables.
That said, you might also consider a minimal packaging system like Carton. Or combine that with something like Docker where you have more control over the isolated environment.
As for a structure, I typically do something like this:
In your executable (projectdir/bin/foo) you might do something like this:
This works in situations where you aren't deploying the module to a location known to PERL5LIB and not known to some tool such as Carton.