| 1 | # Build::Hopen::Scope::Environment - a hopen Scope for %ENV | ||||||||||||||||||||||||||||||||||||||||||
| 2 | package Build::Hopen::Scope::Environment; | ||||||||||||||||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use Build::Hopen::Base; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use Build::Hopen qw(hlog); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 3 | our $VERSION = '0.000008'; # TRIAL | |||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use parent 'Build::Hopen::Scope'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use Build::Hopen::Arrrgs; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use Set::Scalar; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 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<Build::Hopen::Scope>. It only supports one set of data | ||||||||||||||||||||||||||||||||||||||||||
| 23 | (L<Build::Hopen::Scope/$set>), which is named C<0> for consistency | ||||||||||||||||||||||||||||||||||||||||||
| 24 | with L<Build::Hopen::Scope::Hash>. | ||||||||||||||||||||||||||||||||||||||||||
| 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 | 13 | ▶ | sub _set0 { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_set0: called CC=5 SCAR=19.4
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 13 | ▶ | $_[0] //= 0; # Give the caller a default set | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$_[0] //= 0
MC/DC0%0/1
$_[0] //= 0
$_[0]
Truth table50%1/2
A
A= $_[0]
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 13 | my $set = shift; | |||||||||||||||||||||||||||||||||||||||||
| 41 | 13 | ▶ | return false if defined($set) && $set ne '0' && $set ne '*'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
defined $set and $set ne 0 and $set ne "*"
defined $set and $set ne 0
MC/DC0%0/3
defined $set and $set ne 0 and $set ne "*"
defined $set
$set ne 0
$set ne "*"
Truth table25%1/4
A and B and C
A= defined $setB= $set ne 0C= $set ne "*"
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 13 | 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 | 9 | ▶ | sub _find_here { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_find_here: called CC=4 SCAR=14.1
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | 9 | my ($self, %args) = parameters('self', [qw(name ; set)], @_); | |||||||||||||||||||||||||||||||||||||||||
| 54 | 9 | ▶ | _set0 $args{set} or croak 'I only support set 0'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | 9 | my $val = $ENV{$args{name}}; | |||||||||||||||||||||||||||||||||||||||||
| 56 | 9 | ▶ | return undef unless defined $val; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 6 | ▶ | return ($args{set} eq '*') ? { 0 => $val } : $val; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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 | 1 | ▶ | sub add { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 69 | 1 | ▶ | croak "Got an odd number of parameters" if @_%2; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 1 | ▶ | while(@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | 1 | my $k = shift; | |||||||||||||||||||||||||||||||||||||||||
| 72 | 1 | $ENV{$k} = shift; | |||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||
| 74 | 1 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 75 | } #add() | ||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | =head2 _names_here | ||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | Add the names in C<%ENV> to the given L<Set::Scalar>. | ||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | 4 | ▶ | sub _names_here { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_names_here: called CC=2 SCAR=7.4
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 4 | my ($self, %args) = parameters('self', [qw(retval ; set)], @_); | |||||||||||||||||||||||||||||||||||||||||
| 85 | 4 | ▶ | _set0 $args{set} or croak 'I only support set 0'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | 4 | $args{retval}->insert(keys %ENV); | |||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | ▶ | hlog { __PACKAGE__ . '::_names_here', Dumper $args{retval} }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | } #_names_here() | ||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 91 | __END__ | ||||||||||||||||||||||||||||||||||||||||||