| 1 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||
| 4 | package Config::Entities; | ||||||||||||||||||||||||||||||||||||
| 5 | 1 | $Config::Entities::VERSION = '1.07'; | |||||||||||||||||||||||||||||||||||
| 6 | # ABSTRACT: An multi-level overridable perl based configuration module | ||||||||||||||||||||||||||||||||||||
| 7 | # PODNAME: Config::Entities | ||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Cwd qw(abs_path); | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use File::Find; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use File::Spec; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use Log::Any; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||
| 15 | 1 | my $logger = Log::Any->get_logger(); | |||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||
| 17 | 13 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 18 | 13 | my ( $class, @args ) = @_; | |||||||||||||||||||||||||||||||||||
| 19 | 13 | return bless( {}, $class )->_init(@args); | |||||||||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||
| 22 | 2 | ▶ | sub as_hashref { | ||||||||||||||||||||||||||||||||||
|
Subroutine
as_hashref: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 23 | 2 | return _copy(@_); | |||||||||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||
| 26 | 38 | ▶ | sub _copy { | ||||||||||||||||||||||||||||||||||
|
Subroutine
_copy: called CC=6 SCAR=21.4
| |||||||||||||||||||||||||||||||||||||
| 27 | 38 | my ($value) = @_; | |||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||
| 29 | 38 | my $ref = ref($value); | |||||||||||||||||||||||||||||||||||
| 30 | 38 | ▶ | if ($ref) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 31 | 14 | ▶ | if ( $ref eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||
| 32 | 0 | return [ map { _copy($_) } @$value ]; | |||||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||||
| 34 | ▶ | elsif ( $ref eq 'HASH' || $value->isa('Config::Entities') ) { | |||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$ref eq "HASH" or $value->isa("Config::Entities")
MC/DC0%0/2
$ref eq "HASH" or $value->isa("Config::Entities")
$ref eq "HASH"
$value->isa("Config::Entities")
Truth table66%2/3
A or B
A= $ref eq "HASH"B= $value->isa("Config::Entities")
| |||||||||||||||||||||||||||||||||||||
| 35 | 14 | return { map { $_ => _copy( $value->{$_} ) } keys(%$value) }; | |||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||
| 37 | elsif ( $ref eq 'SCALAR' ) { | ||||||||||||||||||||||||||||||||||||
| 38 | 0 | return $value; | |||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||
| 40 | else { | ||||||||||||||||||||||||||||||||||||
| 41 | 0 | croak("unsupported type '$ref'"); | |||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||
| 44 | else { | ||||||||||||||||||||||||||||||||||||
| 45 | 24 | return $value; | |||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||
| 49 | 13 | ▶ | sub _add_properties { | ||||||||||||||||||||||||||||||||||
|
Subroutine
_add_properties: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 50 | 13 | my ( $self, $properties, $more_properties ) = @_; | |||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||
| 52 | 13 | foreach my $key ( keys( %{$more_properties} ) ) { | |||||||||||||||||||||||||||||||||||
| 53 | 20 | $properties->{$key} = $more_properties->{$key}; | |||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||
| 57 | 5 | ▶ | sub fill { | ||||||||||||||||||||||||||||||||||
|
Subroutine
fill: called CC=9 SCAR=22.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 58 | 5 | my ( $self, $coordinate, $hashref, %options ) = @_; | |||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||
| 60 | 5 | my @entity = $self->get_entity( $coordinate, %options ); | |||||||||||||||||||||||||||||||||||
| 61 | 5 | foreach my $key ( keys(%$hashref) ) { | |||||||||||||||||||||||||||||||||||
| 62 | 11 | ▶ | if ( ref( $entity[0] ) eq 'HASH' && exists( $entity[0]->{$key} ) ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition100%3/3
ref $entity[0] eq "HASH" and exists $entity[0]{$key}
MC/DC100%2/2
ref $entity[0] eq "HASH" and exists $entity[0]{$key}
ref $entity[0] eq "HASH"
exists $entity[0]{$key}
Truth table100%3/3
A and B
A= ref $entity[0] eq "HASH"B= exists $entity[0]{$key}
| |||||||||||||||||||||||||||||||||||||
| 63 | 5 | $hashref->{$key} = $entity[0]->{$key}; | |||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||
| 65 | ▶ | elsif ( $hashref->{$key} && $hashref->{$key} eq 'Config::Entities::entity' ) { | |||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$hashref->{$key} and $hashref->{$key} eq "Config::Entities::entity"
MC/DC50%1/2
$hashref->{$key} and $hashref->{$key} eq "Config::Entities::entity"
$hashref->{$key}
$hashref->{$key} eq "Config::Entities::entity"
Truth table66%2/3
A and B
A= $hashref->{$key}B= $hashref->{$key} eq "Config::Entities::entity"
| |||||||||||||||||||||||||||||||||||||
| 66 | 1 | $hashref->{$key} = $entity[0]; | |||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||
| 68 | elsif ( $options{ancestry} ) { | ||||||||||||||||||||||||||||||||||||
| 69 | 5 | ▶ | for ( my $index = 1; $index < scalar(@entity); $index++ ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 70 | 14 | ▶ | if ( defined( $entity[$index]->{$key} ) ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 71 | 5 | $hashref->{$key} = $entity[$index]->{$key}; | |||||||||||||||||||||||||||||||||||
| 72 | 5 | last; | |||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||
| 78 | 5 | return $hashref; | |||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||
| 81 | 9 | ▶ | sub get_entity { | ||||||||||||||||||||||||||||||||||
|
Subroutine
get_entity: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 82 | 9 | my ( $self, $coordinate, %options ) = @_; | |||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||
| 84 | 9 | my @result = ($self); | |||||||||||||||||||||||||||||||||||
| 85 | 9 | ▶ | if ($coordinate) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 86 | 9 | foreach my $coordinate_part ( split( /\./, $coordinate ) ) { | |||||||||||||||||||||||||||||||||||
| 87 | 25 | my $child = $result[0]->{$coordinate_part}; | |||||||||||||||||||||||||||||||||||
| 88 | 25 | ▶ | return if ( !defined($child) ); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 89 | 25 | unshift( @result, $child ); | |||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||
| 92 | 9 | ▶ | return $options{ancestry} ? @result : shift(@result); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||
| 95 | 13 | ▶ | sub _init { | ||||||||||||||||||||||||||||||||||
|
Subroutine
_init: called CC=10 SCAR=23.0
| |||||||||||||||||||||||||||||||||||||
| 96 | 13 | my ( $self, @args ) = @_; | |||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||
| 98 | # if last arg is a hash, it is an options hash | ||||||||||||||||||||||||||||||||||||
| 99 | 13 | ▶ | my $options = | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 100 | ref( $args[$#args] ) eq 'HASH' | ||||||||||||||||||||||||||||||||||||
| 101 | ? pop(@args) | ||||||||||||||||||||||||||||||||||||
| 102 | : {}; | ||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||
| 104 | # all other args are entities roots | ||||||||||||||||||||||||||||||||||||
| 105 | 13 | my @entities_roots = @args; | |||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||
| 107 | 13 | my $properties = {}; | |||||||||||||||||||||||||||||||||||
| 108 | 13 | ▶ | if ( $options->{properties_file} ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||
| 110 | # merge in properties from files | ||||||||||||||||||||||||||||||||||||
| 111 | my @properties_files = | ||||||||||||||||||||||||||||||||||||
| 112 | ref( $options->{properties_file} ) eq 'ARRAY' | ||||||||||||||||||||||||||||||||||||
| 113 | 1 | ? @{ $options->{properties_file} } | |||||||||||||||||||||||||||||||||||
| 114 | 6 | ▶ | : ( $options->{properties_file} ); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||
| 116 | 6 | foreach my $properties_file (@properties_files) { | |||||||||||||||||||||||||||||||||||
| 117 | 7 | $self->_add_properties( $properties, do($properties_file) ); | |||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||
| 120 | 13 | ▶ | if ( $options->{properties} ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||
| 122 | # merge in direct properties | ||||||||||||||||||||||||||||||||||||
| 123 | 6 | $self->_add_properties( $properties, $options->{properties} ); | |||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||
| 126 | 13 | ▶ | if ( $options->{entity} ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 127 | 4 | foreach my $key ( keys( %{ $options->{entity} } ) ) { | |||||||||||||||||||||||||||||||||||
| 128 | 7 | _merge( $self, $key, $options->{entity}{$key} ); | |||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||
| 132 | 13 | ▶ | if ( scalar(@entities_roots) ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 133 | find( | ||||||||||||||||||||||||||||||||||||
| 134 | 52 | ▶ | sub { | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||||||||||
| 135 | 52 | ▶ | if ( $_ =~ /^(.*)\.pmc?$/ && -f $File::Find::name ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$_ =~ /^(.*)\.pmc?$/ and -f $File::Find::name
MC/DC50%1/2
$_ =~ /^(.*)\.pmc?$/ and -f $File::Find::name
$_ =~ /^(.*)\.pmc?$/
-f $File::Find::name
Truth table66%2/3
A and B
A= $_ =~ /^(.*)\.pmc?$/B= -f $File::Find::name
| |||||||||||||||||||||||||||||||||||||
| 136 | 32 | my $key = $1; | |||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||
| 138 | 32 | my $hashref = $self; | |||||||||||||||||||||||||||||||||||
| 139 | 32 | my @directories = File::Spec->splitdir( | |||||||||||||||||||||||||||||||||||
| 140 | substr( $File::Find::dir, length($File::Find::topdir) ) ); | ||||||||||||||||||||||||||||||||||||
| 141 | 32 | ▶ | if ( scalar(@directories) ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 142 | 16 | ▶ | shift(@directories) while ( !$directories[0] ); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 143 | 16 | foreach my $dir (@directories) { | |||||||||||||||||||||||||||||||||||
| 144 | 24 | ▶ | if ( !defined( $hashref->{$dir} ) ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 145 | 4 | $hashref->{$dir} = {}; | |||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||
| 147 | 24 | $hashref = $hashref->{$dir}; | |||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||
| 151 | 32 | my $entity; | |||||||||||||||||||||||||||||||||||
| 152 | { | ||||||||||||||||||||||||||||||||||||
| 153 | # export %properties to the entity file | ||||||||||||||||||||||||||||||||||||
| 154 | 32 | local $Config::Entities::properties = $properties; | |||||||||||||||||||||||||||||||||||
| 155 | ## no critic (ProhibitNoStrict) | ||||||||||||||||||||||||||||||||||||
| 156 | 1 | ▶ | no strict 'vars'; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 157 | 32 | ▶ | local %properties = $properties ? %$properties : (); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 158 | 32 | $entity = do($File::Find::name); | |||||||||||||||||||||||||||||||||||
| 159 | ## use critic | ||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||
| 161 | 32 | ▶ | $logger->warn( 'unable to compile ', $File::Find::name, ': ', $@, "\n" ) | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 162 | if ($@); | ||||||||||||||||||||||||||||||||||||
| 163 | 32 | _merge( $hashref, $key, $entity ); | |||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||
| 165 | }, | ||||||||||||||||||||||||||||||||||||
| 166 | 8 | map { Cwd::abs_path($_) } @entities_roots | |||||||||||||||||||||||||||||||||||
| 167 | ); | ||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||
| 170 | 13 | &$_($self) foreach $self->_inherit( undef, $self ); | |||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||
| 172 | 13 | return $self; | |||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||
| 175 | 134 | ▶ | sub _inherit { | ||||||||||||||||||||||||||||||||||
|
Subroutine
_inherit: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||
| 176 | 134 | my ( $self, $parent, $child ) = @_; | |||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||
| 178 | 134 | my @after_inherit = (); | |||||||||||||||||||||||||||||||||||
| 179 | 134 | ▶ | if ($child) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 180 | 123 | my $ref = ref($child); | |||||||||||||||||||||||||||||||||||
| 181 | 123 | ▶ | if ( $ref eq 'HASH' || $ref eq 'Config::Entities' ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$ref eq "HASH" or $ref eq "Config::Entities"
MC/DC100%2/2
$ref eq "HASH" or $ref eq "Config::Entities"
$ref eq "HASH"
$ref eq "Config::Entities"
Truth table100%3/3
A or B
A= $ref eq "HASH"B= $ref eq "Config::Entities"
| |||||||||||||||||||||||||||||||||||||
| 182 | 54 | ▶ | if ( $parent && $child->{'Config::Entities::inherit'} ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$parent and $child->{"Config::Entities::inherit"}
MC/DC100%2/2
$parent and $child->{"Config::Entities::inherit"}
$parent
$child->{"Config::Entities::inherit"}
Truth table100%3/3
A and B
A= $parentB= $child->{"Config::Entities::inherit"}
| |||||||||||||||||||||||||||||||||||||
| 183 | push( | ||||||||||||||||||||||||||||||||||||
| 184 | @after_inherit, | ||||||||||||||||||||||||||||||||||||
| 185 | $self->_inherit_each( | ||||||||||||||||||||||||||||||||||||
| 186 | 6 | delete( $child->{'Config::Entities::inherit'} ), | |||||||||||||||||||||||||||||||||||
| 187 | $parent, $child | ||||||||||||||||||||||||||||||||||||
| 188 | ) | ||||||||||||||||||||||||||||||||||||
| 189 | ); | ||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||
| 191 | 54 | push( @after_inherit, $self->_inherit( $child, $child->{$_} ) ) foreach keys(%$child); | |||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||
| 194 | 134 | return @after_inherit; | |||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||
| 197 | 6 | ▶ | sub _inherit_each { | ||||||||||||||||||||||||||||||||||
|
Subroutine
_inherit_each: called CC=7 SCAR=20.4
| |||||||||||||||||||||||||||||||||||||
| 198 | 6 | my ( $self, $inherit, $parent, $child ) = @_; | |||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||
| 200 | 6 | my @after_inherit = (); | |||||||||||||||||||||||||||||||||||
| 201 | 6 | ▶ | if ( ref($inherit) eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 202 | 6 | foreach my $spec (@$inherit) { | |||||||||||||||||||||||||||||||||||
| 203 | 8 | my $spec_ref = ref($spec); | |||||||||||||||||||||||||||||||||||
| 204 | 8 | ▶ | if ($spec_ref) { | ||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||
| 205 | 2 | ▶ | if ( $spec_ref eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 206 | 2 | push( @after_inherit, $self->_inherit_spec( $spec, $parent, $child ) ); | |||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||
| 208 | else { | ||||||||||||||||||||||||||||||||||||
| 209 | 0 | croak('invalid inherit'); | |||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||
| 212 | elsif ( defined( $parent->{$spec} ) ) { | ||||||||||||||||||||||||||||||||||||
| 213 | $child->{$spec} = $parent->{$spec} | ||||||||||||||||||||||||||||||||||||
| 214 | 6 | ▶ | unless ( defined( $child->{$spec} ) ); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||
| 218 | 6 | return @after_inherit; | |||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||
| 221 | 2 | ▶ | sub _inherit_spec { | ||||||||||||||||||||||||||||||||||
|
Subroutine
_inherit_spec: called CC=6 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||
| 222 | 2 | my ( $self, $spec, $parent, $child ) = @_; | |||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||
| 224 | 2 | ▶ | if ( $spec->{name} ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||
| 225 | 1 | ▶ | my $as = $spec->{as} || $spec->{name}; | ||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$spec->{'as'} || $spec->{'name'}
MC/DC0%0/2
$spec->{'as'} || $spec->{'name'}
$spec->{'as'}
$spec->{'name'}
Truth table33%1/3
A || B
A= $spec->{'as'}B= $spec->{'name'}
| |||||||||||||||||||||||||||||||||||||
| 226 | $child->{$as} = $parent->{ $spec->{name} } | ||||||||||||||||||||||||||||||||||||
| 227 | 1 | ▶ | unless ( defined( $child->{$as} ) ); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||
| 229 | elsif ( $spec->{coordinate} ) { | ||||||||||||||||||||||||||||||||||||
| 230 | 1 | my $as = $spec->{as}; | |||||||||||||||||||||||||||||||||||
| 231 | 1 | ▶ | unless ($as) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 232 | 0 | $as = $spec->{coordinate}; | |||||||||||||||||||||||||||||||||||
| 233 | 0 | $as =~ s/^.*\.//; | |||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||
| 236 | 1 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||
| 237 | 1 | my ($entities) = @_; | |||||||||||||||||||||||||||||||||||
| 238 | 1 | $child->{$as} = _copy( $entities->get_entity( $spec->{coordinate} ) ); | |||||||||||||||||||||||||||||||||||
| 239 | 1 | ▶ | _merge( $child, $as, $spec->{using} ) if ( $spec->{using} ); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 240 | 1 | }; | |||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||
| 242 | 1 | return; | |||||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||
| 245 | 128 | ▶ | sub _merge { | ||||||||||||||||||||||||||||||||||
|
Subroutine
_merge: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||
| 246 | 128 | my ( $hashref, $key, $value ) = @_; | |||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||
| 248 | 128 | ▶ | if ( ref($value) eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||
| 250 | # transfer key/value pairs from hashref | ||||||||||||||||||||||||||||||||||||
| 251 | # will merge rather than replace... | ||||||||||||||||||||||||||||||||||||
| 252 | 43 | ▶ | if ( !defined( $hashref->{$key} ) ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 253 | 37 | $hashref->{$key} = {}; | |||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||
| 255 | 43 | $hashref = $hashref->{$key}; | |||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||
| 257 | 43 | ▶ | while ( my ( $sub_key, $sub_value ) = each(%$value) ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 258 | 88 | _merge( $hashref, $sub_key, $sub_value ); | |||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||
| 261 | else { | ||||||||||||||||||||||||||||||||||||
| 262 | # anything not a hashref will replace | ||||||||||||||||||||||||||||||||||||
| 263 | 85 | $hashref->{$key} = $value; | |||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||
| 267 | 1 | 1; | |||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||
| 269 | __END__ | ||||||||||||||||||||||||||||||||||||