line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Env::Sanctify::Moosified; |
2
|
|
|
|
|
|
|
{ |
3
|
|
|
|
|
|
|
$Env::Sanctify::Moosified::VERSION = '1.06'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
#ABSTRACT: Lexically scoped sanctification of %ENV |
7
|
|
|
|
|
|
|
|
8
|
4
|
|
|
4
|
|
116325
|
use strict; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
155
|
|
9
|
4
|
|
|
4
|
|
21
|
use warnings; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
116
|
|
10
|
|
|
|
|
|
|
|
11
|
4
|
|
|
4
|
|
20367
|
use Moo; |
|
4
|
|
|
|
|
119661
|
|
|
4
|
|
|
|
|
29
|
|
12
|
4
|
|
|
4
|
|
12443
|
use MooX::late; |
|
4
|
|
|
|
|
175963
|
|
|
4
|
|
|
|
|
35
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has env => ( |
15
|
|
|
|
|
|
|
is => 'ro', |
16
|
|
|
|
|
|
|
isa => 'HashRef', |
17
|
|
|
|
|
|
|
default => sub { { } }, |
18
|
|
|
|
|
|
|
); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
has sanctify => ( |
21
|
|
|
|
|
|
|
is => 'ro', |
22
|
|
|
|
|
|
|
isa => 'ArrayRef', |
23
|
|
|
|
|
|
|
default => sub { [ ] }, |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
has _backup => ( |
27
|
|
|
|
|
|
|
is => 'ro', |
28
|
|
|
|
|
|
|
isa => 'HashRef', |
29
|
|
|
|
|
|
|
default => sub { { } }, |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
has _restored => ( |
33
|
|
|
|
|
|
|
is => 'rw', |
34
|
|
|
|
|
|
|
isa => 'Bool', |
35
|
|
|
|
|
|
|
default => 0, |
36
|
|
|
|
|
|
|
); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub consecrate { |
39
|
4
|
|
|
4
|
1
|
283
|
my $self = shift->new( @_ ); |
40
|
4
|
|
|
|
|
300
|
$self->_sanctify; |
41
|
4
|
|
|
|
|
14
|
return $self; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub _sanctify { |
45
|
4
|
|
|
4
|
|
11
|
my $self = shift; |
46
|
4
|
|
|
|
|
13
|
foreach my $regex ( @{ $self->sanctify } ) { |
|
4
|
|
|
|
|
25
|
|
47
|
5
|
|
|
|
|
37
|
$self->_backup->{$_} = delete $ENV{$_} for grep { eval { /$regex/ } } keys %ENV; |
|
120
|
|
|
|
|
116
|
|
|
120
|
|
|
|
|
369
|
|
48
|
|
|
|
|
|
|
} |
49
|
4
|
|
|
|
|
13
|
$self->_backup->{$_} = delete $ENV{$_} for grep { defined $ENV{$_} } keys %{ $self->env }; |
|
4
|
|
|
|
|
24
|
|
|
4
|
|
|
|
|
29
|
|
50
|
4
|
|
|
|
|
11
|
$ENV{$_} = $self->env->{$_} for keys %{ $self->env }; |
|
4
|
|
|
|
|
42
|
|
51
|
4
|
|
|
|
|
12
|
return 1; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub restore { |
55
|
4
|
|
|
4
|
1
|
3825
|
my $self = shift; |
56
|
4
|
|
|
|
|
9
|
delete $ENV{$_} for keys %{ $self->env }; |
|
4
|
|
|
|
|
47
|
|
57
|
4
|
|
|
|
|
10
|
$ENV{$_} = $self->_backup->{$_} for keys %{ $self->_backup }; |
|
4
|
|
|
|
|
123
|
|
58
|
4
|
|
|
|
|
63
|
return $self->_restored(1); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub DEMOLISH { |
62
|
4
|
|
|
4
|
0
|
11900
|
my $self = shift; |
63
|
4
|
100
|
|
|
|
63
|
$self->restore unless $self->_restored; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
4
|
|
|
4
|
|
2567
|
no Moo; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
30
|
|
67
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
'Sanctify yourself, set yourself free'; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
__END__ |