| 1 |
NAME |
| 2 |
Env::Sanctify - Lexically scoped sanctification of %ENV |
| 3 |
|
| 4 |
VERSION |
| 5 |
version 1.12 |
| 6 |
|
| 7 |
SYNOPSIS |
| 8 |
my $sanctify = Env::Sanctify->sanctify( sanctify => [ '^POE' ] ); |
| 9 |
|
| 10 |
# do some stuff, fork some processes etc. |
| 11 |
|
| 12 |
$sanctify->restore |
| 13 |
|
| 14 |
{ |
| 15 |
|
| 16 |
my $sanctify = Env::Sanctify->sanctify( env => { POE_TRACE_DEFAULT => 1 } ); |
| 17 |
|
| 18 |
# do some stuff, fork some processes etc. |
| 19 |
} |
| 20 |
|
| 21 |
# out of scope, %ENV is back to normal |
| 22 |
|
| 23 |
DESCRIPTION |
| 24 |
Env::Sanctify is a module that provides lexically scoped manipulation |
| 25 |
and sanctification of %ENV. |
| 26 |
|
| 27 |
You can specify that it alter or add additional environment variables or |
| 28 |
remove existing ones according to a list of matching regexen. |
| 29 |
|
| 30 |
You can then either "restore" the environment back manually or let the |
| 31 |
object fall out of scope, which automagically restores. |
| 32 |
|
| 33 |
Useful for manipulating the environment that forked processes and |
| 34 |
sub-processes will inherit. |
| 35 |
|
| 36 |
CONSTRUCTOR |
| 37 |
"sanctify" |
| 38 |
Creates an Env::Sanctify object. Takes two optional arguments: |
| 39 |
|
| 40 |
'env', a hashref of env vars to add to %ENV; |
| 41 |
'sanctify', an arrayref of regex pattern strings to match against current %ENV vars; |
| 42 |
|
| 43 |
Any %ENV var that matches a "sanctify" regex is removed from the |
| 44 |
resultant %ENV. |
| 45 |
|
| 46 |
METHODs |
| 47 |
"restore" |
| 48 |
Explicitly restore the previous %ENV. This is called automagically |
| 49 |
when the object is "DESTROY"ed, for instance, when it goes out of |
| 50 |
scope. |
| 51 |
|
| 52 |
CAVEATS |
| 53 |
It has been reported that redefining the Env::Sanctify object causes |
| 54 |
unexpected behaviour. |
| 55 |
|
| 56 |
use strict; |
| 57 |
use warnings; |
| 58 |
|
| 59 |
use Env::Sanctify; |
| 60 |
|
| 61 |
$ENV{TEST} = 'Test thing'; |
| 62 |
|
| 63 |
my $sanctify = Env::Sanctify->sanctify( sanctify => [ 'TEST' ] ); |
| 64 |
|
| 65 |
printf "My ENV{TEST}: %s\n", $ENV{TEST}; |
| 66 |
|
| 67 |
$sanctify = Env::Sanctify->sanctify( env => { TEST => 'Other answer' } ); |
| 68 |
|
| 69 |
printf "My ENV{TEST}: %s\n", $ENV{TEST}; |
| 70 |
|
| 71 |
This script outputs: |
| 72 |
|
| 73 |
My ENV{TEST}: |
| 74 |
My ENV{TEST}: Test thing |
| 75 |
|
| 76 |
AUTHOR |
| 77 |
Chris Williams <[email protected]> |
| 78 |
|
| 79 |
COPYRIGHT AND LICENSE |
| 80 |
This software is copyright (c) 2014 by Chris Williams. |
| 81 |
|
| 82 |
This is free software; you can redistribute it and/or modify it under |
| 83 |
the same terms as the Perl 5 programming language system itself. |
| 84 |
|