| 1 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | package Maven::SettingsLoader; | ||||||||||||||||||||||||||||
| 5 | 5 | $Maven::SettingsLoader::VERSION = '1.12'; | |||||||||||||||||||||||||||
| 6 | # ABSTRACT: The loader for settings files | ||||||||||||||||||||||||||||
| 7 | # PODNAME: Maven::SettingsLoader | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 5 | ▶ | use Exporter qw(import); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 5 | ▶ | use File::ShareDir; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 5 | ▶ | use Log::Any; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 5 | ▶ | use Maven::Xml::Settings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 5 | our @EXPORT_OK = qw(load_settings); | |||||||||||||||||||||||||||
| 15 | 5 | my $logger = Log::Any->get_logger(); | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | sub load_settings { | ||||||||||||||||||||||||||||
| 18 | 10 | ▶ | my ( $settings_files, $properties ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
load_settings: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 10 | my $settings = | |||||||||||||||||||||||||||
| 21 | Maven::Xml::Settings->new( | ||||||||||||||||||||||||||||
| 22 | file => File::ShareDir::module_file( 'Maven::Xml::Settings', 'settings.xml' ) ); | ||||||||||||||||||||||||||||
| 23 | 10 | foreach my $file (@$settings_files) { | |||||||||||||||||||||||||||
| 24 | 20 | ▶ | if ( $file && -f $file ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$file and -f $file
MC/DC100%2/2
$file and -f $file
$file
-f $file
Truth table100%3/3
A and B
A= $fileB= -f $file
| |||||||||||||||||||||||||||||
| 25 | 16 | $settings = _merge( Maven::Xml::Settings->new( file => $file ), $settings ); | |||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 10 | _interpolate( $settings, $properties ); | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 10 | return $settings; | |||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | sub _interpolate { | ||||||||||||||||||||||||||||
| 35 | 1007 | ▶ | my ( $value, $properties ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_interpolate: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 1007 | my $ref = ref($value); | |||||||||||||||||||||||||||
| 38 | 1007 | ▶ | if ($ref) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 39 | 263 | ▶ | if ( $ref eq 'ARRAY' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | 67 | ▶ | for ( my $i = 0; $i < scalar(@$value); $i++ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | 118 | $value->[$i] = _interpolate( $value->[$i], $properties ); | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | else { | ||||||||||||||||||||||||||||
| 45 | 196 | foreach my $key ( keys(%$value) ) { | |||||||||||||||||||||||||||
| 46 | 879 | $value->{$key} = _interpolate( $value->{$key}, $properties ); | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | elsif ($value) { | ||||||||||||||||||||||||||||
| 51 | 200 | $logger->tracef( 'interpolating \'%s\'', $value ); | |||||||||||||||||||||||||||
| 52 | 200 | $value =~ s/\$\{(.*?)\}/$properties->{$1}/g; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 1007 | return $value; | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | sub _merge { | ||||||||||||||||||||||||||||
| 59 | 16 | ▶ | my ( $dominant, $recessive ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_merge: called CC=17 SCAR=28.5
| |||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 16 | ▶ | if ( !$dominant->get_localRepository() ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | 11 | $dominant->set_localRepository( $recessive->get_localRepository() ); | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | 16 | ▶ | if ( !$dominant->get_interactiveMode() ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | 16 | $dominant->set_interactiveMode( $recessive->get_interactiveMode() ); | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | 16 | ▶ | if ( !$dominant->get_usePluginRegistry() ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | 16 | $dominant->set_usePluginRegistry( $recessive->get_usePluginRegistry() ); | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | 16 | ▶ | if ( !$dominant->get_offline() ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | 16 | $dominant->set_offline( $recessive->get_offline() ); | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 16 | ▶ | if ( $dominant->get_mirrors() ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | 12 | _shallow_merge_by_ids( $dominant->get_mirrors(), $recessive->get_mirrors() ); | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | else { | ||||||||||||||||||||||||||||
| 78 | 4 | $dominant->set_mirrors( $recessive->get_mirrors() ); | |||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 16 | ▶ | if ( $dominant->get_servers() ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | 12 | _shallow_merge_by_ids( $dominant->get_servers(), $recessive->get_servers() ); | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | else { | ||||||||||||||||||||||||||||
| 85 | 4 | $dominant->set_servers( $recessive->get_servers() ); | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 16 | ▶ | if ( $dominant->get_proxies() ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | 12 | _shallow_merge_by_ids( $dominant->get_proxies(), $recessive->get_proxies() ); | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | else { | ||||||||||||||||||||||||||||
| 92 | 4 | $dominant->set_proxies( $recessive->get_proxies() ); | |||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 16 | ▶ | if ( $dominant->get_profiles() ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | 14 | _shallow_merge_by_ids( $dominant->get_profiles(), $recessive->get_profiles() ); | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | else { | ||||||||||||||||||||||||||||
| 99 | 2 | $dominant->set_profiles( $recessive->get_profiles() ); | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 16 | ▶ | if ( $recessive->get_activeProfiles() ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | 5 | my $dominant_active_profiles = $dominant->get_activeProfiles(); | |||||||||||||||||||||||||||
| 104 | 5 | ▶ | if ( $dominant_active_profiles && scalar(@$dominant_active_profiles) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$dominant_active_profiles and scalar @$dominant_active_profiles
MC/DC0%0/1
$dominant_active_profiles and scalar @$dominant_active_profiles
$dominant_active_profiles
Truth table50%1/2
A
A= $dominant_active_profiles
| |||||||||||||||||||||||||||||
| 105 | 5 | my %dominant = map { $_ => 1 } @$dominant_active_profiles; | |||||||||||||||||||||||||||
| 106 | 5 | foreach my $recessive_active_profile ( @{ $recessive->get_activeProfiles() } ) { | |||||||||||||||||||||||||||
| 107 | 5 | push( @$dominant_active_profiles, $recessive_active_profile ); | |||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | else { | ||||||||||||||||||||||||||||
| 111 | 0 | $dominant->set_activeProfiles( $recessive->get_activeProfiles() ); | |||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 16 | ▶ | if ( $recessive->get_pluginGroups() ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | 16 | my $dominant_plugin_groups = $dominant->get_pluginGroups(); | |||||||||||||||||||||||||||
| 117 | 16 | ▶ | if ( $dominant_plugin_groups && scalar(@$dominant_plugin_groups) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$dominant_plugin_groups and scalar @$dominant_plugin_groups
MC/DC100%1/1
$dominant_plugin_groups and scalar @$dominant_plugin_groups
$dominant_plugin_groups
Truth table100%2/2
A
A= $dominant_plugin_groups
| |||||||||||||||||||||||||||||
| 118 | 12 | my %dominant = map { $_ => 1 } @$dominant_plugin_groups; | |||||||||||||||||||||||||||
| 119 | 12 | foreach my $recessive_plugin_groups ( @{ $recessive->get_pluginGroups() } ) { | |||||||||||||||||||||||||||
| 120 | 30 | push( @$dominant_plugin_groups, $recessive_plugin_groups ); | |||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | else { | ||||||||||||||||||||||||||||
| 124 | 4 | $dominant->set_pluginGroups( $recessive->get_pluginGroups() ); | |||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 16 | return $dominant; | |||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | sub _shallow_merge_by_ids { | ||||||||||||||||||||||||||||
| 132 | 50 | ▶ | my ( $dominant, $recessive ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_shallow_merge_by_ids: called CC=6 SCAR=18.2
| |||||||||||||||||||||||||||||
| 133 | 50 | ▶ | return if ( !$recessive || !scalar(@$recessive) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$recessive and scalar @$recessive
MC/DC50%1/2
$recessive and scalar @$recessive
$recessive
scalar @$recessive
Truth table66%2/3
A and B
A= $recessiveB= scalar @$recessive
| |||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | 24 | my %dominant_by_id = map { $_->get_id() => $_ } @$dominant; | |||||||||||||||||||||||||||
| 136 | 24 | foreach my $recessive_entry (@$recessive) { | |||||||||||||||||||||||||||
| 137 | 24 | ▶ | next unless $recessive_entry; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 138 | 24 | ▶ | if ( !$dominant_by_id{ $recessive_entry->get_id() } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 139 | 24 | push( @$dominant, $recessive_entry ); | |||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | 5 | 1; | |||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | __END__ | ||||||||||||||||||||||||||||