line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package School::Code::Compare::Charset; |
2
|
|
|
|
|
|
|
# ABSTRACT: trim whitespace, comments and unessential chars |
3
|
|
|
|
|
|
|
$School::Code::Compare::Charset::VERSION = '0.102'; # TRIAL |
4
|
4
|
|
|
4
|
|
386865
|
use strict; |
|
4
|
|
|
|
|
34
|
|
|
4
|
|
|
|
|
116
|
|
5
|
4
|
|
|
4
|
|
21
|
use warnings; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
115
|
|
6
|
|
|
|
|
|
|
|
7
|
4
|
|
|
4
|
|
1546
|
use School::Code::Compare::Charset::NoComments; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
116
|
|
8
|
4
|
|
|
4
|
|
1586
|
use School::Code::Compare::Charset::NoWhitespace; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
107
|
|
9
|
4
|
|
|
4
|
|
1585
|
use School::Code::Compare::Charset::NumSignes; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
101
|
|
10
|
4
|
|
|
4
|
|
1480
|
use School::Code::Compare::Charset::Signes; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
1654
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
14
|
|
|
14
|
0
|
8117
|
my $class = shift; |
14
|
|
|
|
|
|
|
|
15
|
14
|
|
|
|
|
39
|
my $self = { |
16
|
|
|
|
|
|
|
language => 'txt', |
17
|
|
|
|
|
|
|
}; |
18
|
14
|
|
|
|
|
27
|
bless $self, $class; |
19
|
|
|
|
|
|
|
|
20
|
14
|
|
|
|
|
49
|
return $self; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub set_language { |
24
|
14
|
|
|
14
|
0
|
86
|
my $self = shift; |
25
|
|
|
|
|
|
|
|
26
|
14
|
|
|
|
|
39
|
$self->{language} = shift; |
27
|
|
|
|
|
|
|
|
28
|
14
|
|
|
|
|
41
|
return $self; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub sort_by_lines { |
32
|
9
|
|
|
9
|
0
|
43
|
my $self = shift; |
33
|
9
|
|
|
|
|
17
|
my $lines_ref = shift; |
34
|
|
|
|
|
|
|
|
35
|
9
|
|
|
|
|
13
|
my @sorted = sort { $a cmp $b } @{$lines_ref}; |
|
281
|
|
|
|
|
334
|
|
|
9
|
|
|
|
|
38
|
|
36
|
|
|
|
|
|
|
|
37
|
9
|
|
|
|
|
26
|
return \@sorted; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub trim_comments { |
41
|
20
|
|
|
20
|
0
|
33
|
my $self = shift; |
42
|
20
|
|
|
|
|
26
|
my $lines_ref = shift; |
43
|
|
|
|
|
|
|
|
44
|
20
|
|
|
|
|
75
|
my $clean = School::Code::Compare::Charset::NoComments->new(); |
45
|
20
|
|
|
|
|
30
|
my $cleaned = ''; |
46
|
20
|
|
|
|
|
158
|
my $lang = $self->{language}; |
47
|
|
|
|
|
|
|
|
48
|
20
|
100
|
33
|
|
|
250
|
if ($lang eq 'python' |
|
|
100
|
33
|
|
|
|
|
|
|
50
|
66
|
|
|
|
|
|
|
50
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
33
|
|
|
|
|
49
|
|
|
|
|
|
|
or $lang eq 'perl' |
50
|
|
|
|
|
|
|
or $lang eq 'bash' |
51
|
|
|
|
|
|
|
or $lang eq 'hashy' |
52
|
|
|
|
|
|
|
) { |
53
|
11
|
|
|
|
|
26
|
$cleaned = $clean->hashy ( $lines_ref ); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
elsif ($lang eq 'php' |
56
|
|
|
|
|
|
|
or $lang eq 'js' |
57
|
|
|
|
|
|
|
or $lang eq 'cpp' |
58
|
|
|
|
|
|
|
or $lang eq 'cs' |
59
|
|
|
|
|
|
|
or $lang eq 'c' |
60
|
|
|
|
|
|
|
or $lang eq 'java' |
61
|
|
|
|
|
|
|
or $lang eq 'slashy' |
62
|
|
|
|
|
|
|
) { |
63
|
6
|
|
|
|
|
17
|
$cleaned = $clean->slashy ( $lines_ref ); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
elsif ($lang eq 'html' |
66
|
|
|
|
|
|
|
or $lang eq 'xml' |
67
|
|
|
|
|
|
|
) { |
68
|
0
|
|
|
|
|
0
|
$cleaned = $clean->html ( $lines_ref ); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
elsif ($lang eq 'txt') { |
71
|
3
|
|
|
|
|
6
|
$cleaned = $lines_ref; # do nothing |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
20
|
|
|
|
|
66
|
return $cleaned; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub get_visibles { |
78
|
11
|
|
|
11
|
0
|
247
|
my $self = shift; |
79
|
11
|
|
|
|
|
16
|
my $lines_ref = shift; |
80
|
|
|
|
|
|
|
|
81
|
11
|
|
|
|
|
27
|
my $cleaned = $self->trim_comments($lines_ref); |
82
|
|
|
|
|
|
|
|
83
|
11
|
|
|
|
|
66
|
return School::Code::Compare::Charset::NoWhitespace->new() |
84
|
|
|
|
|
|
|
->filter($cleaned); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub get_numsignes { |
88
|
1
|
|
|
1
|
0
|
901
|
my $self = shift; |
89
|
1
|
|
|
|
|
2
|
my $lines_ref = shift; |
90
|
|
|
|
|
|
|
|
91
|
1
|
|
|
|
|
3
|
my $no_comments = $self->trim_comments($lines_ref); |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
# order is important: |
94
|
|
|
|
|
|
|
# first create numsigns, then remove whitespace. |
95
|
|
|
|
|
|
|
# otherwise "words" will loose their meaning. |
96
|
|
|
|
|
|
|
|
97
|
1
|
|
|
|
|
9
|
my $ns = School::Code::Compare::Charset::NumSignes->new() |
98
|
|
|
|
|
|
|
->filter($no_comments); |
99
|
|
|
|
|
|
|
|
100
|
1
|
|
|
|
|
7
|
return School::Code::Compare::Charset::NoWhitespace->new() |
101
|
|
|
|
|
|
|
->filter($ns); |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub get_signes { |
105
|
8
|
|
|
8
|
0
|
29746
|
my $self = shift; |
106
|
8
|
|
|
|
|
12
|
my $lines_ref = shift; |
107
|
|
|
|
|
|
|
|
108
|
8
|
|
|
|
|
19
|
my $no_comments = $self->trim_comments($lines_ref); |
109
|
|
|
|
|
|
|
|
110
|
8
|
|
|
|
|
45
|
my $ns = School::Code::Compare::Charset::Signes->new() |
111
|
|
|
|
|
|
|
->filter($no_comments); |
112
|
|
|
|
|
|
|
|
113
|
8
|
|
|
|
|
37
|
return School::Code::Compare::Charset::NoWhitespace->new() |
114
|
|
|
|
|
|
|
->filter($ns); |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
1; |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
__END__ |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=pod |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=encoding UTF-8 |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head1 NAME |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
School::Code::Compare::Charset - trim whitespace, comments and unessential chars |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head1 VERSION |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
version 0.102 |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 AUTHOR |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Boris Däppen <bdaeppen.perl@gmail.com> |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
This software is copyright (c) 2020 by Boris Däppen. |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
142
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=cut |