line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# PODNAME: Textoola::PatternStatParser |
2
|
|
|
|
|
|
|
# ABSTRACT: Class to parse text into pattern-tokenline and creating at counting-hash of pattern-tokenline. |
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
23518
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
24
|
|
5
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
20
|
|
6
|
1
|
|
|
1
|
|
6
|
use v5.14; |
|
1
|
|
|
|
|
2
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
package Textoola::PatternStatParser; |
9
|
|
|
|
|
|
|
$Textoola::PatternStatParser::VERSION = '0.003'; |
10
|
|
|
|
|
|
|
sub new { |
11
|
2
|
|
|
2
|
0
|
1254
|
my $class = shift; |
12
|
2
|
|
|
|
|
5
|
my %args = @_; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my $self={ |
15
|
|
|
|
|
|
|
separator => '\s', |
16
|
|
|
|
|
|
|
separator_subst => ' ', |
17
|
|
|
|
|
|
|
path => $args{path}, |
18
|
2
|
|
|
|
|
9
|
patternstats => {}, |
19
|
|
|
|
|
|
|
}; |
20
|
|
|
|
|
|
|
|
21
|
2
|
|
|
|
|
3
|
bless $self, $class; |
22
|
2
|
|
|
|
|
5
|
return $self; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub parse_line { |
26
|
3
|
|
|
3
|
0
|
7
|
my $self = shift; |
27
|
3
|
|
|
|
|
3
|
my $line = shift; |
28
|
|
|
|
|
|
|
|
29
|
3
|
|
|
|
|
4
|
chomp $line; |
30
|
3
|
|
|
|
|
8
|
my $sep = $self->{separator}; |
31
|
3
|
|
|
|
|
4
|
my $sepsub = $self->{separator_subst}; |
32
|
3
|
|
|
|
|
3
|
my $patstats = $self->{patternstats}; |
33
|
3
|
|
|
|
|
19
|
my @tokens = split /$sep/,$line; |
34
|
|
|
|
|
|
|
|
35
|
3
|
|
|
|
|
9
|
my $pattern; |
36
|
3
|
50
|
|
|
|
7
|
if (scalar(@tokens)) { |
37
|
3
|
|
33
|
|
|
11
|
$pattern //= shift @tokens; |
38
|
3
|
|
|
|
|
4
|
$patstats->{$pattern}++; |
39
|
|
|
|
|
|
|
|
40
|
3
|
|
|
|
|
7
|
while (scalar(@tokens)) { |
41
|
6
|
|
|
|
|
8
|
$pattern .= $sepsub.shift @tokens; |
42
|
6
|
|
|
|
|
18
|
$patstats->{$pattern}++; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub parse { |
48
|
1
|
|
|
1
|
0
|
6
|
my $self = shift; |
49
|
1
|
|
|
|
|
2
|
my $path = $self->{path}; |
50
|
|
|
|
|
|
|
|
51
|
1
|
|
|
|
|
2
|
my $fh; |
52
|
1
|
50
|
|
|
|
5
|
if (defined $path) { |
53
|
1
|
50
|
|
1
|
|
6
|
open($fh,"<",$path) or die "File $path not found"; |
|
1
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
34
|
|
54
|
|
|
|
|
|
|
} else { |
55
|
0
|
|
|
|
|
0
|
$fh=*STDIN; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
1
|
|
|
|
|
779
|
while(my $line=<$fh>) { |
59
|
1
|
|
|
|
|
3
|
$self->parse_line($line); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
1
|
|
|
|
|
4
|
close $fh; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub patternstats { |
66
|
4
|
|
|
4
|
0
|
10
|
my $self = shift; |
67
|
4
|
|
|
|
|
23
|
return $self->{patternstats}; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
1; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
__END__ |