これは実行可能です。以下を実行するとおそらくパフォーマンスが低下すると思います。考えられるすべてのケースをカバーしていないことは確かですが、これで間違いなく始めることができます。
use strict;
use warnings;
tie %ENV, 'change_noticer', %ENV or die $!;
$ENV{PATH} .= ":test";
print $ENV{PATH}, "\n";
delete $ENV{PATH};
package change_noticer;
use strict;
use warnings;
use Carp;
use Tie::Hash;
use base 'Tie::StdHash';
sub DELETE {
my $this = shift;
carp "deleting \$ENV{$_[0]}";
$this->SUPER::DELETE(@_);
}
sub STORE {
my $this = shift;
carp "altering \$ENV{$_[0]}";
$this->SUPER::STORE(@_);
}
sub TIEHASH {
my $class = shift;
my $this = bless {}, $class;
while( my ($k,$v) = splice @_, 0, 2 ) {
$this->{$k} = $v;
}
return $this;
}