blib/lib/POE/Filter/CSV_XS.pm

filter: Statementstmt 76.0% 38 / 50 Branchbran 30.0% 3 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 80.0% 8 / 10 Podpod 100% 5 / 5 totaltotal 72.0% 54 / 75 SCAR 25.8
CC
10
Cov
68%
get_one
12.0
get_one_start
6.0
put
4.2
CRAP 13.2
↑ Summary
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  
10 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 4 ▶use Text::CSV_XS;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 4 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 4 ▶use base qw(POE::Filter);
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 4 $VERSION = '1.16';
17  
18 sub new {
19 2 ▶ my $class = shift;
Subroutine new: called CC=2 SCAR=6.9
Pod documented
20 2 my %opts = @_;
21 2 $opts{lc $_} = delete $opts{$_} for keys %opts;
22 2 delete $opts{eol};
23 2 my $self = {};
24 2 $self->{BUFFER} = [];
25 2 $self->{csv_filter} = Text::CSV_XS->new( \%opts );
26 2 bless $self, $class;
27 }
28  
29 sub get {
30 2 ▶ my ($self, $raw) = @_;
Subroutine get: called CC=3 SCAR=11.0
Pod documented
31 2 my $events = [];
32  
33 2 foreach my $event ( @$raw ) {
34 2 my $status = $self->{csv_filter}->parse($event);
35 2 ▶ push @$events, [ $self->{csv_filter}->fields() ] if $status;
Branch: 1 branch
BranchTrueFalseTotal
if $status 2 0 2
36 }
37 2 return $events;
38 }
39  
40 sub get_one_start {
41 0 ▶ my ($self, $raw) = @_;
Subroutine get_one_start: not called CC=2 SCAR=17.9
Pod documented
42 0 push @{ $self->{BUFFER} }, $_ for @$raw;
43 }
44  
45 sub get_one {
46 0 ▶ my $self = shift;
Subroutine get_one: not called CC=3 SCAR=24.8
Pod documented
47 0 my $events = [];
48  
49 0 my $event = shift @{ $self->{BUFFER} };
50 0 ▶ if ( defined $event ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $event) 0 0 0
51 0 my $status = $self->{csv_filter}->parse($event);
52 0 ▶ push @$events, [ $self->{csv_filter}->fields() ] if $status;
Branch: 1 branch
BranchTrueFalseTotal
if $status 0 0 0
53 }
54 0 return $events;
55 }
56  
57 sub put {
58 2 ▶ my ($self,$events) = @_;
Subroutine put: called CC=4 SCAR=14.5
Pod documented
59 2 my $raw_lines = [];
60  
61 2 foreach my $event ( @$events ) {
62 2 ▶ if ( ref $event eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $event eq 'ARRAY') { } 2 0 2
63 2 my $status = $self->{csv_filter}->combine(@$event);
64 2 ▶ push @$raw_lines, $self->{csv_filter}->string() if $status;
Branch: 1 branch
BranchTrueFalseTotal
if $status 2 0 2
65  
66 }
67 else {
68 0 warn "non arrayref passed to put()\n";
69 }
70 }
71 2 return $raw_lines;
72 }
73  
74 4 1;
75 __END__
↑ Summary