line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::mycnfdiff::Utils; |
2
|
|
|
|
|
|
|
$App::mycnfdiff::Utils::VERSION = '1.00'; |
3
|
1
|
|
|
1
|
|
59731
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
23
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
24
|
|
5
|
1
|
|
|
1
|
|
4
|
use feature 'say'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
114
|
|
6
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
57
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
686
|
use List::Compare; |
|
1
|
|
|
|
|
16278
|
|
|
1
|
|
|
|
|
42
|
|
9
|
1
|
|
|
1
|
|
7
|
use List::Util qw(uniq); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
84
|
|
10
|
1
|
|
|
1
|
|
397
|
use Config::MySQL::Reader; |
|
1
|
|
|
|
|
39360
|
|
|
1
|
|
|
|
|
36
|
|
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
375
|
use Data::Dump qw(dd); |
|
1
|
|
|
|
|
3536
|
|
|
1
|
|
|
|
|
61
|
|
13
|
1
|
|
|
1
|
|
7
|
use Data::Dumper; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
36
|
|
14
|
|
|
|
|
|
|
|
15
|
1
|
|
|
1
|
|
368
|
use Const::Fast; |
|
1
|
|
|
|
|
1711
|
|
|
1
|
|
|
|
|
5
|
|
16
|
|
|
|
|
|
|
const my $ALLOWED_EXTENSIONS_REGEX => qr/\.ini|cnf$/; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
require Exporter; |
19
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
20
|
|
|
|
|
|
|
our @EXPORT_OK = qw( |
21
|
|
|
|
|
|
|
get_folder |
22
|
|
|
|
|
|
|
get_configs |
23
|
|
|
|
|
|
|
compare |
24
|
|
|
|
|
|
|
split_compare_hash |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [@EXPORT_OK] ); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
#Process skip files, filter extensions and return pwd-ed path |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub get_folder { |
31
|
0
|
|
|
0
|
0
|
|
my (%opts) = @_; |
32
|
|
|
|
|
|
|
|
33
|
0
|
0
|
|
|
|
|
say "Inspecting modules in " . $opts{'dir'} if $opts{'v'}; |
34
|
0
|
|
|
|
|
|
say "Skip files : " . join( ',', @{ $opts{'skip'} } ) |
35
|
0
|
0
|
0
|
|
|
|
if ( $opts{'v'} && @{ $opts{'skip'} } ); |
|
0
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
my @files; |
38
|
0
|
0
|
|
|
|
|
opendir( my $dh, $opts{'dir'} ) or die $!; |
39
|
0
|
|
|
|
|
|
while ( my $file = readdir($dh) ) { |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# warn $file; |
42
|
0
|
0
|
|
|
|
|
next unless ( -f $opts{'dir'} . '/' . $file ); |
43
|
0
|
0
|
|
|
|
|
next unless ( $file =~ m/$ALLOWED_EXTENSIONS_REGEX/ ); |
44
|
0
|
|
|
|
|
|
push @files, $opts{'dir'} . '/' . $file; |
45
|
|
|
|
|
|
|
} |
46
|
0
|
|
|
|
|
|
closedir($dh); |
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
my $lc = List::Compare->new( \@files, $opts{'skip'} ); |
49
|
0
|
|
|
|
|
|
return $lc->get_Lonly; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub get_configs { |
54
|
0
|
|
|
0
|
0
|
|
my (%opts) = @_; |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
my $result = {}; |
57
|
|
|
|
|
|
|
|
58
|
0
|
0
|
|
|
|
|
if ( @{ $opts{'include_only'} } ) { |
|
0
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
for my $filename ( @{ $opts{'include_only'} } ) { |
|
0
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# to-do: resolve compiled defaults exec: tag |
62
|
|
|
|
|
|
|
# _detect_compiled_defaults_format |
63
|
0
|
|
|
|
|
|
$result->{$filename} = Config::MySQL::Reader->read_file($filename); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
else { |
67
|
0
|
|
|
|
|
|
my @files = get_folder(%opts); |
68
|
0
|
|
|
|
|
|
$result->{$_} = Config::MySQL::Reader->read_file($_) for (@files); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
warn Dumper $result; |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
return $result; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
# Return value if all hash values are same and |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub _try_group_hash { |
79
|
0
|
|
|
0
|
|
|
my %x = @_; |
80
|
0
|
|
|
|
|
|
my @values = uniq values %x; |
81
|
0
|
0
|
|
|
|
|
return $values[0] if ( scalar @values == 1 ); |
82
|
0
|
|
|
|
|
|
my $result; |
83
|
0
|
|
|
|
|
|
while ( my ( $key, $value ) = each(%x) ) { |
84
|
0
|
|
|
|
|
|
$result->{$key} = $value; |
85
|
|
|
|
|
|
|
} |
86
|
0
|
|
|
|
|
|
return $result; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub compare { |
90
|
0
|
|
|
0
|
0
|
|
my ($h) = @_; |
91
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
my @filenames = keys %$h; |
93
|
0
|
|
|
|
|
|
my @all_possible_ini_groups = uniq map { keys %$_ } values %$h; |
|
0
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
my $result; |
96
|
0
|
|
|
|
|
|
for my $group_name (@all_possible_ini_groups) { |
97
|
|
|
|
|
|
|
$result->{$group_name} = |
98
|
0
|
|
|
|
|
|
[ uniq map { keys %{ $h->{$_}{$group_name} } } @filenames ]; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
99
|
0
|
|
|
|
|
|
my $temp = {}; |
100
|
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
for my $param ( @{ $result->{$group_name} } ) { |
|
0
|
|
|
|
|
|
|
102
|
0
|
|
|
|
|
|
my %values = map { $_ => $h->{$_}{$group_name}{$param} } @filenames; |
|
0
|
|
|
|
|
|
|
103
|
0
|
|
|
|
|
|
$temp->{$param} = _try_group_hash(%values); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
0
|
|
|
|
|
|
$result->{$group_name} = $temp; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
0
|
|
|
|
|
|
return $result; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
# if group_key->param_key->val = scalar push to same key, otherwise to diff |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub split_compare_hash { |
115
|
0
|
|
|
0
|
0
|
|
my ($hash) = @_; |
116
|
|
|
|
|
|
|
|
117
|
0
|
|
|
|
|
|
my $res = { |
118
|
|
|
|
|
|
|
same => {}, |
119
|
|
|
|
|
|
|
diff => {} |
120
|
|
|
|
|
|
|
}; |
121
|
|
|
|
|
|
|
|
122
|
0
|
|
|
|
|
|
while ( my ( $group_name, $group_params ) = each(%$hash) ) { |
123
|
|
|
|
|
|
|
|
124
|
0
|
|
|
|
|
|
my ( $group_same, $group_diff ) = {}; |
125
|
0
|
|
|
|
|
|
while ( my ( $param, $val ) = each(%$group_params) ) { |
126
|
|
|
|
|
|
|
|
127
|
0
|
0
|
|
|
|
|
if ( ref $val eq '' ) { |
128
|
0
|
|
|
|
|
|
$group_same->{$param} = $val; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
else { |
131
|
0
|
|
|
|
|
|
$group_diff->{$param} = $val; |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
0
|
0
|
|
|
|
|
$res->{same}{$group_name} = $group_same if (%$group_same); |
136
|
0
|
0
|
|
|
|
|
$res->{diff}{$group_name} = $group_diff if (%$group_diff); |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
} |
139
|
0
|
|
|
|
|
|
return $res; |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
1; |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
__END__ |