blib/lib/Text/ECSV.pm

filter: Statementstmt 94.2% 33 / 35 Branchbran 75.0% 6 / 8 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 6 / 6 Podpod 100% 3 / 3 totaltotal 89.4% 51 / 57 CC 7 SCAR 13.5
CC
7
Cov
89%
parse
6.4
combine
2.0
BEGIN
1.0
CRAP 3.9
↑ Summary
1 package Text::ECSV;
2  
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 our $VERSION = '0.02';
7  
8 1 ▶use base 'Text::CSV_XS', 'Class::Accessor::Fast';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 __PACKAGE__->mk_accessors(qw{
11 fields_hash
12 dup_keys_strategy
13 }
14 );
15  
16 7 ▶sub field_named {
Subroutine field_named: called CC=1 SCAR=0.0
Pod documented
17 7 my $self = shift;
18 7 my $name = shift;
19  
20 7 return $self->fields_hash->{$name};
21 }
22  
23 4 ▶sub parse {
Subroutine parse: called CC=6 SCAR=18.5
Pod documented
24 4 my $self = shift;
25  
26 # reset fields hash
27 4 $self->fields_hash({});
28  
29 # run Text::CSV_XS parse
30 4 my $status = $self->SUPER::parse(@_);
31  
32 # if the CSV parsing failed then just return
33 4 ▶ return $status
Branch: 1 branch
BranchTrueFalseTotal
unless $status 0 4 4
34 if not $status;
35  
36 # decode the fileds
37 4 foreach my $field ($self->fields) {
38  
39 # if we have key value pair
40 14 ▶ if ($field =~ m/^([^=]+)=(.*)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($field =~ /^([^=]+)=(.*)$/) { } 14 0 14
41 14 my $name = $1;
42 14 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 ▶ if ( exists $self->{'fields_hash'}->{$name}
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"fields_hash"}{$name} and exists $self->{"dup_keys_strategy"}) 3 11 14
Condition66%2/3
exists $self->{"fields_hash"}{$name} and exists $self->{"dup_keys_strategy"}
!ll&&!rl&&r
1103
MC/DC50%1/2
exists $self->{"fields_hash"}{$name} and exists $self->{"dup_keys_strategy"}
exists $self->{"fields_hash"}{$name} exists $self->{"dup_keys_strategy"}
Truth table66%2/3
A and B
A= exists $self->{"fields_hash"}{$name}B= exists $self->{"dup_keys_strategy"}
ABresult
0X0
100
111
47 and exists $self->{'dup_keys_strategy'}) {
48 $value = $self->{'dup_keys_strategy'}
49 3 ->($name, $self->{'fields_hash'}->{$name}, $value);
50 }
51  
52 # store value
53 14 $self->{'fields_hash'}->{$name} = $value;
54 }
55  
56 # else fail
57 else {
58 0 $status = 0;
59  
60 # TODO fill error messages
61  
62 0 last;
63 }
64 }
65  
66 4 return $status;
67 }
68  
69 1 ▶sub combine {
Subroutine combine: called CC=2 SCAR=6.9
Pod documented
70 1 my $self = shift;
71 1 my @key_values = @_;
72 1 my @fields;
73  
74 1 ▶ while (@key_values) {
Branch: 1 branch
BranchTrueFalseTotal
if (@key_values) 3 1 4
75 3 push @fields, (shift(@key_values) . '=' . shift(@key_values));
76 }
77  
78 1 return $self->SUPER::combine(@fields);
79 }
80  
81 1 1;
82  
83 __END__
↑ Summary