line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Build::Hopen::Scope::Environment - a hopen Scope for %ENV |
2
|
|
|
|
|
|
|
package Build::Hopen::Scope::Environment; |
3
|
3
|
|
|
3
|
|
1578
|
use Build::Hopen::Base; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
38
|
|
4
|
3
|
|
|
3
|
|
663
|
use Build::Hopen qw(hlog); |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
206
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.000007'; # TRIAL |
7
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
|
18
|
use parent 'Build::Hopen::Scope'; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
20
|
|
9
|
|
|
|
|
|
|
|
10
|
3
|
|
|
3
|
|
166
|
use Build::Hopen::Arrrgs; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
108
|
|
11
|
3
|
|
|
3
|
|
17
|
use Set::Scalar; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
1242
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# Docs {{{1 |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 NAME |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
Build::Hopen::Scope::Environment - a Build::Hopen::Scope of %ENV |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 SYNOPSIS |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
This is a thin wrapper around C<%ENV>, implemented as a |
22
|
|
|
|
|
|
|
L. It only supports one set of data |
23
|
|
|
|
|
|
|
(L), which is named C<0> for consistency |
24
|
|
|
|
|
|
|
with L. |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 METHODS |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=cut |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# }}}1 |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
### Protected functions ### |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# Don't support -set, but permit `-set=>0` for the sake of code calling |
35
|
|
|
|
|
|
|
# through the Scope interface. Call as `_set0($set)`. |
36
|
|
|
|
|
|
|
# Returns truthy of OK, falsy if not. |
37
|
|
|
|
|
|
|
# Better a readily-obvious crash than a subtle bug! |
38
|
|
|
|
|
|
|
sub _set0 { |
39
|
13
|
|
50
|
13
|
|
68
|
$_[0] //= 0; # Give the caller a default set |
40
|
13
|
|
|
|
|
24
|
my $set = shift; |
41
|
13
|
50
|
33
|
|
|
52
|
return false if defined($set) && $set ne '0' && $set ne '*'; |
|
|
|
33
|
|
|
|
|
42
|
13
|
|
|
|
|
188
|
return true; |
43
|
|
|
|
|
|
|
} #_set0() |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head2 _find_here |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
Find a named data item in C<%ENV> and return it. Returns undef on |
48
|
|
|
|
|
|
|
failure. |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=cut |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub _find_here { |
53
|
9
|
|
|
9
|
|
43
|
my ($self, %args) = parameters('self', [qw(name ; set)], @_); |
54
|
9
|
50
|
|
|
|
29
|
_set0 $args{set} or croak 'I only support set 0'; |
55
|
9
|
|
|
|
|
27
|
my $val = $ENV{$args{name}}; |
56
|
9
|
100
|
|
|
|
27
|
return undef unless defined $val; |
57
|
6
|
50
|
|
|
|
31
|
return ($args{set} eq '*') ? { 0 => $val } : $val; |
58
|
|
|
|
|
|
|
} #_find_here() |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head2 add |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
Updates the corresponding environment variables, in order, by setting C<$ENV{}>. |
63
|
|
|
|
|
|
|
Returns the instance. |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=cut |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub add { |
68
|
1
|
|
|
1
|
1
|
1036
|
my $self = shift; |
69
|
1
|
50
|
|
|
|
5
|
croak "Got an odd number of parameters" if @_%2; |
70
|
1
|
|
|
|
|
5
|
while(@_) { |
71
|
1
|
|
|
|
|
3
|
my $k = shift; |
72
|
1
|
|
|
|
|
10
|
$ENV{$k} = shift; |
73
|
|
|
|
|
|
|
} |
74
|
1
|
|
|
|
|
3
|
return $self; |
75
|
|
|
|
|
|
|
} #add() |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head2 _names_here |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
Add the names in C<%ENV> to the given L. |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=cut |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub _names_here { |
84
|
4
|
|
|
4
|
|
20
|
my ($self, %args) = parameters('self', [qw(retval ; set)], @_); |
85
|
4
|
50
|
|
|
|
18
|
_set0 $args{set} or croak 'I only support set 0'; |
86
|
4
|
|
|
|
|
46
|
$args{retval}->insert(keys %ENV); |
87
|
4
|
|
|
0
|
|
996
|
hlog { __PACKAGE__ . '::_names_here', Dumper $args{retval} }; |
|
0
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
} #_names_here() |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
1; |
91
|
|
|
|
|
|
|
__END__ |