line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Module::Checkstyle::Config; |
2
|
|
|
|
|
|
|
|
3
|
9
|
|
|
9
|
|
1296437
|
use strict; |
|
9
|
|
|
|
|
26
|
|
|
9
|
|
|
|
|
364
|
|
4
|
9
|
|
|
9
|
|
54
|
use warnings; |
|
9
|
|
|
|
|
16
|
|
|
9
|
|
|
|
|
386
|
|
5
|
9
|
|
|
9
|
|
55
|
use Carp qw(croak); |
|
9
|
|
|
|
|
21
|
|
|
9
|
|
|
|
|
613
|
|
6
|
9
|
|
|
9
|
|
13151
|
use File::HomeDir; |
|
9
|
|
|
|
|
64406
|
|
|
9
|
|
|
|
|
641
|
|
7
|
|
|
|
|
|
|
|
8
|
9
|
|
|
9
|
|
78
|
use base qw(Config::Tiny); |
|
9
|
|
|
|
|
19
|
|
|
9
|
|
|
|
|
9800
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
11
|
27
|
|
|
27
|
1
|
11277
|
my ($class, $file) = @_; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# If we pass a Module::Checkstyle::Config object |
14
|
|
|
|
|
|
|
# we make that our config instead of cloning it. |
15
|
27
|
100
|
|
|
|
113
|
if (defined $file) { |
16
|
26
|
50
|
|
|
|
150
|
if (UNIVERSAL::isa($file, 'Module::Checkstyle::Config')) { |
17
|
0
|
|
|
|
|
0
|
return $file; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# Resort to user-default config |
22
|
27
|
100
|
|
|
|
107
|
if (!defined $file) { |
23
|
1
|
|
|
|
|
6
|
$file = File::Spec->catfile(home(), '.module-checkstyle', 'config'); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# Load the config or bail out |
27
|
27
|
|
|
|
|
126
|
my ($self, $name); |
28
|
27
|
100
|
66
|
|
|
255
|
if (ref $file eq 'GLOB') { |
|
|
100
|
66
|
|
|
|
|
|
|
100
|
|
|
|
|
|
29
|
2
|
|
|
|
|
46
|
my $config = join("", <$file>); |
30
|
2
|
|
|
|
|
24
|
$self = $class->SUPER::read_string($config); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
elsif(ref $file eq 'SCALAR') { |
33
|
22
|
|
|
|
|
259
|
$self = $class->SUPER::read_string($$file); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
elsif($file && -e $file && -f $file) { |
36
|
1
|
|
|
|
|
11
|
$self = $class->SUPER::read($file); |
37
|
1
|
|
|
|
|
613
|
$name = $file; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
else { |
40
|
2
|
|
|
|
|
43
|
$self = $class->SUPER::new(); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
27
|
50
|
|
|
|
1662
|
if (!defined $self) { |
44
|
0
|
|
|
|
|
0
|
croak 'Failed to load config'; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
27
|
|
|
|
|
112
|
$self->{_}->{'_config-path'} = $name; |
48
|
27
|
50
|
66
|
|
|
162
|
if (!exists $self->{_}->{'global-error-level'} || $self->{_}->{'global-error-level'} !~ /^cricial|error|info|warn$/) { |
49
|
27
|
|
|
|
|
82
|
$self->{_}->{'global-error-level'} = 'warn'; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
27
|
|
|
|
|
118
|
$self->_fix(); |
53
|
27
|
|
|
|
|
188
|
return $self; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub _fix { |
57
|
27
|
|
|
27
|
|
55
|
my $self = shift; |
58
|
|
|
|
|
|
|
|
59
|
27
|
|
|
|
|
116
|
FIX_PROPERTIES: |
60
|
27
|
|
|
|
|
49
|
foreach my $section (keys %{$self}) { |
61
|
56
|
100
|
|
|
|
207
|
next FIX_PROPERTIES if $section eq '_'; |
62
|
29
|
|
|
|
|
47
|
foreach my $property (keys %{$self->{$section}}) { |
|
29
|
|
|
|
|
101
|
|
63
|
42
|
50
|
|
|
|
347
|
if ($self->{$section}->{$property} =~ m/^ \s* (?:(critical|error|info|warn)\s+)? (.*?) $/ix) { |
64
|
42
|
|
|
|
|
151
|
$self->{_}->{_level}->{$section}->{$property} = $1; |
65
|
42
|
|
|
|
|
163
|
$self->{$section}->{$property} = $2; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub _get_check_and_property { |
72
|
151
|
|
|
151
|
|
420
|
my ($self, $check, $property) = @_; |
73
|
|
|
|
|
|
|
|
74
|
151
|
100
|
66
|
|
|
1039
|
if (defined $check && !defined $property) { |
75
|
64
|
|
|
|
|
90
|
$property = $check; |
76
|
64
|
|
|
|
|
122
|
my $caller = caller(1); |
77
|
64
|
|
|
|
|
341
|
($check) = $caller =~ m/^Module::Checkstyle::Check::(.*?)$/; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
151
|
50
|
|
|
|
712
|
if (!defined $check) { |
81
|
0
|
|
|
|
|
0
|
croak "Can't determine check"; |
82
|
|
|
|
|
|
|
} |
83
|
151
|
50
|
|
|
|
302
|
if (!defined $property) { |
84
|
0
|
|
|
|
|
0
|
croak "Can't determine property"; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
151
|
|
|
|
|
423
|
return ($self, $check, $property); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub get_enabled_sections { |
91
|
7
|
|
|
7
|
1
|
15
|
my ($self) = @_; |
92
|
7
|
|
|
|
|
29
|
my @sections = grep { $_ ne '_' } keys %$self; |
|
11
|
|
|
|
|
35
|
|
93
|
7
|
|
|
|
|
24
|
return @sections; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub get_severity { |
97
|
41
|
|
|
41
|
1
|
105
|
my ($self, $check, $property) = &_get_check_and_property; |
98
|
|
|
|
|
|
|
|
99
|
41
|
|
|
|
|
164
|
my $level = $self->{_}->{_level}->{$check}->{$property}; |
100
|
41
|
|
66
|
|
|
183
|
return $level || $self->get_directive('_', 'global-error-level'); |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub get_directive { |
104
|
110
|
|
|
110
|
1
|
262
|
my ($self, $check, $property) = &_get_check_and_property; |
105
|
110
|
|
|
|
|
636
|
return $self->{$check}->{$property}; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
1; |
109
|
|
|
|
|
|
|
__END__ |