line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::CSV_PP::Simple; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
2523
|
use warnings; |
|
4
|
|
|
|
|
13
|
|
|
4
|
|
|
|
|
246
|
|
4
|
4
|
|
|
4
|
|
26
|
use strict; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
143
|
|
5
|
4
|
|
|
4
|
|
21
|
use Carp; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
373
|
|
6
|
|
|
|
|
|
|
|
7
|
4
|
|
|
4
|
|
5373
|
use version; our $VERSION = qv('0.0.5'); |
|
4
|
|
|
|
|
11279
|
|
|
4
|
|
|
|
|
251
|
|
8
|
|
|
|
|
|
|
|
9
|
4
|
|
|
4
|
|
21419
|
use Text::CSV_PP; |
|
4
|
|
|
|
|
89736
|
|
|
4
|
|
|
|
|
160
|
|
10
|
4
|
|
|
4
|
|
6294
|
use IO::File; |
|
4
|
|
|
|
|
78936
|
|
|
4
|
|
|
|
|
1994
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
2
|
|
|
2
|
1
|
31
|
my $class = shift; |
14
|
2
|
|
|
|
|
31
|
return bless { _parser => Text::CSV_PP->new(@_), } => $class; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub field_map { |
18
|
6
|
|
|
6
|
1
|
11
|
my $self = shift; |
19
|
6
|
50
|
|
|
|
17
|
if (@_) { |
20
|
0
|
|
|
|
|
0
|
$self->{_map} = [@_]; |
21
|
|
|
|
|
|
|
} |
22
|
6
|
50
|
|
|
|
9
|
return @{ $self->{_map} || [] }; |
|
6
|
|
|
|
|
44
|
|
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub want_fields { |
26
|
7
|
|
|
7
|
1
|
117
|
my $self = shift; |
27
|
7
|
100
|
|
|
|
22
|
if (@_) { |
28
|
1
|
|
|
|
|
9
|
$self->{_wanted} = [@_]; |
29
|
|
|
|
|
|
|
} |
30
|
7
|
100
|
|
|
|
9
|
return @{ $self->{_wanted} || [] }; |
|
7
|
|
|
|
|
64
|
|
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub read_file { |
34
|
2
|
|
|
2
|
1
|
101
|
my ($self, $file) = @_; |
35
|
|
|
|
|
|
|
|
36
|
2
|
|
|
|
|
5
|
my @result; |
37
|
2
|
|
|
|
|
8
|
my $csv = $self->{"_parser"}; |
38
|
2
|
50
|
|
|
|
19
|
my $fh = IO::File->new($file, 'r') or croak $!; |
39
|
2
|
|
|
|
|
288
|
while (not $fh->eof) { |
40
|
6
|
|
|
|
|
119
|
my $cells = $csv->getline($fh); |
41
|
6
|
100
|
|
|
|
2218
|
if (my @wanted = $self->want_fields){ |
42
|
3
|
|
|
|
|
5
|
@{$cells} = @{$cells}[@wanted]; |
|
3
|
|
|
|
|
11
|
|
|
3
|
|
|
|
|
4
|
|
43
|
|
|
|
|
|
|
} |
44
|
4
|
|
|
4
|
|
5225
|
use Data::Dumper; |
|
4
|
|
|
|
|
29170
|
|
|
4
|
|
|
|
|
954
|
|
45
|
6
|
|
|
|
|
27
|
print Dumper $cells; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
48
|
6
|
|
|
|
|
566
|
my $addition = $cells; |
49
|
6
|
50
|
|
|
|
18
|
if (my @map = $self->field_map ){ |
50
|
0
|
|
|
|
|
0
|
my $hash = { map { $_ => shift @{$cells} } @map }; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
51
|
0
|
|
|
|
|
0
|
delete $hash->{null}; |
52
|
0
|
|
|
|
|
0
|
$addition = $hash; |
53
|
|
|
|
|
|
|
} |
54
|
6
|
|
|
|
|
26
|
push @result, $addition; |
55
|
|
|
|
|
|
|
} |
56
|
2
|
|
|
|
|
44
|
return @result; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
1; |
60
|
|
|
|
|
|
|
__END__ |