Cleanup huge Perl Codebase
cgi, code-cleanup, perl, web-applications
Solution
Devel::Modlist may give you what you need, but I have never used it.
The few times I have needed to do somehing like this I have opted for the more brute force approach of inspecting `%INC` at the end the program.
END {
open my $log_fh, ...;
print $log_fh "$_\n" for sort keys %INC;
}
Problem
I am currently working on a roughly 15 years old web application. It contains mainly CGI perl scripts with HTML::Template templates. It has over 12 000 files and roughly 260 MB of total code. I estimate that no more than 1500 perl scripts are needed and I want to get rid of all the unused code. There are practically no tests written for the code. My questions are: - Are you aware of any CPAN module that can help me get a list of only `use`d and `require`d modules? - What would be your approach if you'd want to get rid of all the extra code? I was thinking at the following approaches: - try to override the `use` and `require` perl builtins with ones that output the loaded file name in a specific location - override the `warnings` and/or `strict` modules `import` function and output the file name in the specific location - study the `Devel::Cover` perl module and take the same approach and analyze the code when doing manual testing instead of automated tests - replace the perl executable with a custom one, which will log each name of file it reads (I don't know how to do that yet) - some creative use of `lsof` (?!?)