Hopen/Scope/Environment.pm

filter: Statementstmt 97.2% 35 / 36 Branchbran 83.3% 10 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 90.0% 9 / 10 Podpod 100% 1 / 1 totaltotal 93.2% 55 / 59 CC 7 SCAR 8.2
CC
7
Cov
94%
_find_here
4.0
put
3.0
_names_here
2.1
CRAP 2.3
« Hopen/G/Entity.pm ↑ Summary Hopen/Scope/Inputs.pm »
1 # Data::Hopen::Scope::Environment - a hopen Scope for %ENV
2 # TODO handle $set == FIRST_ONLY
3 package Data::Hopen::Scope::Environment;
4 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 7 ▶use Data::Hopen::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 7 our $VERSION = '0.000018';
8  
9 7 ▶use Data::Hopen::Scope qw(:default :internal);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 7 ▶use parent 'Data::Hopen::Scope';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 7 ▶use Data::Hopen qw(hlog getparameters);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 7 ▶use Set::Scalar;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 # Docs {{{1
16  
17 =head1 NAME
18  
19 Data::Hopen::Scope::Environment - a Data::Hopen::Scope of %ENV
20  
21 =head1 SYNOPSIS
22  
23 This is a thin wrapper around C<%ENV>, implemented as a
24 L<Data::Hopen::Scope>. It only supports one set of data
25 (L<Data::Hopen::Scope/$set>), which is named C<0> for consistency
26 with L<Data::Hopen::Scope::Hash>.
27  
28 =head1 METHODS
29  
30 Note: L<Data::Hopen::Scope/merge> is unsupported.
31  
32 =cut
33  
34 # }}}1
35  
36 ### Protected functions ###
37  
38 =head2 _find_here
39  
40 Find a named data item in C<%ENV> and return it. Returns undef on
41 failure.
42  
43 =cut
44  
45 sub _find_here {
46 12 ▶ my ($self, %args) = getparameters('self', [qw(name ; set)], @_);
Subroutine _find_here: called CC=4 SCAR=13.9
47 12 ▶ _set0 $args{set} or croak 'I only support set 0';
Branch: 1 branch
BranchTrueFalseTotal
_set0($args{"set"}) or croak("I only support set 0") 0 12 12
48 12 my $val = $ENV{$args{name}};
49 12 ▶ return undef unless defined $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 3 9 12
50 9 ▶ return ($args{set} eq '*') ? { 0 => $val } : $val;
Branch: 1 branch
BranchTrueFalseTotal
$args{'set'} eq '*' ? : 1 8 9
51 } #_find_here()
52  
53 =head2 put
54  
55 Updates the corresponding environment variables, in order, by setting C<$ENV{}>.
56 Returns the instance.
57  
58 =cut
59  
60 sub put {
61 3 ▶ my $self = shift;
Subroutine put: called CC=3 SCAR=11.0
Pod documented
62 3 ▶ croak "Got an odd number of parameters" if @_%2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ % 2 1 2 3
63 2 ▶ while(@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 2 3
64 1 my $k = shift;
65 1 $ENV{$k} = shift;
66 }
67 2 return $self;
68 } #add()
69  
70 =head2 _names_here
71  
72 Add the names in C<%ENV> to the given L<Set::Scalar>.
73  
74 =cut
75  
76 sub _names_here {
77 4 ▶ my ($self, %args) = getparameters('self', [qw(retval ; set)], @_);
Subroutine _names_here: called CC=2 SCAR=7.4
78 4 ▶ _set0 $args{set} or croak 'I only support set 0';
Branch: 1 branch
BranchTrueFalseTotal
_set0($args{"set"}) or croak("I only support set 0") 0 4 4
79 4 $args{retval}->insert(keys %ENV);
80 4 ▶ hlog { __PACKAGE__ . '::_names_here', Dumper $args{retval} } 9;
Subroutine __ANON__: not called CC=1 SCAR=1.2
81 # Don't usually log, since the environment is often fairly hefty!
82 } #_names_here()
83  
84 7 1;
85 __END__
« Hopen/G/Entity.pm ↑ Summary Hopen/Scope/Inputs.pm »