SettingsLoader.pm

filter: Statementstmt 98.8% 87 / 88 Branchbran 82.5% 33 / 40 Conditioncond 80.0% 8 / 10 MC/DCmcdc 66.6% 4 / 6 Subroutinesub 100% 10 / 10 Podpod 100% 1 / 1 totaltotal 92.2% 143 / 155 CC 30 SCAR 23.0
CC
30
Cov
93%
_merge
17.3
_shallow_merge_by_ids
6.2
_interpolate
6.0
CRAP 10.0
« Xml/Pom.pm ↑ Summary Repository.pm »
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
BranchTrueFalseTotal
if ($file and -f $file) 16 4 20
Condition100%3/3
$file and -f $file
!ll&&!rl&&r
2216
MC/DC100%2/2
$file and -f $file
$file -f $file
Truth table100%3/3
A and B
A= $fileB= -f $file
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if ($ref) { } 263 744 1007
elsif ($value) { } 200 544 744
39 263 ▶ if ( $ref eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ref eq 'ARRAY') { } 67 196 263
40 67 ▶ for ( my $i = 0; $i < scalar(@$value); $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @$value) 118 67 185
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
BranchTrueFalseTotal
unless ($dominant->get_localRepository) 11 5 16
62 11 $dominant->set_localRepository( $recessive->get_localRepository() );
63 }
64 16 ▶ if ( !$dominant->get_interactiveMode() ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dominant->get_interactiveMode) 16 0 16
65 16 $dominant->set_interactiveMode( $recessive->get_interactiveMode() );
66 }
67 16 ▶ if ( !$dominant->get_usePluginRegistry() ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dominant->get_usePluginRegistry) 16 0 16
68 16 $dominant->set_usePluginRegistry( $recessive->get_usePluginRegistry() );
69 }
70 16 ▶ if ( !$dominant->get_offline() ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dominant->get_offline) 16 0 16
71 16 $dominant->set_offline( $recessive->get_offline() );
72 }
73  
74 16 ▶ if ( $dominant->get_mirrors() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dominant->get_mirrors) { } 12 4 16
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
BranchTrueFalseTotal
if ($dominant->get_servers) { } 12 4 16
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
BranchTrueFalseTotal
if ($dominant->get_proxies) { } 12 4 16
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
BranchTrueFalseTotal
if ($dominant->get_profiles) { } 14 2 16
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
BranchTrueFalseTotal
if ($recessive->get_activeProfiles) 5 11 16
103 5 my $dominant_active_profiles = $dominant->get_activeProfiles();
104 5 ▶ if ( $dominant_active_profiles && scalar(@$dominant_active_profiles) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dominant_active_profiles and scalar @$dominant_active_profiles) { } 5 0 5
Condition50%1/2
$dominant_active_profiles and scalar @$dominant_active_profiles
!ll
05
MC/DC0%0/1
$dominant_active_profiles and scalar @$dominant_active_profiles
$dominant_active_profiles
Truth table50%1/2
A
A= $dominant_active_profiles
Aresult
00
11
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
BranchTrueFalseTotal
if ($recessive->get_pluginGroups) 16 0 16
116 16 my $dominant_plugin_groups = $dominant->get_pluginGroups();
117 16 ▶ if ( $dominant_plugin_groups && scalar(@$dominant_plugin_groups) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dominant_plugin_groups and scalar @$dominant_plugin_groups) { } 12 4 16
Condition100%2/2
$dominant_plugin_groups and scalar @$dominant_plugin_groups
!ll
412
MC/DC100%1/1
$dominant_plugin_groups and scalar @$dominant_plugin_groups
$dominant_plugin_groups
Truth table100%2/2
A
A= $dominant_plugin_groups
Aresult
00
11
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
BranchTrueFalseTotal
unless $recessive and scalar @$recessive 26 24 50
Condition66%2/3
$recessive and scalar @$recessive
!ll&&!rl&&r
26024
MC/DC50%1/2
$recessive and scalar @$recessive
$recessive scalar @$recessive
Truth table66%2/3
A and B
A= $recessiveB= scalar @$recessive
ABresult
0X0
100
111
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
BranchTrueFalseTotal
unless $recessive_entry 0 24 24
138 24 ▶ if ( !$dominant_by_id{ $recessive_entry->get_id() } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dominant_by_id{$recessive_entry->get_id}) 24 0 24
139 24 push( @$dominant, $recessive_entry );
140 }
141 }
142 }
143  
144 5 1;
145  
146 __END__
« Xml/Pom.pm ↑ Summary Repository.pm »