Module...stitute(3pm)
π Module::Install::Substitute(3pm) β the manual, but make it cute β¨
okay bestie, you found the manpage for Module::Install::Substitute β the Perl extension that swaps values into your files before install. paths to libs, paths to binaries, the whole vibe. let's get into it π«Ά
πΈ NAME πΈ
Module::Install::Substitute β substitute values into files before install, no cap π
β¨ SYNOPSIS β¨
like, here's the whole fantasy. first your Makefile.PL:
... Makefile.PL ...
substitute(
{
LESS => '/usr/bin/less',
APXS => '/usr/bin/apxs2',
},
'bin/my-app'
);
and then in bin/my-app, watch the glow-up:
... bin/my-app ...
### after: my $less_path = '@LESS@';
my $less_path = '/usr/bin/less';
it literally did that. iconic. ππ
π¦ DESCRIPTION π¦
Module::Install::Substitute is an extension for the Module::Install system, and what it does is let you substitute values into files before install. think paths to libs, think paths to binary executables. basically anything you don't wanna hardcode at authoring time but do want hardcoded by the time it lands on someone's machine. main character energy, fr fr β¨
π METHODS π
π substitute {SUBSTITUTIONS} [{OPTIONS}] @FILES
so this one takes:
- a hash reference with substitutions β key/value pairs, as one does
- an optional hash reference with options
- and a list of files to deal with
that's it. that's the call. π
π Options
Several options are available, and yes there are several, here they all are:
sufixβ Sufix for source files! for example you can use sufix".in"and then the results of processing ofMakefile.inwould be written into the fileMakefile. note that you don't need to specify sufixes in the list of files. (also yes, it's spelledsufix, we're keeping it exactly as-is, don't @ me π)fromβ Source base dir. by default it's the current working directory (Cwd). all files in the list are treated as relative to this directory.toβ Destination base dir. by default it's the current working directory (Cwd).
π§ File format
in the files, the following constructs get replaced:
###\s*after:\s?some string with @KEY@
some string with @KEY@
some string with value
###\s*before:\s?some string with @KEY@
###\s*replace:\s?some string with @KEY@
so the string should start with three # characters, followed by optional spaces, an action keyword, and then some string where the @SOME_KEY@ bits get substituted. β¨
okay so here's the clever part β this module can replace lines after or before the above constructs, based on the action keyword. that's what lets you change files in place without moving them around, and it's also what makes it possible to run the substitution multiple times. obsessed. π₯
π AUTHOR π
Ruslan Zakirov <ruz@cpan.org> β thank you for your service, king π
and that's the whole page, bestie!! this was documented for perl v5.32.0 on 2020-12-06 β and that's the sign-off, mwah πβ¨π
π¦ where this page comes from
- debian bookworm: libmodule-install-substitute-perl 0.03-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu jammy: libmodule-install-substitute-perl 0.03-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libmodule-install-substitute-perl 0.03-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms