line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Author Chris "BinGOs" Williams |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# This module may be used, modified, and distributed under the same |
4
|
|
|
|
|
|
|
# terms as Perl itself. Please see the license that came with your Perl |
5
|
|
|
|
|
|
|
# distribution for details. |
6
|
|
|
|
|
|
|
# |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
package POE::Filter::CSV; |
9
|
|
|
|
|
|
|
$POE::Filter::CSV::VERSION = '1.18'; |
10
|
|
|
|
|
|
|
#ABSTRACT: A POE-based parser for CSV based files. |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
13121
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
23
|
|
13
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
18
|
|
14
|
1
|
|
|
1
|
|
594
|
use Text::CSV; |
|
1
|
|
|
|
|
8629
|
|
|
1
|
|
|
|
|
42
|
|
15
|
1
|
|
|
1
|
|
7
|
use base qw(POE::Filter); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
432
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub new { |
18
|
1
|
|
|
1
|
1
|
10
|
my $class = shift; |
19
|
1
|
|
|
|
|
3
|
my $self = {}; |
20
|
1
|
|
|
|
|
2
|
$self->{BUFFER} = []; |
21
|
1
|
|
|
|
|
7
|
$self->{csv_filter} = Text::CSV->new(@_); |
22
|
1
|
|
|
|
|
91
|
bless $self, $class; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub get { |
26
|
2
|
|
|
2
|
1
|
1002
|
my ($self, $raw) = @_; |
27
|
2
|
|
|
|
|
3
|
my $events = []; |
28
|
|
|
|
|
|
|
|
29
|
2
|
|
|
|
|
3
|
foreach my $event ( @$raw ) { |
30
|
2
|
|
|
|
|
11
|
my $status = $self->{csv_filter}->parse($event); |
31
|
2
|
50
|
|
|
|
65
|
push @$events, [ $self->{csv_filter}->fields() ] if $status; |
32
|
|
|
|
|
|
|
} |
33
|
2
|
|
|
|
|
14
|
return $events; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub get_one_start { |
37
|
0
|
|
|
0
|
1
|
0
|
my ($self, $raw) = @_; |
38
|
0
|
|
|
|
|
0
|
push @{ $self->{BUFFER} }, $_ for @$raw; |
|
0
|
|
|
|
|
0
|
|
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub get_one { |
42
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
43
|
0
|
|
|
|
|
0
|
my $events = []; |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
0
|
my $event = shift @{ $self->{BUFFER} }; |
|
0
|
|
|
|
|
0
|
|
46
|
0
|
0
|
|
|
|
0
|
if ( defined $event ) { |
47
|
0
|
|
|
|
|
0
|
my $status = $self->{csv_filter}->parse($event); |
48
|
0
|
0
|
|
|
|
0
|
push @$events, [ $self->{csv_filter}->fields() ] if $status; |
49
|
|
|
|
|
|
|
} |
50
|
0
|
|
|
|
|
0
|
return $events; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub put { |
54
|
2
|
|
|
2
|
1
|
335
|
my ($self,$events) = @_; |
55
|
2
|
|
|
|
|
2
|
my $raw_lines = []; |
56
|
|
|
|
|
|
|
|
57
|
2
|
|
|
|
|
4
|
foreach my $event ( @$events ) { |
58
|
2
|
50
|
|
|
|
5
|
if ( ref $event eq 'ARRAY' ) { |
59
|
2
|
|
|
|
|
10
|
my $status = $self->{csv_filter}->combine(@$event); |
60
|
2
|
50
|
|
|
|
37
|
push @$raw_lines, $self->{csv_filter}->string() if $status; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
else { |
64
|
0
|
|
|
|
|
0
|
warn "non arrayref passed to put()\n"; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
} |
67
|
2
|
|
|
|
|
13
|
return $raw_lines; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub clone { |
71
|
1
|
|
|
1
|
1
|
166
|
my $self = shift; |
72
|
1
|
|
|
|
|
2
|
my $nself = { }; |
73
|
1
|
|
|
|
|
1
|
$nself->{$_} = $self->{$_} for keys %{ $self }; |
|
1
|
|
|
|
|
5
|
|
74
|
1
|
|
|
|
|
2
|
$nself->{BUFFER} = [ ]; |
75
|
1
|
|
|
|
|
3
|
return bless $nself, ref $self; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
qq[let,us,csv]; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
__END__ |