line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Tie::Handle::CSV::Hash; |
2
|
|
|
|
|
|
|
|
3
|
10
|
|
|
10
|
|
200
|
use 5.006; |
|
10
|
|
|
|
|
37
|
|
|
10
|
|
|
|
|
418
|
|
4
|
10
|
|
|
10
|
|
4228
|
use strict; |
|
10
|
|
|
|
|
24
|
|
|
10
|
|
|
|
|
439
|
|
5
|
10
|
|
|
10
|
|
59
|
use warnings; |
|
10
|
|
|
|
|
19
|
|
|
10
|
|
|
|
|
377
|
|
6
|
|
|
|
|
|
|
|
7
|
10
|
|
|
10
|
|
60
|
use Carp 'cluck'; |
|
10
|
|
|
|
|
19
|
|
|
10
|
|
|
|
|
758
|
|
8
|
|
|
|
|
|
|
|
9
|
10
|
|
|
10
|
|
1506
|
use overload '""' => \&_stringify, fallback => 1; |
|
10
|
|
|
|
|
1108
|
|
|
10
|
|
|
|
|
123
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub _new |
12
|
|
|
|
|
|
|
{ |
13
|
22
|
|
|
22
|
|
40
|
my ($class, $parent) = @_; |
14
|
22
|
|
|
|
|
26
|
my %self; |
15
|
22
|
|
|
|
|
431
|
tie(%self, $class, $parent); |
16
|
22
|
|
|
|
|
89
|
bless \%self, $class; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub TIEHASH |
20
|
|
|
|
|
|
|
{ |
21
|
22
|
|
|
22
|
|
34
|
my ($class, $parent) = @_; |
22
|
22
|
|
|
|
|
56
|
my $opts = *$parent->{opts}; |
23
|
22
|
|
|
|
|
150
|
my $self = bless |
24
|
|
|
|
|
|
|
{ |
25
|
|
|
|
|
|
|
data => {}, |
26
|
|
|
|
|
|
|
csv_xs => $opts->{csv_parser}, |
27
|
|
|
|
|
|
|
header => $opts->{header}, |
28
|
|
|
|
|
|
|
}, |
29
|
|
|
|
|
|
|
$class; |
30
|
|
|
|
|
|
|
|
31
|
22
|
|
100
|
|
|
315
|
$self->{'lc'} = defined $opts->{'key_case'} && lc $opts->{'key_case'} eq 'any'; |
32
|
22
|
|
|
|
|
61
|
return $self; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub STORE |
36
|
|
|
|
|
|
|
{ |
37
|
0
|
|
|
0
|
|
0
|
my ($self, $key, $value) = @_; |
38
|
0
|
0
|
|
|
|
0
|
$key = lc $key if $self->{lc}; |
39
|
0
|
|
|
|
|
0
|
$self->{'data'}{$key} = $value; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub FETCH |
43
|
|
|
|
|
|
|
{ |
44
|
89
|
|
|
89
|
|
58451
|
my ($self, $key) = @_; |
45
|
89
|
100
|
|
|
|
285
|
$key = lc $key if $self->{lc}; |
46
|
89
|
|
|
|
|
578
|
return $self->{'data'}{$key}; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub EXISTS |
50
|
|
|
|
|
|
|
{ |
51
|
2
|
|
|
2
|
|
1198
|
my ($self, $key) = @_; |
52
|
2
|
100
|
|
|
|
14
|
$key = lc $key if $self->{lc}; |
53
|
2
|
|
|
|
|
14
|
exists $self->{'data'}{$key}; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub DELETE |
57
|
|
|
|
|
|
|
{ |
58
|
2
|
|
|
2
|
|
7
|
my ($self, $key) = @_; |
59
|
2
|
100
|
|
|
|
14
|
$key = lc $key if $self->{lc}; |
60
|
2
|
|
|
|
|
16
|
delete $self->{'data'}{$key}; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub CLEAR |
64
|
|
|
|
|
|
|
{ |
65
|
1
|
|
|
1
|
|
3
|
my ($self) = @_; |
66
|
1
|
|
|
|
|
2
|
%{ $self->{'data'} } = (); |
|
1
|
|
|
|
|
7
|
|
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub FIRSTKEY |
70
|
|
|
|
|
|
|
{ |
71
|
4
|
|
|
4
|
|
1735
|
my ($self) = @_; |
72
|
4
|
|
|
|
|
8
|
$self->{'keys'} = [ @{ $self->{'header'} } ]; |
|
4
|
|
|
|
|
23
|
|
73
|
4
|
|
|
|
|
6
|
return shift @{ $self->{'keys'} }; |
|
4
|
|
|
|
|
22
|
|
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub NEXTKEY |
77
|
|
|
|
|
|
|
{ |
78
|
12
|
|
|
12
|
|
20
|
my ($self) = @_; |
79
|
12
|
|
|
|
|
50
|
@{ $self->{'keys'} } |
|
8
|
|
|
|
|
29
|
|
80
|
12
|
100
|
|
|
|
15
|
? return shift @{ $self->{'keys'} } |
81
|
|
|
|
|
|
|
: return; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub _stringify |
85
|
|
|
|
|
|
|
{ |
86
|
22
|
|
|
22
|
|
8802
|
my ($self) = @_; |
87
|
22
|
|
|
|
|
32
|
my $under_tie = tied %{ $self }; |
|
22
|
|
|
|
|
55
|
|
88
|
22
|
|
|
|
|
56
|
my $keys = $under_tie->{'header'}; |
89
|
22
|
100
|
|
|
|
74
|
if ($under_tie->{'lc'}) |
90
|
|
|
|
|
|
|
{ |
91
|
2
|
|
|
|
|
7
|
$keys = [ map { lc($_) } @{ $keys } ]; |
|
6
|
|
|
|
|
17
|
|
|
2
|
|
|
|
|
5
|
|
92
|
|
|
|
|
|
|
} |
93
|
22
|
|
|
|
|
32
|
my @values = @{ $under_tie->{'data'} }{ @{ $keys } }; |
|
22
|
|
|
|
|
88
|
|
|
22
|
|
|
|
|
33
|
|
94
|
22
|
|
|
|
|
42
|
my $csv_xs = $under_tie->{csv_xs}; |
95
|
22
|
50
|
|
|
|
86
|
$csv_xs->combine(@values) |
96
|
|
|
|
|
|
|
|| croak $$csv_xs->error_input(); |
97
|
22
|
|
|
|
|
451
|
return $csv_xs->string(); |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub _init_store |
101
|
|
|
|
|
|
|
{ |
102
|
22
|
|
|
22
|
|
35
|
my ($self, $values) = @_; |
103
|
22
|
|
|
|
|
30
|
my $under_tie = tied %{ $self }; |
|
22
|
|
|
|
|
51
|
|
104
|
22
|
|
|
|
|
40
|
my $keys = $under_tie->{'header'}; |
105
|
22
|
100
|
|
|
|
58
|
if ($under_tie->{'lc'}) |
106
|
|
|
|
|
|
|
{ |
107
|
2
|
|
|
|
|
3
|
$keys = [ map { lc($_) } @{ $keys } ]; |
|
6
|
|
|
|
|
15
|
|
|
2
|
|
|
|
|
3
|
|
108
|
|
|
|
|
|
|
} |
109
|
22
|
|
|
|
|
44
|
my $data = $under_tie->{data}; |
110
|
22
|
|
|
|
|
26
|
@{ $data }{ @{ $keys } } = @{ $values }; |
|
22
|
|
|
|
|
121
|
|
|
22
|
|
|
|
|
36
|
|
|
22
|
|
|
|
|
34
|
|
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
1; |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
__END__ |