| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Pipe::Tube::Csv; |
|
2
|
1
|
|
|
1
|
|
2680
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
28
|
|
|
3
|
1
|
|
|
1
|
|
10
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
40
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.05'; |
|
6
|
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
5
|
use base 'Pipe::Tube'; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
96
|
|
|
8
|
1
|
|
|
1
|
|
847
|
use Text::CSV; |
|
|
1
|
|
|
|
|
23039
|
|
|
|
1
|
|
|
|
|
46
|
|
|
9
|
1
|
|
|
1
|
|
605
|
use Data::Dumper; |
|
|
1
|
|
|
|
|
7205
|
|
|
|
1
|
|
|
|
|
191
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub init { |
|
13
|
1
|
|
|
1
|
0
|
280
|
my ($self, $attr) = @_; |
|
14
|
1
|
50
|
33
|
|
|
10
|
die "First paramater of csv should be HASH reference or nothing" if $attr and ref $attr ne 'HASH'; |
|
15
|
1
|
|
50
|
|
|
11
|
$attr ||= {}; |
|
16
|
|
|
|
|
|
|
|
|
17
|
1
|
|
|
|
|
3
|
$self->logger("Receiving Csv definition: " . Dumper $attr); |
|
18
|
|
|
|
|
|
|
|
|
19
|
1
|
|
|
|
|
76
|
$self->{csv} = Text::CSV->new($attr); |
|
20
|
|
|
|
|
|
|
|
|
21
|
1
|
|
|
|
|
115
|
return $self; |
|
22
|
|
|
|
|
|
|
} |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub run { |
|
25
|
4
|
|
|
4
|
0
|
270
|
my ($self, @input) = @_; |
|
26
|
|
|
|
|
|
|
|
|
27
|
4
|
|
|
|
|
5
|
my @resp; |
|
28
|
4
|
|
|
|
|
7
|
foreach my $line (@input) { |
|
29
|
2
|
|
|
|
|
8
|
$self->{csv}->parse($line); |
|
30
|
2
|
|
|
|
|
71
|
push @resp, [ $self->{csv}->fields ]; |
|
31
|
|
|
|
|
|
|
} |
|
32
|
4
|
|
|
|
|
25
|
return @resp; |
|
33
|
|
|
|
|
|
|
} |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
1; |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
__END__ |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head1 NAME |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
Pipe::Tube::Csv - Csv processor tube in Pipe |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 SYNPOSIS |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
my @resp = Pipe->for(@rows)->csv->run; |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
my @resp = Pipe->cat("t/data/file1", "t/data/file2") |
|
48
|
|
|
|
|
|
|
->csv({ sep_char => "\t" }) |
|
49
|
|
|
|
|
|
|
->run; |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
The ->csv() call can get a HASH reference parameter, the same parameter as |
|
54
|
|
|
|
|
|
|
L<Text::CSV> would get. We pass it directly to that module. |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
Split up lines of csv file and return an array reference for each line. |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
TODO: use the first row as key names and on every other row return a hash of the values |
|
59
|
|
|
|
|
|
|
using the above header |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head1 AUTHOR |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
Gabor Szabo <gabor@szabgab.com> |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head1 COPYRIGHT |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
Copyright 2006-2012 by Gabor Szabo <gabor@szabgab.com>. |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
This program is free software; |
|
71
|
|
|
|
|
|
|
you can redistribute it and/or modify it under the same terms as Perl itself. |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
See http://www.perl.com/perl/misc/Artistic.html |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 See Also |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
L<Pipe> and L<Text::CSV> |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=cut |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
|