line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mail::Karmasphere::Parser::Base; |
2
|
|
|
|
|
|
|
|
3
|
8
|
|
|
8
|
|
50
|
use strict; |
|
8
|
|
|
|
|
13
|
|
|
8
|
|
|
|
|
269
|
|
4
|
8
|
|
|
8
|
|
39
|
use warnings; |
|
8
|
|
|
|
|
16
|
|
|
8
|
|
|
|
|
252
|
|
5
|
8
|
|
|
8
|
|
8868
|
use Data::Dumper; |
|
8
|
|
|
|
|
47744
|
|
|
8
|
|
|
|
|
590
|
|
6
|
8
|
|
|
8
|
|
5119
|
use Mail::Karmasphere::Parser::Record; |
|
8
|
|
|
|
|
23
|
|
|
8
|
|
|
|
|
278
|
|
7
|
8
|
|
|
8
|
|
49
|
use Carp qw(confess); |
|
8
|
|
|
|
|
16
|
|
|
8
|
|
|
|
|
8826
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub new { |
10
|
7
|
|
|
7
|
0
|
85
|
my $class = shift; |
11
|
7
|
50
|
|
|
|
28
|
my $self = ($#_ == 0) ? { %{ (shift) } } : { @_ }; |
|
7
|
|
|
|
|
32
|
|
12
|
7
|
50
|
|
|
|
126
|
die "No input mechanism (fh)" unless exists $self->{fh}; |
13
|
7
|
50
|
|
|
|
32
|
die "No stream metadata (Streams)" unless exists $self->{Streams}; |
14
|
7
|
|
|
|
|
97
|
return bless $self, $class; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub warning { |
18
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
19
|
0
|
0
|
|
|
|
0
|
if (++$self->{Warnings} < 10) { |
20
|
0
|
|
|
|
|
0
|
warn @_; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub error { |
25
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
26
|
0
|
|
|
|
|
0
|
++$self->{Errors}; |
27
|
0
|
|
|
|
|
0
|
die @_; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub fh { |
31
|
135
|
|
|
135
|
0
|
3313
|
return $_[0]->{fh}; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub _parse { |
35
|
0
|
|
|
0
|
|
0
|
die "Subclass must implement _parse routine"; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub streams { |
39
|
0
|
|
|
0
|
0
|
0
|
return $_[0]->{Streams}; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub parse { |
43
|
63
|
|
|
63
|
0
|
1291
|
my $self = shift; |
44
|
63
|
50
|
|
|
|
226
|
return if $self->{Done}; |
45
|
|
|
|
|
|
|
RECORDS: |
46
|
63
|
|
|
|
|
58
|
for (;;) { |
47
|
|
|
|
|
|
|
# print STDERR "> > parsing...\n"; |
48
|
63
|
|
|
|
|
191
|
my @records = $self->_parse; |
49
|
63
|
|
|
|
|
79
|
my @toreturn; |
50
|
|
|
|
|
|
|
RECORD: |
51
|
63
|
|
|
|
|
93
|
for my $record (@records) { |
52
|
|
|
|
|
|
|
# print STDERR " > record: $record\n"; |
53
|
61
|
100
|
|
|
|
127
|
last RECORD unless defined $record; |
54
|
57
|
50
|
|
|
|
165
|
print Dumper($record) if $self->debug; |
55
|
57
|
|
|
|
|
155
|
my $stream = $record->stream; |
56
|
57
|
|
|
|
|
106
|
my $type = $self->{Streams}->[$stream]; |
57
|
|
|
|
|
|
|
|
58
|
57
|
50
|
|
|
|
188
|
if (!defined $type) { |
|
|
50
|
|
|
|
|
|
59
|
0
|
|
|
|
|
0
|
$self->warning("Ignoring record: " . |
60
|
|
|
|
|
|
|
"Invalid stream: " . |
61
|
|
|
|
|
|
|
$stream); |
62
|
0
|
|
|
|
|
0
|
next RECORDS; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
elsif ($type ne $record->type) { |
65
|
0
|
|
|
|
|
0
|
$self->warning("Ignoring record: " . |
66
|
|
|
|
|
|
|
"Stream type mismatch: " . |
67
|
|
|
|
|
|
|
"Expected $type, got " . $record->type . |
68
|
|
|
|
|
|
|
": " . $record->as_string); |
69
|
0
|
|
|
|
|
0
|
next RECORDS; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
else { |
72
|
57
|
|
|
|
|
157
|
push @toreturn, $record; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
63
|
50
|
|
|
|
219
|
if (wantarray) { |
|
|
50
|
|
|
|
|
|
77
|
0
|
|
|
|
|
0
|
return @toreturn; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
elsif (@toreturn <= 1) { |
80
|
63
|
|
|
|
|
169
|
return $toreturn[0]; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
else { |
83
|
0
|
|
|
|
|
0
|
croak("Parser has @{[scalar @toreturn]} records to return, but parse() was called in scalar context"); |
|
0
|
|
|
|
|
0
|
|
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
} |
86
|
0
|
|
|
|
|
0
|
$self->{Done} = 1; |
87
|
0
|
|
|
|
|
0
|
return; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
78
|
|
|
78
|
0
|
218
|
sub debug { $ENV{DEBUG} } |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
1; |