I agree with this post. For an example of how to do this, I recommend How a script becomes a module.
To summarize part of that, if you really want to leave things as a script, the important thing is to write the script to allow it to be required like a module or run like a script. brian_d_foy calls this a "modulino". The key is to put all executable code into subroutines, but only execute the "main" function if there is no caller. This lets you require the modulino for testing, or to call it as a script.
# File modulino.pl package My::Modulino; use strict; use warnings; __PACKAGE__->main() unless caller(); sub foo { # utility subroutine return "foo"; } sub main { # body of the script } 1; # require needs to be true
Then you can test individual subroutines by loading it as a module:
use Test::More tests => 2; require_ok( "modulino.pl" ); is( My::Modulino::foo(), "foo", "got foo" );
Hope that helps.
-xdg
Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.
In reply to Re^2: Testing .pl files in Test::Simple
by xdg
in thread Testing .pl files in Test::Simple
by orphanBrent
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |