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_XS; |
9
|
|
|
|
|
|
|
$POE::Filter::CSV_XS::VERSION = '1.18'; |
10
|
|
|
|
|
|
|
#ABSTRACT: A POE-based parser for CSV based files. |
11
|
|
|
|
|
|
|
|
12
|
2
|
|
|
2
|
|
28621
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
46
|
|
13
|
2
|
|
|
2
|
|
6
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
40
|
|
14
|
2
|
|
|
2
|
|
1464
|
use Text::CSV_XS; |
|
2
|
|
|
|
|
14803
|
|
|
2
|
|
|
|
|
120
|
|
15
|
2
|
|
|
2
|
|
15
|
use base qw(POE::Filter); |
|
2
|
|
|
|
|
1
|
|
|
2
|
|
|
|
|
1012
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub new { |
18
|
2
|
|
|
2
|
1
|
24
|
my $class = shift; |
19
|
2
|
|
|
|
|
4
|
my %opts = @_; |
20
|
2
|
|
|
|
|
11
|
$opts{lc $_} = delete $opts{$_} for keys %opts; |
21
|
2
|
|
|
|
|
3
|
delete $opts{eol}; |
22
|
2
|
|
|
|
|
3
|
my $self = {}; |
23
|
2
|
|
|
|
|
4
|
$self->{BUFFER} = []; |
24
|
2
|
|
|
|
|
14
|
$self->{csv_filter} = Text::CSV_XS->new( \%opts ); |
25
|
2
|
|
|
|
|
235
|
bless $self, $class; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub get { |
29
|
2
|
|
|
2
|
1
|
1003
|
my ($self, $raw) = @_; |
30
|
2
|
|
|
|
|
3
|
my $events = []; |
31
|
|
|
|
|
|
|
|
32
|
2
|
|
|
|
|
6
|
foreach my $event ( @$raw ) { |
33
|
2
|
|
|
|
|
15
|
my $status = $self->{csv_filter}->parse($event); |
34
|
2
|
50
|
|
|
|
94
|
push @$events, [ $self->{csv_filter}->fields() ] if $status; |
35
|
|
|
|
|
|
|
} |
36
|
2
|
|
|
|
|
17
|
return $events; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub get_one_start { |
40
|
0
|
|
|
0
|
1
|
0
|
my ($self, $raw) = @_; |
41
|
0
|
|
|
|
|
0
|
push @{ $self->{BUFFER} }, $_ for @$raw; |
|
0
|
|
|
|
|
0
|
|
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub get_one { |
45
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
46
|
0
|
|
|
|
|
0
|
my $events = []; |
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
0
|
my $event = shift @{ $self->{BUFFER} }; |
|
0
|
|
|
|
|
0
|
|
49
|
0
|
0
|
|
|
|
0
|
if ( defined $event ) { |
50
|
0
|
|
|
|
|
0
|
my $status = $self->{csv_filter}->parse($event); |
51
|
0
|
0
|
|
|
|
0
|
push @$events, [ $self->{csv_filter}->fields() ] if $status; |
52
|
|
|
|
|
|
|
} |
53
|
0
|
|
|
|
|
0
|
return $events; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub put { |
57
|
2
|
|
|
2
|
1
|
546
|
my ($self,$events) = @_; |
58
|
2
|
|
|
|
|
4
|
my $raw_lines = []; |
59
|
|
|
|
|
|
|
|
60
|
2
|
|
|
|
|
5
|
foreach my $event ( @$events ) { |
61
|
2
|
50
|
|
|
|
7
|
if ( ref $event eq 'ARRAY' ) { |
62
|
2
|
|
|
|
|
9
|
my $status = $self->{csv_filter}->combine(@$event); |
63
|
2
|
50
|
|
|
|
48
|
push @$raw_lines, $self->{csv_filter}->string() if $status; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
else { |
67
|
0
|
|
|
|
|
0
|
warn "non arrayref passed to put()\n"; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
} |
70
|
2
|
|
|
|
|
17
|
return $raw_lines; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
qq[let,us,csv,xs]; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
__END__ |