CSV/Hash.pm

filter: Statementstmt 96.0% 72 / 75 Branchbran 81.2% 13 / 16 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 93.7% 15 / 16 Podpod n/a totaltotal 93.7% 105 / 112 CC 10 SCAR 7.5
CC
10
Cov
94%
STORE
6.0
_stringify
3.0
TIEHASH
2.0
CRAP 2.1
« CSV.pm ↑ Summary CSV/Array.pm »
1 package Tie::Handle::CSV::Hash;
2  
3 11 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 11 ▶use Carp 'cluck';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 11 ▶use overload '""' => \&_stringify, fallback => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 sub _new
12 22 ▶ {
Subroutine _new: called CC=1 SCAR=0.0
13 22 my ($class, $parent) = @_;
14 22 my %self;
15 22 tie(%self, $class, $parent);
16 22 bless \%self, $class;
17 }
18  
19 sub TIEHASH
20 22 ▶ {
Subroutine TIEHASH: called CC=2 SCAR=6.9
21 22 my ($class, $parent) = @_;
22 22 my $opts = *$parent->{opts};
23 my $self = bless
24 {
25 data => {},
26 csv_xs => $opts->{csv_parser},
27 header => $opts->{header},
28 },
29 22 $class;
30  
31 22 ▶ $self->{'lc'} = defined $opts->{'key_case'} && lc $opts->{'key_case'} eq 'any';
Condition100%3/3
defined $opts->{'key_case'} && lc $opts->{'key_case'} eq 'any'
!ll&&!rl&&r
4162
MC/DC100%2/2
defined $opts->{'key_case'} && lc $opts->{'key_case'} eq 'any'
defined $opts->{'key_case'} lc $opts->{'key_case'} eq 'any'
Truth table100%3/3
A && B
A= defined $opts->{'key_case'}B= lc $opts->{'key_case'} eq 'any'
ABresult
0X0
100
111
32 22 return $self;
33 }
34  
35 sub STORE
36 0 ▶ {
Subroutine STORE: not called CC=2 SCAR=17.9
37 0 my ($self, $key, $value) = @_;
38 0 ▶ $key = lc $key if $self->{lc};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"lc"} 0 0 0
39 0 $self->{'data'}{$key} = $value;
40 }
41  
42 sub FETCH
43 89 ▶ {
Subroutine FETCH: called CC=2 SCAR=6.9
44 89 my ($self, $key) = @_;
45 89 ▶ $key = lc $key if $self->{lc};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"lc"} 9 80 89
46 89 return $self->{'data'}{$key};
47 }
48  
49 sub EXISTS
50 2 ▶ {
Subroutine EXISTS: called CC=2 SCAR=6.9
51 2 my ($self, $key) = @_;
52 2 ▶ $key = lc $key if $self->{lc};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"lc"} 1 1 2
53 2 exists $self->{'data'}{$key};
54 }
55  
56 sub DELETE
57 2 ▶ {
Subroutine DELETE: called CC=2 SCAR=6.9
58 2 my ($self, $key) = @_;
59 2 ▶ $key = lc $key if $self->{lc};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"lc"} 1 1 2
60 2 delete $self->{'data'}{$key};
61 }
62  
63 sub CLEAR
64 1 ▶ {
Subroutine CLEAR: called CC=1 SCAR=0.0
65 1 my ($self) = @_;
66 1 %{ $self->{'data'} } = ();
67 }
68  
69 sub FIRSTKEY
70 4 ▶ {
Subroutine FIRSTKEY: called CC=1 SCAR=0.0
71 4 my ($self) = @_;
72 4 $self->{'keys'} = [ @{ $self->{'header'} } ];
73 4 return shift @{ $self->{'keys'} };
74 }
75  
76 sub NEXTKEY
77 12 ▶ {
Subroutine NEXTKEY: called CC=2 SCAR=6.9
78 12 my ($self) = @_;
79 12 @{ $self->{'keys'} }
80 12 ▶ ? return shift @{ $self->{'keys'} }
Branch: 1 branch
BranchTrueFalseTotal
@{$self->{'keys'};} ? : 8 4 12
81 : return;
82 }
83  
84 sub _stringify
85 22 ▶ {
Subroutine _stringify: called CC=3 SCAR=11.0
86 22 my ($self) = @_;
87 22 my $under_tie = tied %{ $self };
88 22 my $keys = $under_tie->{'header'};
89 22 ▶ if ($under_tie->{'lc'})
Branch: 1 branch
BranchTrueFalseTotal
if ($under_tie->{"lc"}) 2 20 22
90 {
91 2 $keys = [ map { lc($_) } @{ $keys } ];
92 }
93 22 my @values = @{ $under_tie->{'data'} }{ @{ $keys } };
94 22 my $csv_xs = $under_tie->{csv_xs};
95 22 ▶ $csv_xs->combine(@values)
Branch: 1 branch
BranchTrueFalseTotal
$csv_xs->combine(@values) or $$csv_xs->croak->error_input 22 0 22
96 || croak $$csv_xs->error_input();
97 22 return $csv_xs->string();
98 }
99  
100 sub _init_store
101 22 ▶ {
Subroutine _init_store: called CC=2 SCAR=6.9
102 22 my ($self, $values) = @_;
103 22 my $under_tie = tied %{ $self };
104 22 my $keys = $under_tie->{'header'};
105 22 ▶ if ($under_tie->{'lc'})
Branch: 1 branch
BranchTrueFalseTotal
if ($under_tie->{"lc"}) 2 20 22
106 {
107 2 $keys = [ map { lc($_) } @{ $keys } ];
108 }
109 22 my $data = $under_tie->{data};
110 22 @{ $data }{ @{ $keys } } = @{ $values };
111 }
112  
113 11 1;
114  
115 __END__
« CSV.pm ↑ Summary CSV/Array.pm »