Connector/Builtin/Env.pm

filter: Statementstmt 95.2% 40 / 42 Branchbran 100% 4 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 90.9% 10 / 11 Podpod 100% 3 / 3 totaltotal 95.0% 57 / 60 CC 3 SCAR 3.3
CC
3
Cov
96%
get
2.0
get_meta
2.0
_get_node
2.0
CRAP 1.4
« Connector/Wrapper.pm ↑ Summary Connector/Builtin/File/Simple.pm »
1 # Connector::Builtin::Env
2 #
3 # Read values from the environment
4 #
5 # Written by Oliver Welter for the OpenXPKI project 2014
6 #
7 package Connector::Builtin::Env;
8  
9 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use English;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 extends 'Connector::Builtin';
17  
18 1 has '+LOCATION' => ( required => 0 );
19  
20 1 has prefix => (
21 is => 'rw',
22 isa => 'Str',
23 default => ''
24 );
25  
26 6 ▶sub get {
Subroutine get: called CC=2 SCAR=6.9
Pod documented
27  
28 6 my $self = shift;
29 6 my $key = shift;
30 6 my $val = $self->_get_node( $key );
31  
32 6 ▶ if (!defined $val) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $val) 2 4 6
33 2 return $self->_node_not_exists( $key );
34 }
35  
36 4 return $val;
37  
38 }
39  
40 0 ▶sub get_meta {
Subroutine get_meta: not called CC=1 SCAR=6.9
Pod documented
41 0 my $self = shift;
42 0 return { TYPE => "scalar" };
43 }
44  
45 4 ▶sub exists {
Subroutine exists: called CC=1 SCAR=0.0
Pod documented
46  
47 4 my $self = shift;
48 4 my $val = $self->_get_node( shift );
49 4 return defined $val;
50  
51 }
52  
53 10 ▶sub _get_node {
Subroutine _get_node: called CC=2 SCAR=6.9
54  
55 10 my $self = shift;
56  
57 10 my $prefix = $self->prefix();
58  
59 10 my $key = shift;
60 # We expect only a scalar key, so this is a fast and valid conversion
61 10 ▶ $key = $key->[0] if (ref $key eq 'ARRAY');
Branch: 1 branch
BranchTrueFalseTotal
if ref $key eq "ARRAY" 2 8 10
62  
63 10 return $ENV{$prefix.$key};
64  
65 }
66  
67 1 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
68 1 __PACKAGE__->meta->make_immutable;
69  
70 1 1;
71 __END__
« Connector/Wrapper.pm ↑ Summary Connector/Builtin/File/Simple.pm »