Env::Sanctify(3pm)
π Env::Sanctify π
okay bestie, so this is the Env::Sanctify page from the User Contributed Perl Documentation, and it's genuinely one of those little modules that just π gets it. Let's go.
β¨ NAME β¨
Env::Sanctify β lexically scoped sanctification of %ENV π§
πΈ VERSION πΈ
version 1.12
π¦ SYNOPSIS π¦
my $sanctify = Env::Sanctify->sanctify( sanctify => [ '^POE' ] );
# do some stuff, fork some processes etc.
$sanctify->restore
{
my $sanctify = Env::Sanctify->sanctify( env => { POE_TRACE_DEFAULT => 1 } );
# do some stuff, fork some processes etc.
}
# out of scope, %ENV is back to normal
π DESCRIPTION π
Env::Sanctify is the module that gives you lexically scoped manipulation and sanctification of %ENV. Like, it literally holds your environment's hand. π«Ά
You can tell it to alter stuff, add extra environment variables, or straight-up remove the existing ones β and you do all that by handing it a list of matching regexen. (Yes, regexen. Plural of regex. Iconic word, no notes.) π₯
Then you've got two β¨choicesβ¨: either "restore" the environment back manually yourself, or just let the object fall out of scope and it automagically restores everything for you. main character behaviour fr fr π
It's super useful for manipulating the environment that forked processes and sub-processes will inherit. lowkey essential, ngl π
π CONSTRUCTOR π
"sanctify"β creates anEnv::Sanctifyobject. Takes two optional arguments:
'env', a hashref of env vars to add to %ENV;
'sanctify', an arrayref of regex pattern strings to match against current %ENV vars;
Any %ENV var that matches a "sanctify" regex is removed from the resultant %ENV. bye bye bestie ππ
π METHODs π
"restore"β explicitly restore the previous%ENV. This gets called automagically when the object is"DESTROY"ed, like, for instance when it goes out of scope. it's giving β¨self-cleaningβ¨
π CAVEATS π
okay so listen. It has been reported that redefining the Env::Sanctify object causes unexpected behaviour. not me finding out the hard way π
The offending script, verbatim bestie:
use strict;
use warnings;
use Env::Sanctify;
$ENV{TEST} = 'Test thing';
my $sanctify = Env::Sanctify->sanctify( sanctify => [ 'TEST' ] );
printf "My ENV{TEST}: %s\n", $ENV{TEST};
$sanctify = Env::Sanctify->sanctify( env => { TEST => 'Other answer' } );
printf "My ENV{TEST}: %s\n", $ENV{TEST};
And this script outputs:
My ENV{TEST}:
My ENV{TEST}: Test thing
yeah. the first one's empty. so real. π
π AUTHOR π
Chris Williams <chris@bingosnet.co.uk> π
β COPYRIGHT AND LICENSE β
This software is copyright (c) 2014 by Chris Williams.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
and that's the whole page, bestie πβ¨ This was built on perl v5.36.0 and dated back on 2022-10-13 β so yeah, drop a π in the group chat, this one's a certified classic. mwah π
π
π¦ where this page comes from
- ubuntu noble: libenv-sanctify-perl 1.12-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libenv-sanctify-perl 1.12-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libenv-sanctify-perl 1.12-3 Β· 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