| 1 | package Env::Bash; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use 5.008; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 4 | require Exporter; | |||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 4 | our @ISA = qw(Exporter); | |||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 4 | our @EXPORT = qw( get_env_var get_env_keys ); | |||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 4 | our $VERSION = '0.00_05'; | |||||||||||||||||||||||||||||||||||||||||
| 16 | 4 | $VERSION = eval $VERSION; | |||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | Env::Bash - Perl extension for accessing _aLL_ bash environment variables. | ||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | use Env::Bash; | ||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | Standard interface: | ||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | my @var = get_env_var( "SORCERER_MIRRORS", | ||||||||||||||||||||||||||||||||||||||||||
| 31 | Source => "/etc/sorcery/config", ); | ||||||||||||||||||||||||||||||||||||||||||
| 32 | print "SORCERER_MIRRORS via get_env_var:\n", | ||||||||||||||||||||||||||||||||||||||||||
| 33 | join( "\n", @var ), "\ncount = ", scalar @var, "\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | @var = Env::Bash::SORCERER_MIRRORS | ||||||||||||||||||||||||||||||||||||||||||
| 36 | ( Source => "/etc/sorcery/config", ); | ||||||||||||||||||||||||||||||||||||||||||
| 37 | print "SORCERER_MIRRORS via name:\n", | ||||||||||||||||||||||||||||||||||||||||||
| 38 | join( "\n", @var ), "\ncount = ", scalar @var, "\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | my @keys = get_env_keys( Source => "/etc/sorcery/config", | ||||||||||||||||||||||||||||||||||||||||||
| 41 | SourceOnly => 1, ); | ||||||||||||||||||||||||||||||||||||||||||
| 42 | print "first 10 keys:\n", map { " $_\n" } @keys[0..9]; | ||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | # ------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 47 | # Implementation - AUTOLOAD | ||||||||||||||||||||||||||||||||||||||||||
| 48 | # ------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | sub AUTOLOAD { | ||||||||||||||||||||||||||||||||||||||||||
| 51 | 3 | ▶ | my $name = our $AUTOLOAD; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: called CC=6 SCAR=32.9
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 3 | ▶ | return if $name =~ /DESTROY$/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | $name =~ s/^.*:://; | |||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | return unless $name =~ /^[_A-Z][_A-Z0-9]*$/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | my $s = shift; | |||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | $s && ref $s && $s->isa( 'Env::Bash' ) ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$s and ref $s and $s->isa("Env::Bash")
$s and ref $s
MC/DC0%0/3
$s and ref $s and $s->isa("Env::Bash")
$s
ref $s
$s->isa("Env::Bash")
Truth table0%0/4
A and B and C
A= $sB= ref $sC= $s->isa("Env::Bash")
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | $s->get( $name, @_ ) : | ||||||||||||||||||||||||||||||||||||||||||
| 58 | _get_env_var( $name, $s, @_ ); | ||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | # ------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 62 | # Implementation - exported | ||||||||||||||||||||||||||||||||||||||||||
| 63 | # ------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | sub get_env_var | ||||||||||||||||||||||||||||||||||||||||||
| 66 | { | ||||||||||||||||||||||||||||||||||||||||||
| 67 | 29 | ▶ | _get_env_var( @_ ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_env_var: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | sub get_env_keys | ||||||||||||||||||||||||||||||||||||||||||
| 71 | { | ||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | _get_env_keys( @_ ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_env_keys: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | Object oriented interface: | ||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | my $be = Env::Bash->new( Source => "/etc/sorcery/config", | ||||||||||||||||||||||||||||||||||||||||||
| 80 | Keys => 1, ); | ||||||||||||||||||||||||||||||||||||||||||
| 81 | my @var = $be->get( "SORCERER_MIRRORS" ); | ||||||||||||||||||||||||||||||||||||||||||
| 82 | print "SORCERER_MIRRORS via get:\n", | ||||||||||||||||||||||||||||||||||||||||||
| 83 | join( "\n", @var ), "\ncount = ", scalar @var, "\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | @var = $be->SORCERER_MIRRORS; | ||||||||||||||||||||||||||||||||||||||||||
| 86 | print "SORCERER_MIRRORS via name:\n", | ||||||||||||||||||||||||||||||||||||||||||
| 87 | join( "\n", @var ), "\ncount = ", scalar @var, "\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | $be = Env::Bash->new( Keys => 1,); | ||||||||||||||||||||||||||||||||||||||||||
| 90 | @var = $be->HOSTTYPE; | ||||||||||||||||||||||||||||||||||||||||||
| 91 | print "HOSTTYPE via name:\n", | ||||||||||||||||||||||||||||||||||||||||||
| 92 | join( "\n", @var ), "\ncount = ", scalar @var, "\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | if( $be->exists( 'BASH_VERSINFO' ) ) { | ||||||||||||||||||||||||||||||||||||||||||
| 95 | print "BASH_VERSINFO =>\n ", | ||||||||||||||||||||||||||||||||||||||||||
| 96 | join( "\n ", $be->BASH_VERSINFO ), "\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | my %options = $be->options( [], Keys => 1 ); | ||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | # ------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 104 | # Implementation - oo i/f | ||||||||||||||||||||||||||||||||||||||||||
| 105 | # ------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | sub new | ||||||||||||||||||||||||||||||||||||||||||
| 108 | { | ||||||||||||||||||||||||||||||||||||||||||
| 109 | 1 | ▶ | my( $invocant, @options ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | 1 | ▶ | my $class = ref( $invocant ) || $invocant; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $invocant || $invocant
MC/DC0%0/2
ref $invocant || $invocant
ref $invocant
$invocant
Truth table33%1/3
A || B
A= ref $invocantB= $invocant
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | 1 | my $s = { options => {}, }; | |||||||||||||||||||||||||||||||||||||||||
| 112 | 1 | bless $s, $class; | |||||||||||||||||||||||||||||||||||||||||
| 113 | 1 | _get_bash(); | |||||||||||||||||||||||||||||||||||||||||
| 114 | 1 | $s->options( @options ); | |||||||||||||||||||||||||||||||||||||||||
| 115 | 1 | ▶ | $s->keys() if $s->{options}{Keys}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | 1 | $s; | |||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | sub get | ||||||||||||||||||||||||||||||||||||||||||
| 120 | { | ||||||||||||||||||||||||||||||||||||||||||
| 121 | 29 | ▶ | my( $s, $name, @options ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | 29 | my %options = $s->options( @options ); | |||||||||||||||||||||||||||||||||||||||||
| 123 | 29 | _get_env_var( $name, %options ); | |||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | sub exists | ||||||||||||||||||||||||||||||||||||||||||
| 127 | { | ||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | ▶ | my( $s, $key ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
exists: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | ▶ | unless( $s->{keys} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | $s->{options}{Keys} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | $s->keys(); | |||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | grep /^$key$/, @{$s->{keys}}; | |||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | sub keys | ||||||||||||||||||||||||||||||||||||||||||
| 137 | { | ||||||||||||||||||||||||||||||||||||||||||
| 138 | 2 | ▶ | my( $s, @options ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
keys: called CC=7 SCAR=28.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 139 | 2 | $s->options( @options ); | |||||||||||||||||||||||||||||||||||||||||
| 140 | 2 | ▶ | if( exists $s->{keys} && @{$s->{keys}} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $s->{"keys"} and @{$s->{"keys"};}
MC/DC0%0/2
exists $s->{"keys"} and @{$s->{"keys"};}
exists $s->{"keys"}
@{$s->{"keys"};}
Truth table33%1/3
A and B
A= exists $s->{"keys"}B= @{$s->{"keys"};}
| |||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | ▶ | return unless defined wantarray; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | ▶ | return wantarray ? @{$s->{keys}} : $s->{keys}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||
| 144 | 2 | my @keys = _get_env_keys( %{$s->{options}} ); | |||||||||||||||||||||||||||||||||||||||||
| 145 | 1 | $s->{keys} = [ @keys ]; | |||||||||||||||||||||||||||||||||||||||||
| 146 | 1 | ▶ | return unless defined wantarray; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | ▶ | wantarray ? @keys : \@keys; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||
| 150 | sub reload_keys | ||||||||||||||||||||||||||||||||||||||||||
| 151 | { | ||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | ▶ | my( $s, @options ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
reload_keys: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | delete $s->{keys}; | |||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | $s->keys( @options ); | |||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | sub options | ||||||||||||||||||||||||||||||||||||||||||
| 158 | { | ||||||||||||||||||||||||||||||||||||||||||
| 159 | 34 | ▶ | my $s = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
options: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 160 | 34 | my %options = _options( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 161 | 34 | ▶ | unless( %options ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | 32 | ▶ | return unless defined wantarray; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 163 | 28 | ▶ | return wantarray ? %{$s->{options}} : $s->{options}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||
| 165 | 2 | $s->{options} = { %{$s->{options}}, %options }; | |||||||||||||||||||||||||||||||||||||||||
| 166 | 2 | ▶ | return unless defined wantarray; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | 1 | ▶ | return wantarray ? %{$s->{options}} : $s->{options}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | Tie HASH interface: | ||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | my %env = (); | ||||||||||||||||||||||||||||||||||||||||||
| 175 | tie %env, "Env::Bash", Source => "/etc/sorcery/config", ForceArray => 1; | ||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||
| 177 | my $var = $env{SORCERER_MIRRORS}; | ||||||||||||||||||||||||||||||||||||||||||
| 178 | print "SORCERER_MIRRORS via tied hash:\n", | ||||||||||||||||||||||||||||||||||||||||||
| 179 | join( "\n", @$var ), "\ncount = ", scalar @$var, "\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||
| 181 | $var = $env{HOSTTYPE}; | ||||||||||||||||||||||||||||||||||||||||||
| 182 | print "HOSTTYPE via tied hash:\n", | ||||||||||||||||||||||||||||||||||||||||||
| 183 | join( "\n", @$var ), "\ncount = ", scalar @$var, "\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||
| 185 | while( my( $key, $value ) = each %env ) { | ||||||||||||||||||||||||||||||||||||||||||
| 186 | print "$key =>\n ", join( "\n ", @$value ), "\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||
| 189 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||
| 191 | # ------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 192 | # Implementation - tie hash | ||||||||||||||||||||||||||||||||||||||||||
| 193 | # ------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||
| 195 | sub TIEHASH | ||||||||||||||||||||||||||||||||||||||||||
| 196 | { | ||||||||||||||||||||||||||||||||||||||||||
| 197 | 2 | ▶ | my( $invocant, @options ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
TIEHASH: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||
| 198 | 2 | ▶ | my $class = ref( $invocant ) || $invocant; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $invocant || $invocant
MC/DC0%0/2
ref $invocant || $invocant
ref $invocant
$invocant
Truth table33%1/3
A || B
A= ref $invocantB= $invocant
| |||||||||||||||||||||||||||||||||||||||||||
| 199 | 2 | my $s = { options => {}, }; | |||||||||||||||||||||||||||||||||||||||||
| 200 | 2 | bless $s, $class; | |||||||||||||||||||||||||||||||||||||||||
| 201 | 2 | _get_bash(); | |||||||||||||||||||||||||||||||||||||||||
| 202 | 2 | $s->options( @options ); | |||||||||||||||||||||||||||||||||||||||||
| 203 | 2 | $s->keys(); | |||||||||||||||||||||||||||||||||||||||||
| 204 | 1 | $s; | |||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||
| 207 | sub FETCH | ||||||||||||||||||||||||||||||||||||||||||
| 208 | { | ||||||||||||||||||||||||||||||||||||||||||
| 209 | 28 | ▶ | my( $s, $key ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
FETCH: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||
| 210 | 28 | ▶ | return undef unless $s->EXISTS( $key ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 211 | 28 | _get_env_var( $key, %{$s->{options}} ); | |||||||||||||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||
| 214 | sub STORE | ||||||||||||||||||||||||||||||||||||||||||
| 215 | { | ||||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | ▶ | Carp::croak( "Tied hash is read-only\n" ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
STORE: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||
| 219 | sub DELETE | ||||||||||||||||||||||||||||||||||||||||||
| 220 | { | ||||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | ▶ | Carp::croak( "Tied hash is read-only\n" ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DELETE: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||
| 224 | sub CLEAR | ||||||||||||||||||||||||||||||||||||||||||
| 225 | { | ||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | ▶ | Carp::croak( "Tied hash is read-only\n" ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
CLEAR: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||
| 229 | sub EXISTS | ||||||||||||||||||||||||||||||||||||||||||
| 230 | { | ||||||||||||||||||||||||||||||||||||||||||
| 231 | 28 | ▶ | my( $s, $key ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
EXISTS: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 232 | 28 | grep /^$key$/, @{$s->{keys}}; | |||||||||||||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||
| 235 | sub FIRSTKEY | ||||||||||||||||||||||||||||||||||||||||||
| 236 | { | ||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | ▶ | my $s = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
FIRSTKEY: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | $s->{keys}[0]; | |||||||||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||
| 241 | sub NEXTKEY | ||||||||||||||||||||||||||||||||||||||||||
| 242 | { | ||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | ▶ | my( $s, $prevkey ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
NEXTKEY: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | my $idx = 0; | |||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | ▶ | return $s->FIRSTKEY() unless $prevkey; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | ▶ | for( ; $idx < @{$s->{keys}}; $idx++ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | ▶ | last if $s->{keys}[$idx] eq $prevkey; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | $s->{keys}[++$idx]; | |||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||
| 252 | # ------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 253 | # 'Private' subs | ||||||||||||||||||||||||||||||||||||||||||
| 254 | # ( denoted by leading '_' ) | ||||||||||||||||||||||||||||||||||||||||||
| 255 | # ------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||
| 257 | sub _get_env_var | ||||||||||||||||||||||||||||||||||||||||||
| 258 | { | ||||||||||||||||||||||||||||||||||||||||||
| 259 | 86 | ▶ | return unless defined wantarray; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_env_var: called CC=9 SCAR=25.6
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 260 | 86 | my $name = shift; | |||||||||||||||||||||||||||||||||||||||||
| 261 | 86 | my %options = _options( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 262 | 86 | ▶ | return undef unless $name; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||
| 264 | 86 | my @script = | |||||||||||||||||||||||||||||||||||||||||
| 265 | ( | ||||||||||||||||||||||||||||||||||||||||||
| 266 | _sources( %options ), | ||||||||||||||||||||||||||||||||||||||||||
| 267 | _script_contents( $name ), | ||||||||||||||||||||||||||||||||||||||||||
| 268 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 269 | 86 | my $script = join ";", @script; | |||||||||||||||||||||||||||||||||||||||||
| 270 | 86 | ▶ | print STDERR "script:\n$script\n" if $options{Debug}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||
| 272 | 86 | my $result = _execute_script( $script, %options ); | |||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||
| 274 | 84 | my $href = _load_contents( $result, %options ); | |||||||||||||||||||||||||||||||||||||||||
| 275 | 84 | ▶ | my @ret = $href->{$name} ? @{$href->{$name}} : () ; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 276 | 84 | ▶ | if( $options{ForceArray} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | ▶ | return wantarray ? @ret : \@ret; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||||||||||||||
| 279 | 84 | ▶ | wantarray ? @ret : ( defined $ret[0] ? $ret[0] : '' ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||
| 282 | sub _get_env_keys | ||||||||||||||||||||||||||||||||||||||||||
| 283 | { | ||||||||||||||||||||||||||||||||||||||||||
| 284 | 2 | ▶ | my %options = _options( @_ ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_env_keys: called CC=6 SCAR=21.3
| |||||||||||||||||||||||||||||||||||||||||||
| 285 | 2 | my $bash = _get_bash(); | |||||||||||||||||||||||||||||||||||||||||
| 286 | 2 | my @sources = _sources( %options ); | |||||||||||||||||||||||||||||||||||||||||
| 287 | 2 | ▶ | my $script = "#!$bash\n" . | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 288 | ( @sources ? join( ';', @sources ).';' : '' ) . | ||||||||||||||||||||||||||||||||||||||||||
| 289 | 'set'; | ||||||||||||||||||||||||||||||||||||||||||
| 290 | 2 | my $result = _execute_script( $script, %options ); | |||||||||||||||||||||||||||||||||||||||||
| 291 | 1 | my %hkeys = _select_keys( $result, %options ); | |||||||||||||||||||||||||||||||||||||||||
| 292 | 1 | ▶ | if( @sources && $options{SourceOnly} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@sources and $options{"SourceOnly"}
MC/DC0%0/2
@sources and $options{"SourceOnly"}
@sources
$options{"SourceOnly"}
Truth table33%1/3
A and B
A= @sourcesB= $options{"SourceOnly"}
| |||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | $script = "#!$bash\nset"; | |||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | $result = _execute_script( $script, %options ); | |||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | my %bhkeys = _select_keys( $result, %options ); | |||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | map { delete $hkeys{$_} } CORE::keys %bhkeys; | |||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | delete $hkeys{PIPESTATUS}; # magically appears when a script is run | |||||||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||||||
| 299 | 1 | my @keys = sort( CORE::keys %hkeys ); | |||||||||||||||||||||||||||||||||||||||||
| 300 | 1 | ▶ | return unless defined wantarray; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 301 | 1 | ▶ | wantarray ? @keys : \@keys; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||
| 304 | sub _select_keys | ||||||||||||||||||||||||||||||||||||||||||
| 305 | { | ||||||||||||||||||||||||||||||||||||||||||
| 306 | 1 | ▶ | my $result = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_select_keys: called CC=6 SCAR=19.1
| |||||||||||||||||||||||||||||||||||||||||||
| 307 | 1 | my %options = _options( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 308 | 1 | my %hkeys = (); | |||||||||||||||||||||||||||||||||||||||||
| 309 | 1 | pos( $result ) = 0; | |||||||||||||||||||||||||||||||||||||||||
| 310 | 1 | ▶ | while( $result =~ /(.*?)=(?:'.*?'\n|\(.*?\)\n|.*?\n)/sg ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 311 | 36 | my $name = $1; | |||||||||||||||||||||||||||||||||||||||||
| 312 | 36 | ▶ | next unless $name; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 313 | 36 | ▶ | next if $name eq 'BASH_EXECUTION_STRING'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 314 | 36 | ▶ | if( $options{SelectRegex} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | ▶ | next unless $name =~ /$options{SelectRegex}/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||||||||||||||||
| 317 | 36 | $hkeys{$name} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||||||||||||
| 319 | 1 | %hkeys; | |||||||||||||||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||
| 322 | sub _get_bash | ||||||||||||||||||||||||||||||||||||||||||
| 323 | { | ||||||||||||||||||||||||||||||||||||||||||
| 324 | 5 | ▶ | my $bash = $ENV{SHELL}; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_bash: called CC=16 SCAR=39.1
| |||||||||||||||||||||||||||||||||||||||||||
| 325 | 5 | ▶ | return $bash if $bash && -f $bash && -x _; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$bash and -f $bash and -x _
$bash and -f $bash
MC/DC0%0/3
$bash and -f $bash and -x _
$bash
-f $bash
-x _
Truth table25%1/4
A and B and C
A= $bashB= -f $bashC= -x _
| |||||||||||||||||||||||||||||||||||||||||||
| 326 | 5 | $bash = `echo "\$SHELL"`; | |||||||||||||||||||||||||||||||||||||||||
| 327 | 5 | ▶ | return $bash if $bash && -f $bash && -x _; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$bash and -f $bash and -x _
$bash and -f $bash
MC/DC0%0/3
$bash and -f $bash and -x _
$bash
-f $bash
-x _
Truth table25%1/4
A and B and C
A= $bashB= -f $bashC= -x _
| |||||||||||||||||||||||||||||||||||||||||||
| 328 | 5 | $bash = $ENV{BASH}; | |||||||||||||||||||||||||||||||||||||||||
| 329 | 5 | ▶ | return $bash if $bash && -f $bash && -x _; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$bash and -f $bash and -x _
$bash and -f $bash
MC/DC0%0/3
$bash and -f $bash and -x _
$bash
-f $bash
-x _
Truth table25%1/4
A and B and C
A= $bashB= -f $bashC= -x _
| |||||||||||||||||||||||||||||||||||||||||||
| 330 | 5 | $bash = `echo "\$BASH"`; | |||||||||||||||||||||||||||||||||||||||||
| 331 | 5 | ▶ | return $bash if $bash && -f $bash && -x _; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$bash and -f $bash and -x _
$bash and -f $bash
MC/DC0%0/3
$bash and -f $bash and -x _
$bash
-f $bash
-x _
Truth table25%1/4
A and B and C
A= $bashB= -f $bashC= -x _
| |||||||||||||||||||||||||||||||||||||||||||
| 332 | 5 | $bash = '/bin/bash'; | |||||||||||||||||||||||||||||||||||||||||
| 333 | 5 | ▶ | return $bash if $bash && -f $bash && -x _; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$bash and -f $bash and -x _
$bash and -f $bash
MC/DC0%0/3
$bash and -f $bash and -x _
$bash
-f $bash
-x _
Truth table25%1/4
A and B and C
A= $bashB= -f $bashC= -x _
| |||||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | Carp::croak( "Oops: cannot find bash.\n" ); | |||||||||||||||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||
| 337 | sub _sources | ||||||||||||||||||||||||||||||||||||||||||
| 338 | { | ||||||||||||||||||||||||||||||||||||||||||
| 339 | 88 | ▶ | my %options = _options( @_ ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_sources: called CC=11 SCAR=28.0
| |||||||||||||||||||||||||||||||||||||||||||
| 340 | my @srcs = | ||||||||||||||||||||||||||||||||||||||||||
| 341 | 3 | ▶ | map { split /;/, $_ } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
ref $options{"Source"} and ref $options{"Source"} eq "ARRAY"
MC/DC0%0/2
ref $options{"Source"} and ref $options{"Source"} eq "ARRAY"
ref $options{"Source"}
ref $options{"Source"} eq "ARRAY"
Truth table33%1/3
A and B
A= ref $options{"Source"}B= ref $options{"Source"} eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||
| 342 | $options{Source} ? | ||||||||||||||||||||||||||||||||||||||||||
| 343 | ( ref $options{Source} && ref $options{Source} eq 'ARRAY' ? | ||||||||||||||||||||||||||||||||||||||||||
| 344 | 88 | @{$options{Source}} : $options{Source} ) : (); | |||||||||||||||||||||||||||||||||||||||||
| 345 | 88 | ▶ | return () unless @srcs; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 346 | 3 | my @sources = (); | |||||||||||||||||||||||||||||||||||||||||
| 347 | 3 | for my $source( @srcs ) { | |||||||||||||||||||||||||||||||||||||||||
| 348 | 3 | ▶ | next unless $source; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 349 | 3 | $source =~ s/^\. //; | |||||||||||||||||||||||||||||||||||||||||
| 350 | 3 | ▶ | next unless $source; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 351 | 3 | ▶ | unless( -f $source ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | warn "Source '$source' not found. Ignored.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 353 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||||||||||||||
| 355 | 3 | ▶ | unless( -x _ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | warn "Source '$source' not executable. Ignored.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 357 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||||||||||||||||
| 359 | 3 | my $fh; | |||||||||||||||||||||||||||||||||||||||||
| 360 | 3 | ▶ | unless( open( $fh, $source ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | warn "Source '$source' open error: $!. Ignored.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||||||||||||||||
| 364 | 3 | close $fh; | |||||||||||||||||||||||||||||||||||||||||
| 365 | 3 | push @sources, ". $source"; | |||||||||||||||||||||||||||||||||||||||||
| 366 | } | ||||||||||||||||||||||||||||||||||||||||||
| 367 | 3 | @sources; | |||||||||||||||||||||||||||||||||||||||||
| 368 | } | ||||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||||
| 370 | sub _script_contents | ||||||||||||||||||||||||||||||||||||||||||
| 371 | { | ||||||||||||||||||||||||||||||||||||||||||
| 372 | 86 | ▶ | my( $name ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_script_contents: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 373 | ( | ||||||||||||||||||||||||||||||||||||||||||
| 374 | 86 | "for element in \$(seq 0 \$((\${#${name}[@]} - 1)))", | |||||||||||||||||||||||||||||||||||||||||
| 375 | "do echo \"<<8774$name>>\${${name}[\$element]}<<4587>>\"", | ||||||||||||||||||||||||||||||||||||||||||
| 376 | "done", | ||||||||||||||||||||||||||||||||||||||||||
| 377 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 378 | } | ||||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||||
| 380 | sub _execute_script | ||||||||||||||||||||||||||||||||||||||||||
| 381 | { | ||||||||||||||||||||||||||||||||||||||||||
| 382 | 88 | ▶ | my $script = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_execute_script: called CC=5 SCAR=16.4
| |||||||||||||||||||||||||||||||||||||||||||
| 383 | 88 | my %options = _options( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 384 | 88 | ▶ | print STDERR "script:\n$script\n" if $options{Debug}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 385 | 88 | my $result = eval { `$script 2>&1` }; | |||||||||||||||||||||||||||||||||||||||||
| 386 | 88 | ▶ | Carp::croak | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$? or $@
MC/DC50%1/2
$? or $@
$?
$@
Truth table66%2/3
A or B
A= $?B= $@
| |||||||||||||||||||||||||||||||||||||||||||
| 387 | ( "Oops: internal bash script error or your shell is not bash:\n". | ||||||||||||||||||||||||||||||||||||||||||
| 388 | $result ) if $? || $@; | ||||||||||||||||||||||||||||||||||||||||||
| 389 | 85 | ▶ | print STDERR "script output:\n$result\n" if $options{Debug}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 390 | 85 | $result; | |||||||||||||||||||||||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||
| 393 | sub _load_contents | ||||||||||||||||||||||||||||||||||||||||||
| 394 | { | ||||||||||||||||||||||||||||||||||||||||||
| 395 | 84 | ▶ | my $data = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_load_contents: called CC=3 SCAR=11.8
| |||||||||||||||||||||||||||||||||||||||||||
| 396 | 84 | my %options = _options( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 397 | 84 | my $content = {}; | |||||||||||||||||||||||||||||||||||||||||
| 398 | 84 | pos( $data ) = 0; | |||||||||||||||||||||||||||||||||||||||||
| 399 | 84 | ▶ | while( $data =~ /<<8774(.+?)>>(.*?|)<<4587>>/sg ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 400 | 0 | push @{$content->{$1}}, $2; | |||||||||||||||||||||||||||||||||||||||||
| 401 | } | ||||||||||||||||||||||||||||||||||||||||||
| 402 | 84 | ▶ | print STDERR "content: ", Dumper( $content ) if $options{Debug}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 403 | 84 | $content; | |||||||||||||||||||||||||||||||||||||||||
| 404 | } | ||||||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||||||
| 406 | sub _options | ||||||||||||||||||||||||||||||||||||||||||
| 407 | { | ||||||||||||||||||||||||||||||||||||||||||
| 408 | 383 | ▶ | my %options; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_options: called CC=9 SCAR=25.4
| |||||||||||||||||||||||||||||||||||||||||||
| 409 | 383 | ▶ | if( $_[0] && ref $_[0] && ref $_[0] eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$_[0] and ref $_[0] and ref $_[0] eq "ARRAY"
$_[0] and ref $_[0]
MC/DC0%0/3
$_[0] and ref $_[0] and ref $_[0] eq "ARRAY"
$_[0]
ref $_[0]
ref $_[0] eq "ARRAY"
Truth table50%2/4
A and B and C
A= $_[0]B= ref $_[0]C= ref $_[0] eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||
| 410 | 0 | shift; %options = ( @_, ForceArray => 1, ); | |||||||||||||||||||||||||||||||||||||||||
| 411 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 412 | 383 | %options = @_; | |||||||||||||||||||||||||||||||||||||||||
| 413 | } | ||||||||||||||||||||||||||||||||||||||||||
| 414 | 383 | ▶ | unless( %options ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 415 | 372 | ▶ | return unless defined wantarray; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 416 | 372 | ▶ | return wantarray ? () : []; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||||||||||||||||
| 418 | 11 | ▶ | return unless defined wantarray; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 419 | 11 | ▶ | return wantarray ? %options : \%options; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 420 | } | ||||||||||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||||||||||
| 422 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||||||
| 424 | __END__ | ||||||||||||||||||||||||||||||||||||||||||