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