line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package TableDataRole::Munge::Concat; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
497
|
use 5.010001; |
|
1
|
|
|
|
|
4
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
20
|
|
5
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
24
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
5
|
use Role::Tiny; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
4
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY |
10
|
|
|
|
|
|
|
our $DATE = '2023-06-14'; # DATE |
11
|
|
|
|
|
|
|
our $DIST = 'TableDataRoles-Standard'; # DIST |
12
|
|
|
|
|
|
|
our $VERSION = '0.016'; # VERSION |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
with 'TableDataRole::Spec::Basic'; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub new { |
17
|
1
|
|
|
1
|
1
|
128
|
my ($class, %args) = @_; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
my $tabledatalist = delete $args{tabledatalist} |
20
|
1
|
50
|
|
|
|
6
|
or die "Please supply 'tabledatalist' argument"; |
21
|
1
|
|
50
|
|
|
7
|
my $load = delete($args{load}) // 1; |
22
|
1
|
50
|
|
|
|
4
|
die "Please supply at least one tabledata in tabledatalist" |
23
|
|
|
|
|
|
|
unless @$tabledatalist; |
24
|
1
|
50
|
|
|
|
5
|
die "Unknown argument(s): ". join(", ", sort keys %args) |
25
|
|
|
|
|
|
|
if keys %args; |
26
|
|
|
|
|
|
|
|
27
|
1
|
|
|
|
|
7
|
bless { |
28
|
|
|
|
|
|
|
tabledatalist => [@$tabledatalist], |
29
|
|
|
|
|
|
|
load => $load, |
30
|
|
|
|
|
|
|
td_pos => 0, # which tabledata are we at |
31
|
|
|
|
|
|
|
pos => 0, # iterator |
32
|
|
|
|
|
|
|
}, $class; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# to lazily instantiate tabledata |
36
|
|
|
|
|
|
|
sub _tabledatalist { |
37
|
35
|
|
|
35
|
|
660
|
require Module::Load::Util; |
38
|
|
|
|
|
|
|
|
39
|
35
|
|
|
|
|
1680
|
my ($self, $idx) = @_; |
40
|
35
|
|
|
|
|
65
|
my $td = $self->{tabledatalist}[$idx]; |
41
|
35
|
100
|
|
|
|
105
|
unless (ref $td) { |
42
|
|
|
|
|
|
|
$td = Module::Load::Util::instantiate_class_with_optional_args( |
43
|
2
|
|
|
|
|
13
|
{load=>$self->{load}, ns_prefix=>"TableData"}, $td); |
44
|
2
|
|
|
|
|
21
|
$self->{tabledatalist}[$idx] = $td; |
45
|
|
|
|
|
|
|
} |
46
|
35
|
|
|
|
|
81
|
$td; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub get_column_count { |
50
|
1
|
|
|
1
|
0
|
7
|
my $self = shift; |
51
|
|
|
|
|
|
|
|
52
|
1
|
|
|
|
|
5
|
$self->_tabledatalist(0)->get_column_count; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub get_column_names { |
56
|
4
|
|
|
4
|
0
|
9
|
my $self = shift; |
57
|
4
|
|
|
|
|
12
|
$self->_tabledatalist(0)->get_column_names; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub has_next_item { |
61
|
11
|
|
|
11
|
0
|
55
|
my $self = shift; |
62
|
11
|
|
|
|
|
20
|
while (1) { |
63
|
12
|
|
|
|
|
29
|
my $td = $self->_tabledatalist($self->{td_pos}); |
64
|
12
|
100
|
|
|
|
28
|
return 1 if $td->has_next_item; |
65
|
2
|
100
|
|
|
|
10
|
return 0 if $self->{td_pos} >= $#{$self->{tabledatalist}}; |
|
2
|
|
|
|
|
17
|
|
66
|
1
|
|
|
|
|
2
|
$self->{td_pos}++; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub get_next_item { |
71
|
17
|
|
|
17
|
0
|
58
|
my $self = shift; |
72
|
17
|
|
|
|
|
25
|
while (1) { |
73
|
18
|
|
|
|
|
38
|
my $td = $self->_tabledatalist($self->{td_pos}); |
74
|
18
|
100
|
|
|
|
43
|
do { $self->{pos}++; return $td->get_next_item } if $td->has_next_item; |
|
17
|
|
|
|
|
28
|
|
|
17
|
|
|
|
|
52
|
|
75
|
1
|
50
|
|
|
|
31
|
die "StopIteration" if $self->{td_pos} >= $#{$self->{tabledatalist}}; |
|
1
|
|
|
|
|
9
|
|
76
|
1
|
|
|
|
|
2
|
$self->{td_pos}++; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub get_next_row_hashref { |
81
|
3
|
|
|
3
|
0
|
10
|
my $self = shift; |
82
|
3
|
|
|
|
|
7
|
my $row = $self->get_next_item; |
83
|
3
|
|
|
|
|
8
|
my $columns = $self->get_column_names; # cache? |
84
|
3
|
|
|
|
|
7
|
+{ map {($columns->[$_] => $row->[$_])} 0..$#{$columns} }; |
|
9
|
|
|
|
|
44
|
|
|
3
|
|
|
|
|
10
|
|
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub get_iterator_pos { |
88
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
89
|
0
|
|
|
|
|
0
|
$self->{pos}; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub reset_iterator { |
93
|
3
|
|
|
3
|
0
|
19
|
my $self = shift; |
94
|
3
|
100
|
|
|
|
6
|
for (@{ $self->{tabledatalist} }) { $_->reset_iterator if ref $_ } |
|
3
|
|
|
|
|
9
|
|
|
6
|
|
|
|
|
24
|
|
95
|
3
|
|
|
|
|
9
|
$self->{td_pos} = 0; |
96
|
3
|
|
|
|
|
13
|
$self->{pos} = 0; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
1; |
100
|
|
|
|
|
|
|
# ABSTRACT: Role to access a series of other tabledata instances |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
__END__ |