line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Module::Checkstyle::Util; |
2
|
|
|
|
|
|
|
|
3
|
8
|
|
|
8
|
|
29155
|
use strict; |
|
8
|
|
|
|
|
15
|
|
|
8
|
|
|
|
|
281
|
|
4
|
8
|
|
|
8
|
|
45
|
use warnings; |
|
8
|
|
|
|
|
17
|
|
|
8
|
|
|
|
|
260
|
|
5
|
|
|
|
|
|
|
|
6
|
8
|
|
|
8
|
|
42
|
use Carp qw(croak); |
|
8
|
|
|
|
|
13
|
|
|
8
|
|
|
|
|
488
|
|
7
|
|
|
|
|
|
|
|
8
|
8
|
|
|
8
|
|
4923
|
use Module::Checkstyle::Problem; |
|
8
|
|
|
|
|
23
|
|
|
8
|
|
|
|
|
9555
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
require Exporter; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our @EXPORT = qw(); |
15
|
|
|
|
|
|
|
our @EXPORT_OK = qw(format_expected_err new_problem as_true as_numeric as_regexp is_valid_position is_valid_align); |
16
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( all => [@EXPORT_OK], |
17
|
|
|
|
|
|
|
problem => [qw(format_expected_err new_problem)], |
18
|
|
|
|
|
|
|
args => [qw(as_true as_numeric as_regexp is_valid_position is_valid_align)], |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub format_expected_err { |
22
|
4
|
|
|
4
|
1
|
17
|
my ($expected, $got) = @_; |
23
|
|
|
|
|
|
|
|
24
|
4
|
|
66
|
|
|
24
|
$expected = ref $expected || $expected; |
25
|
4
|
|
100
|
|
|
20
|
$got = ref $got || $got; |
26
|
|
|
|
|
|
|
|
27
|
4
|
100
|
|
|
|
15
|
$expected = q{} if !defined $expected; |
28
|
4
|
50
|
|
|
|
13
|
$got = q{} if !defined $got; |
29
|
|
|
|
|
|
|
|
30
|
4
|
|
|
|
|
232
|
return qq(Expected '$expected' but got '$got'); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub new_problem { |
34
|
42
|
|
|
42
|
1
|
175
|
my $problem; |
35
|
|
|
|
|
|
|
|
36
|
42
|
100
|
|
|
|
171
|
if (@_ == 4) { |
|
|
50
|
|
|
|
|
|
37
|
1
|
|
|
|
|
9
|
$problem = Module::Checkstyle::Problem->new(@_); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
elsif (@_ == 5) { |
40
|
41
|
|
|
|
|
137
|
my ($config, $directive, $message, $line, $file) = @_; |
41
|
41
|
|
|
|
|
197
|
my $severity; |
42
|
|
|
|
|
|
|
|
43
|
41
|
|
|
|
|
242
|
my ($caller) = caller =~ /^Module::Checkstyle::Check::(.*)$/; |
44
|
41
|
50
|
|
|
|
121
|
if ($caller) { |
45
|
41
|
|
|
|
|
199
|
$severity = $config->get_severity($caller, $directive); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
else { |
48
|
0
|
|
|
|
|
0
|
$severity = $config->get_severity('_', 'global-error-level'); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
41
|
|
|
|
|
225
|
$problem = Module::Checkstyle::Problem->new($severity, $message, $line, $file); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
else { |
54
|
0
|
|
|
|
|
0
|
croak "Module::Checkstyle::Util::new_problem() called with wrong number of arguments"; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
42
|
|
|
|
|
132
|
return $problem; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub as_true { |
61
|
47
|
|
|
47
|
1
|
74
|
my $value = shift; |
62
|
47
|
100
|
66
|
|
|
274
|
return 0 if !defined $value || !$value; |
63
|
18
|
100
|
|
|
|
153
|
return 1 if $value =~ m/^ y | yes | true | 1 $/xi; |
64
|
2
|
|
|
|
|
8
|
return 0; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub as_numeric { |
68
|
11
|
|
|
11
|
1
|
21
|
my $value = shift; |
69
|
|
|
|
|
|
|
|
70
|
11
|
100
|
66
|
|
|
75
|
return 0 if !defined $value || !$value; |
71
|
5
|
100
|
|
|
|
43
|
return $value if $value =~ /^\-?\d+$/; |
72
|
1
|
|
|
|
|
7
|
return 0; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub as_regexp { |
76
|
15
|
|
|
15
|
1
|
31
|
my $value = shift; |
77
|
15
|
100
|
|
|
|
71
|
return undef if !defined $value; |
78
|
7
|
100
|
|
|
|
40
|
return undef if $value =~ /^\s*$/; |
79
|
|
|
|
|
|
|
|
80
|
6
|
100
|
|
|
|
28
|
if ($value !~ /^qr/) { |
81
|
5
|
|
|
|
|
13
|
$value = 'qr' . $value; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
6
|
|
|
|
|
714
|
my $re = eval $value; |
85
|
6
|
50
|
|
|
|
44
|
return undef if $@; |
86
|
6
|
|
|
|
|
48
|
return $re; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub is_valid_position { |
90
|
6
|
|
50
|
6
|
1
|
59
|
my $value = shift || ""; |
91
|
6
|
100
|
|
|
|
74
|
return $value =~ /^same|alone$/i ? 1 : 0; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub is_valid_align { |
96
|
5
|
|
50
|
5
|
1
|
18
|
my $value = shift || ""; |
97
|
5
|
100
|
|
|
|
38
|
return $value =~ /^left|middle|right$/i ? 1 : 0 |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
1; |
101
|
|
|
|
|
|
|
__END__ |