Fatpacking your scripts with fatten

"Thank you for a freakin awesome app. Seriously, fatten is great! <3" --Paul J. Fenwick

fatpack is a utility created by MST to pack a script along with its dependencies (required Perl modules) into a single file. It differs from PAR in that it does not create an archive that must be extracted into the filesystem at the start of program run. Thus, a fatpacked script is simpler and faster to run.

The command-line utility is a bit cumbersome to use, though. Producing the final result involves several invocations of fatpack, and often the final result still misses some required modules. If you want a more turnkey solution to fatpacking a script, you might want to check out fatten.

Using fatten could not be easier:

% fatten /path/to/myapp

You will get the resulting fatpacked script in /path/to/myapp.fatpack (or myapp.fatpack in the current directory, should /path/to/ happen to be unwritable). The fatpacked script is ready to be deployed on any system with just vanilla Perl with no extra modules installed other than core modules.

Unlike with fatpack, you can choose one among several methods of tracing your dependencies. The default fatpacker way is to inspect %INC at the CHECK phase, which means modules require()-ed during runtime will not be included. Other methods include using static analysis (e.g. with Perl::PrereqScanner) and by trapping require during runtime. These methods are not perfect either though. Static analysis might miss modules loaded in unusual way. For example, the current version of Perl::PrereqScanner doesn't recognize modules loaded using Module::Load::load(). On the other hand, trapping require means having to run your program and, depending on the flow of execution, it might miss modules loaded conditionally. Thus, fatten also provides a way to add dependencies manually using --include (-i). Additionally, it provides an option to exclude modules from being included.

Other features of fatten include: configuration file support, stripping comments using Perl::Stripper, skipping core modules by default, etc. For more details, check out the docs.

Another testimony from Paul Fenwick: "I'm using fatten in git pre-commit hooks, so that whenever I update a lean version of a file, a fattened version is automatically produced (meaning other contributors don't need to know how to use the CPAN to work with my build scripts and other utilities)."

Leave a comment

About perlancar

user-pic #perl #indonesia