| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package TableData::Object::hash; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $DATE = '2019-09-15'; # DATE |
|
4
|
|
|
|
|
|
|
our $VERSION = '0.111'; # VERSION |
|
5
|
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
17
|
use 5.010001; |
|
|
1
|
|
|
|
|
3
|
|
|
7
|
1
|
|
|
1
|
|
4
|
use strict; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
18
|
|
|
8
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
26
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
347
|
use parent 'TableData::Object::Base'; |
|
|
1
|
|
|
|
|
253
|
|
|
|
1
|
|
|
|
|
4
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
|
13
|
17
|
|
|
17
|
1
|
33
|
my ($class, $data) = @_; |
|
14
|
|
|
|
|
|
|
|
|
15
|
17
|
|
|
|
|
87
|
bless { |
|
16
|
|
|
|
|
|
|
data => $data, |
|
17
|
|
|
|
|
|
|
cols_by_name => {key=>0, value=>1}, |
|
18
|
|
|
|
|
|
|
cols_by_idx => ["key", "value"], |
|
19
|
|
|
|
|
|
|
}, $class; |
|
20
|
|
|
|
|
|
|
} |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub row_count { |
|
23
|
1
|
|
|
1
|
1
|
2
|
my $self = shift; |
|
24
|
1
|
|
|
|
|
2
|
scalar keys %{ $self->{data} }; |
|
|
1
|
|
|
|
|
6
|
|
|
25
|
|
|
|
|
|
|
} |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub rows { |
|
28
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
|
29
|
0
|
|
|
|
|
0
|
my $data = $self->{data}; |
|
30
|
0
|
|
|
|
|
0
|
[sort keys %$data]; |
|
31
|
|
|
|
|
|
|
} |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub rows_as_aoaos { |
|
34
|
1
|
|
|
1
|
1
|
611
|
my $self = shift; |
|
35
|
1
|
|
|
|
|
3
|
my $data = $self->{data}; |
|
36
|
1
|
|
|
|
|
5
|
[map {[$_, $data->{$_}]} sort keys %$data]; |
|
|
3
|
|
|
|
|
11
|
|
|
37
|
|
|
|
|
|
|
} |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub rows_as_aohos { |
|
40
|
7
|
|
|
7
|
1
|
585
|
my $self = shift; |
|
41
|
7
|
|
|
|
|
13
|
my $data = $self->{data}; |
|
42
|
7
|
|
|
|
|
25
|
[map {{key=>$_, value=>$data->{$_}}} sort keys %$data]; |
|
|
21
|
|
|
|
|
77
|
|
|
43
|
|
|
|
|
|
|
} |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub uniq_col_names { |
|
46
|
6
|
|
|
6
|
1
|
11
|
my $self = shift; |
|
47
|
|
|
|
|
|
|
|
|
48
|
6
|
|
|
|
|
11
|
my @res = ('key'); # by definition, hash key is unique |
|
49
|
6
|
|
|
|
|
8
|
my %mem; |
|
50
|
6
|
|
|
|
|
7
|
for (values %{$self->{data}}) { |
|
|
6
|
|
|
|
|
17
|
|
|
51
|
7
|
100
|
|
|
|
20
|
return @res unless defined; |
|
52
|
5
|
100
|
|
|
|
18
|
return @res if $mem{$_}++; |
|
53
|
|
|
|
|
|
|
} |
|
54
|
3
|
|
|
|
|
5
|
push @res, 'value'; |
|
55
|
3
|
|
|
|
|
15
|
@res; |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub const_col_names { |
|
59
|
6
|
|
|
6
|
1
|
10
|
my $self = shift; |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# by definition, hash key is not constant |
|
62
|
6
|
|
|
|
|
8
|
my $i = -1; |
|
63
|
6
|
|
|
|
|
8
|
my $val; |
|
64
|
|
|
|
|
|
|
my $val_undef; |
|
65
|
6
|
|
|
|
|
8
|
for (values %{$self->{data}}) { |
|
|
6
|
|
|
|
|
16
|
|
|
66
|
8
|
|
|
|
|
9
|
$i++; |
|
67
|
8
|
100
|
|
|
|
55
|
if ($i == 0) { |
|
68
|
5
|
|
|
|
|
5
|
$val = $_; |
|
69
|
5
|
100
|
|
|
|
12
|
$val_undef = 1 unless defined $val; |
|
70
|
|
|
|
|
|
|
} else { |
|
71
|
3
|
50
|
|
|
|
6
|
if ($val_undef) { |
|
72
|
0
|
0
|
|
|
|
0
|
return () if defined; |
|
73
|
|
|
|
|
|
|
} else { |
|
74
|
3
|
100
|
|
|
|
9
|
return () unless defined; |
|
75
|
2
|
100
|
|
|
|
9
|
return () unless $val eq $_; |
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
} |
|
79
|
4
|
|
|
|
|
16
|
('value'); |
|
80
|
|
|
|
|
|
|
} |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub switch_cols { |
|
83
|
4
|
|
|
4
|
1
|
923
|
die "Cannot switch column in hash table"; |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub add_col { |
|
87
|
0
|
|
|
0
|
1
|
0
|
die "Cannot add_col in hash table"; |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub set_col_val { |
|
91
|
3
|
|
|
3
|
0
|
835
|
my ($self, $name_or_idx, $value_sub) = @_; |
|
92
|
|
|
|
|
|
|
|
|
93
|
3
|
|
|
|
|
18
|
my $col_name = $self->col_name($name_or_idx); |
|
94
|
3
|
|
|
|
|
8
|
my $col_idx = $self->col_idx($name_or_idx); |
|
95
|
|
|
|
|
|
|
|
|
96
|
3
|
100
|
|
|
|
17
|
die "Column '$name_or_idx' does not exist" unless defined $col_name; |
|
97
|
|
|
|
|
|
|
|
|
98
|
2
|
|
|
|
|
3
|
my $hash = $self->{data}; |
|
99
|
2
|
100
|
|
|
|
6
|
if ($col_name eq 'key') { |
|
100
|
1
|
|
|
|
|
3
|
my $row_idx = -1; |
|
101
|
1
|
|
|
|
|
5
|
for my $key (sort keys %$hash) { |
|
102
|
3
|
|
|
|
|
5
|
$row_idx++; |
|
103
|
|
|
|
|
|
|
my $new_key = $value_sub->( |
|
104
|
|
|
|
|
|
|
table => $self, |
|
105
|
|
|
|
|
|
|
row_idx => $row_idx, |
|
106
|
|
|
|
|
|
|
row_name => $key, |
|
107
|
|
|
|
|
|
|
col_name => $col_name, |
|
108
|
|
|
|
|
|
|
col_idx => $col_idx, |
|
109
|
3
|
|
|
|
|
6
|
value => $hash->{$key}, |
|
110
|
|
|
|
|
|
|
); |
|
111
|
3
|
50
|
|
|
|
28
|
$hash->{$new_key} = delete $hash->{$key} |
|
112
|
|
|
|
|
|
|
unless $key eq $new_key; |
|
113
|
|
|
|
|
|
|
} |
|
114
|
|
|
|
|
|
|
} else { |
|
115
|
1
|
|
|
|
|
2
|
my $row_idx = -1; |
|
116
|
1
|
|
|
|
|
6
|
for my $key (sort keys %$hash) { |
|
117
|
3
|
|
|
|
|
6
|
$row_idx++; |
|
118
|
|
|
|
|
|
|
$hash->{$key} = $value_sub->( |
|
119
|
|
|
|
|
|
|
table => $self, |
|
120
|
|
|
|
|
|
|
row_idx => $row_idx, |
|
121
|
|
|
|
|
|
|
row_name => $key, |
|
122
|
|
|
|
|
|
|
col_name => $col_name, |
|
123
|
|
|
|
|
|
|
col_idx => $col_idx, |
|
124
|
3
|
|
|
|
|
7
|
value => $hash->{$key}, |
|
125
|
|
|
|
|
|
|
); |
|
126
|
|
|
|
|
|
|
} |
|
127
|
|
|
|
|
|
|
} |
|
128
|
|
|
|
|
|
|
} |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
1; |
|
131
|
|
|
|
|
|
|
# ABSTRACT: Manipulate hash via table object |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
__END__ |