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 an Env::Sanctify object. 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> πŸ’œ

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