line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package TableDataRole::Munge::Concat; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
447
|
use 5.010001; |
|
1
|
|
|
|
|
3
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
22
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
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-02-24'; # DATE |
11
|
|
|
|
|
|
|
our $DIST = 'TableDataRoles-Standard'; # DIST |
12
|
|
|
|
|
|
|
our $VERSION = '0.015'; # VERSION |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
with 'TableDataRole::Spec::Basic'; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub new { |
17
|
1
|
|
|
1
|
1
|
113
|
my ($class, %args) = @_; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
my $tabledatalist = delete $args{tabledatalist} |
20
|
1
|
50
|
|
|
|
6
|
or die "Please supply 'tabledatalist' argument"; |
21
|
1
|
50
|
|
|
|
7
|
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
|
|
|
|
|
8
|
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
|
|
640
|
require Module::Load::Util; |
36
|
|
|
|
|
|
|
|
37
|
35
|
|
|
|
|
1615
|
my ($self, $idx) = @_; |
38
|
35
|
|
|
|
|
70
|
my $td = $self->{tabledatalist}[$idx]; |
39
|
35
|
100
|
|
|
|
79
|
unless (ref $td) { |
40
|
2
|
|
|
|
|
11
|
$td = Module::Load::Util::instantiate_class_with_optional_args( |
41
|
|
|
|
|
|
|
{ns_prefix=>"TableData"}, $td); |
42
|
2
|
|
|
|
|
25
|
$self->{tabledatalist}[$idx] = $td; |
43
|
|
|
|
|
|
|
} |
44
|
35
|
|
|
|
|
74
|
$td; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub get_column_count { |
48
|
1
|
|
|
1
|
0
|
5
|
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
|
49
|
my $self = shift; |
60
|
11
|
|
|
|
|
15
|
while (1) { |
61
|
12
|
|
|
|
|
26
|
my $td = $self->_tabledatalist($self->{td_pos}); |
62
|
12
|
100
|
|
|
|
31
|
return 1 if $td->has_next_item; |
63
|
2
|
100
|
|
|
|
17
|
return 0 if $self->{td_pos} >= $#{$self->{tabledatalist}}; |
|
2
|
|
|
|
|
15
|
|
64
|
1
|
|
|
|
|
2
|
$self->{td_pos}++; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub get_next_item { |
69
|
17
|
|
|
17
|
0
|
60
|
my $self = shift; |
70
|
17
|
|
|
|
|
22
|
while (1) { |
71
|
18
|
|
|
|
|
36
|
my $td = $self->_tabledatalist($self->{td_pos}); |
72
|
18
|
100
|
|
|
|
41
|
do { $self->{pos}++; return $td->get_next_item } if $td->has_next_item; |
|
17
|
|
|
|
|
30
|
|
|
17
|
|
|
|
|
52
|
|
73
|
1
|
50
|
|
|
|
32
|
die "StopIteration" if $self->{td_pos} >= $#{$self->{tabledatalist}}; |
|
1
|
|
|
|
|
21
|
|
74
|
1
|
|
|
|
|
5
|
$self->{td_pos}++; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub get_next_row_hashref { |
79
|
3
|
|
|
3
|
0
|
11
|
my $self = shift; |
80
|
3
|
|
|
|
|
6
|
my $row = $self->get_next_item; |
81
|
3
|
|
|
|
|
8
|
my $columns = $self->get_column_names; # cache? |
82
|
3
|
|
|
|
|
10
|
+{ map {($columns->[$_] => $row->[$_])} 0..$#{$columns} }; |
|
9
|
|
|
|
|
77
|
|
|
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
|
23
|
my $self = shift; |
92
|
3
|
100
|
|
|
|
6
|
for (@{ $self->{tabledatalist} }) { $_->reset_iterator if ref $_ } |
|
3
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
22
|
|
93
|
3
|
|
|
|
|
7
|
$self->{td_pos} = 0; |
94
|
3
|
|
|
|
|
7
|
$self->{pos} = 0; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
1; |
98
|
|
|
|
|
|
|
# ABSTRACT: Role to access a series of other tabledata instances |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
__END__ |