blib/lib/POE/Filter/CSV.pm

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