| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Text::ECSV; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
19892
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
34
|
|
|
4
|
1
|
|
|
1
|
|
4
|
use strict; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
36
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
|
7
|
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
3
|
use base 'Text::CSV_XS', 'Class::Accessor::Fast'; |
|
|
1
|
|
|
|
|
5
|
|
|
|
1
|
|
|
|
|
976
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw{ |
|
11
|
|
|
|
|
|
|
fields_hash |
|
12
|
|
|
|
|
|
|
dup_keys_strategy |
|
13
|
|
|
|
|
|
|
} |
|
14
|
|
|
|
|
|
|
); |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub field_named { |
|
17
|
7
|
|
|
7
|
1
|
585
|
my $self = shift; |
|
18
|
7
|
|
|
|
|
7
|
my $name = shift; |
|
19
|
|
|
|
|
|
|
|
|
20
|
7
|
|
|
|
|
13
|
return $self->fields_hash->{$name}; |
|
21
|
|
|
|
|
|
|
} |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub parse { |
|
24
|
4
|
|
|
4
|
1
|
2772
|
my $self = shift; |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# reset fields hash |
|
27
|
4
|
|
|
|
|
14
|
$self->fields_hash({}); |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# run Text::CSV_XS parse |
|
30
|
4
|
|
|
|
|
33
|
my $status = $self->SUPER::parse(@_); |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# if the CSV parsing failed then just return |
|
33
|
4
|
50
|
|
|
|
103
|
return $status |
|
34
|
|
|
|
|
|
|
if not $status; |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# decode the fileds |
|
37
|
4
|
|
|
|
|
15
|
foreach my $field ($self->fields) { |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# if we have key value pair |
|
40
|
14
|
50
|
|
|
|
68
|
if ($field =~ m/^([^=]+)=(.*)$/) { |
|
41
|
14
|
|
|
|
|
19
|
my $name = $1; |
|
42
|
14
|
|
|
|
|
15
|
my $value = $2; |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# if it the second occurence of the same key and we have a strategy use it |
|
45
|
|
|
|
|
|
|
# to construct the new value |
|
46
|
14
|
50
|
66
|
|
|
30
|
if ( exists $self->{'fields_hash'}->{$name} |
|
47
|
|
|
|
|
|
|
and exists $self->{'dup_keys_strategy'}) { |
|
48
|
|
|
|
|
|
|
$value = $self->{'dup_keys_strategy'} |
|
49
|
3
|
|
|
|
|
8
|
->($name, $self->{'fields_hash'}->{$name}, $value); |
|
50
|
|
|
|
|
|
|
} |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# store value |
|
53
|
14
|
|
|
|
|
44
|
$self->{'fields_hash'}->{$name} = $value; |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# else fail |
|
57
|
|
|
|
|
|
|
else { |
|
58
|
0
|
|
|
|
|
0
|
$status = 0; |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# TODO fill error messages |
|
61
|
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
0
|
last; |
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
|
|
66
|
4
|
|
|
|
|
15
|
return $status; |
|
67
|
|
|
|
|
|
|
} |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub combine { |
|
70
|
1
|
|
|
1
|
1
|
594
|
my $self = shift; |
|
71
|
1
|
|
|
|
|
4
|
my @key_values = @_; |
|
72
|
1
|
|
|
|
|
2
|
my @fields; |
|
73
|
|
|
|
|
|
|
|
|
74
|
1
|
|
|
|
|
3
|
while (@key_values) { |
|
75
|
3
|
|
|
|
|
10
|
push @fields, (shift(@key_values) . '=' . shift(@key_values)); |
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
|
|
78
|
1
|
|
|
|
|
6
|
return $self->SUPER::combine(@fields); |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
1; |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
__END__ |