| 1 | package TableDataRole::Munge::Concat; | ||||||||||||
| 2 | |||||||||||||
| 3 | 3 | ▶ | use 5.010001; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 3 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 3 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | |||||||||||||
| 7 | 3 | ▶ | use Role::Tiny; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | |||||||||||||
| 9 | 3 | our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY | |||||||||||
| 10 | 3 | our $DATE = '2024-05-14'; # DATE | |||||||||||
| 11 | 3 | our $DIST = 'TableDataRoles-Standard'; # DIST | |||||||||||
| 12 | 3 | our $VERSION = '0.025'; # VERSION | |||||||||||
| 13 | |||||||||||||
| 14 | 3 | with 'TableDataRole::Spec::Basic'; | |||||||||||
| 15 | |||||||||||||
| 16 | 1 | ▶ | sub new { | ||||||||||
|
Subroutine
new: called CC=5 SCAR=17.2
Pod
documented
| |||||||||||||
| 17 | 1 | my ($class, %args) = @_; | |||||||||||
| 18 | |||||||||||||
| 19 | my $tabledatalist = delete $args{tabledatalist} | ||||||||||||
| 20 | 1 | ▶ | or die "Please supply 'tabledatalist' argument"; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 21 | 1 | ▶ | my $load = delete($args{load}) // 1; | ||||||||||
|
Condition50%1/2
delete $args{"load"} // 1
MC/DC0%0/1
delete $args{"load"} // 1
delete $args{"load"}
Truth table50%1/2
A
A= delete $args{"load"}
| |||||||||||||
| 22 | 1 | ▶ | die "Please supply at least one tabledata in tabledatalist" | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 23 | unless @$tabledatalist; | ||||||||||||
| 24 | 1 | ▶ | die "Unknown argument(s): ". join(", ", sort keys %args) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 25 | if keys %args; | ||||||||||||
| 26 | |||||||||||||
| 27 | 1 | 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 | 35 | ▶ | sub _tabledatalist { | ||||||||||
|
Subroutine
_tabledatalist: called CC=2 SCAR=6.9
| |||||||||||||
| 37 | 35 | require Module::Load::Util; | |||||||||||
| 38 | |||||||||||||
| 39 | 35 | my ($self, $idx) = @_; | |||||||||||
| 40 | 35 | my $td = $self->{tabledatalist}[$idx]; | |||||||||||
| 41 | 35 | ▶ | unless (ref $td) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 42 | $td = Module::Load::Util::instantiate_class_with_optional_args( | ||||||||||||
| 43 | 2 | {load=>$self->{load}, ns_prefix=>"TableData"}, $td); | |||||||||||
| 44 | 2 | $self->{tabledatalist}[$idx] = $td; | |||||||||||
| 45 | } | ||||||||||||
| 46 | 35 | $td; | |||||||||||
| 47 | } | ||||||||||||
| 48 | |||||||||||||
| 49 | 1 | ▶ | sub get_column_count { | ||||||||||
|
Subroutine
get_column_count: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 50 | 1 | my $self = shift; | |||||||||||
| 51 | |||||||||||||
| 52 | 1 | $self->_tabledatalist(0)->get_column_count; | |||||||||||
| 53 | } | ||||||||||||
| 54 | |||||||||||||
| 55 | 4 | ▶ | sub get_column_names { | ||||||||||
|
Subroutine
get_column_names: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 56 | 4 | my $self = shift; | |||||||||||
| 57 | 4 | $self->_tabledatalist(0)->get_column_names; | |||||||||||
| 58 | } | ||||||||||||
| 59 | |||||||||||||
| 60 | 11 | ▶ | sub has_next_item { | ||||||||||
|
Subroutine
has_next_item: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||
| 61 | 11 | my $self = shift; | |||||||||||
| 62 | 11 | while (1) { | |||||||||||
| 63 | 12 | my $td = $self->_tabledatalist($self->{td_pos}); | |||||||||||
| 64 | 12 | ▶ | return 1 if $td->has_next_item; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 65 | 2 | ▶ | return 0 if $self->{td_pos} >= $#{$self->{tabledatalist}}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 66 | 1 | $self->{td_pos}++; | |||||||||||
| 67 | } | ||||||||||||
| 68 | } | ||||||||||||
| 69 | |||||||||||||
| 70 | 17 | ▶ | sub get_next_item { | ||||||||||
|
Subroutine
get_next_item: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||
| 71 | 17 | my $self = shift; | |||||||||||
| 72 | 17 | while (1) { | |||||||||||
| 73 | 18 | my $td = $self->_tabledatalist($self->{td_pos}); | |||||||||||
| 74 | 18 | ▶ | do { $self->{pos}++; return $td->get_next_item } if $td->has_next_item; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 75 | 1 | ▶ | die "StopIteration" if $self->{td_pos} >= $#{$self->{tabledatalist}}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 76 | 1 | $self->{td_pos}++; | |||||||||||
| 77 | } | ||||||||||||
| 78 | } | ||||||||||||
| 79 | |||||||||||||
| 80 | 3 | ▶ | sub get_next_row_hashref { | ||||||||||
|
Subroutine
get_next_row_hashref: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 81 | 3 | my $self = shift; | |||||||||||
| 82 | 3 | my $row = $self->get_next_item; | |||||||||||
| 83 | 3 | my $columns = $self->get_column_names; # cache? | |||||||||||
| 84 | 3 | +{ map {($columns->[$_] => $row->[$_])} 0..$#{$columns} }; | |||||||||||
| 85 | } | ||||||||||||
| 86 | |||||||||||||
| 87 | 0 | ▶ | sub get_iterator_pos { | ||||||||||
|
Subroutine
get_iterator_pos: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 88 | 0 | my $self = shift; | |||||||||||
| 89 | 0 | $self->{pos}; | |||||||||||
| 90 | } | ||||||||||||
| 91 | |||||||||||||
| 92 | 3 | ▶ | sub reset_iterator { | ||||||||||
|
Subroutine
reset_iterator: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||
| 93 | 3 | my $self = shift; | |||||||||||
| 94 | 3 | ▶ | for (@{ $self->{tabledatalist} }) { $_->reset_iterator if ref $_ } | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 95 | 3 | $self->{td_pos} = 0; | |||||||||||
| 96 | 3 | $self->{pos} = 0; | |||||||||||
| 97 | } | ||||||||||||
| 98 | |||||||||||||
| 99 | 3 | 1; | |||||||||||
| 100 | # ABSTRACT: Role to access a series of other tabledata instances | ||||||||||||
| 101 | |||||||||||||
| 102 | __END__ | ||||||||||||