I have read and digested the recommendations in perlmodstyle but apart from the obvious things like splitting up the larger modules and making the purpose of each as tightly defined as possible is there any best practice I should be following before I embark on this? Is there anyone else out there who has had to deal with a similar problem and can share their experience with me?
I have no idea if it's the best way to do things, but when I've been faced with similar problems, I've tried to change out the instances of 'use' to 'require'. The problem lies in that you need to figure out exactly when each module gets used (and by 'used', I don't mean the 'use' command, I mean when it is actually needed by the calling program). You can also run into problems if you need for there to be functions imported -- you can either change out functions to use the full namespace, or after the require, call import() in the namespace.
Some modules are smart, and do this sort of work for you (not loading the bulk of their program until the fuctions are actually needed), so for Carp, and other modules that don't expect you to actually need them, just because they were mentioned, you don't have to worry about this trouble.
As an example -- someone may have some cases that result in debugging output being sent to the error log under certain conditions:
use Data::Dumper; # much later in the program if ( $some_condition) { warn "DEBUG: ", Dumper ( $whatever ); }
You only need to load Data::Dumper when the need to generate the message has occurred:
if ( $some_condition ) { require Data::Dumper; warn "DEBUG: ", Data::Dumper::Dumper( $whatever ); }
As for how to clean up things ... you might want to take a look at the book 'Perl Medic' for a start -- make an archive of the working copy, then get everything happy under use warnings and use strict. Then, if you want to do what I suggested, comment out every 'use' line, and see what warnings/errors you start generating, and on which line, and add your 'require's near those lines.
Some dependancies may be so important to your module that it's better just to leave it as is. (all usage patterns are different, though, so the benefits are going to be different depending on how often you call each function that needs to check if its required dependencies have been loaded)
In reply to Re: Private module organisation
by jhourcle
in thread Private module organisation
by Smoothhound
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |