Module...stitute(3pm)

πŸ“¦
version 0.03 Β· 2 versions
, in debian bookworm, ubuntu jammy, ubuntu noble

πŸ’– 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 of Makefile.in would be written into the file Makefile. note that you don't need to specify sufixes in the list of files. (also yes, it's spelled sufix, 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