| 1 | package TableDataRole::Source::AOA; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 10 | ▶ | use 5.010001; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 10 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 10 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 10 | ▶ | use Role::Tiny; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 10 | our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY | |||||||||||||||||||||||||||||||||||||||||||||
| 10 | 10 | our $DATE = '2024-05-14'; # DATE | |||||||||||||||||||||||||||||||||||||||||||||
| 11 | 10 | our $DIST = 'TableDataRoles-Standard'; # DIST | |||||||||||||||||||||||||||||||||||||||||||||
| 12 | 10 | our $VERSION = '0.025'; # VERSION | |||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 10 | with 'TableDataRole::Spec::Basic'; | |||||||||||||||||||||||||||||||||||||||||||||
| 15 | 10 | with 'TableDataRole::Spec::GetRowByPos'; | |||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 2 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=14.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 2 | my ($class, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 2 | ▶ | my $column_names = delete $args{column_names} or die "Please specify 'column_names' argument"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 2 | ▶ | my $aoa = delete $args{aoa} or die "Please specify 'aoa' argument"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 2 | ▶ | die "Unknown argument(s): ". join(", ", sort keys %args) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 23 | if keys %args; | ||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||
| 25 | bless { | ||||||||||||||||||||||||||||||||||||||||||||||
| 26 | aoa => $aoa, | ||||||||||||||||||||||||||||||||||||||||||||||
| 27 | pos => 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 28 | column_names => $column_names, | ||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 2 | column_idxs => {map {$column_names->[$_] => $_} 0..$#{$column_names}}, | |||||||||||||||||||||||||||||||||||||||||||||
| 30 | }, $class; | ||||||||||||||||||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 3 | ▶ | sub get_column_count { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_column_count: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 35 | 3 | scalar @{ $self->{column_names} }; | |||||||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 3 | ▶ | sub get_column_names { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_column_names: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 40 | 3 | ▶ | wantarray ? @{ $self->{column_names} } : $self->{column_names}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 57 | ▶ | sub has_next_item { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
has_next_item: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 57 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 45 | 57 | $self->{pos} < @{$self->{aoa}}; | |||||||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 62 | ▶ | sub get_next_item { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_next_item: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 62 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 50 | 62 | my $aoa = $self->{aoa}; | |||||||||||||||||||||||||||||||||||||||||||||
| 51 | 62 | ▶ | die "StopIteration" unless $self->{pos} < @{$aoa}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 62 | $aoa->[ $self->{pos}++ ]; | |||||||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 4 | ▶ | sub get_next_row_hashref { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_next_row_hashref: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 57 | 4 | my $row_aryref = $self->get_next_item; | |||||||||||||||||||||||||||||||||||||||||||||
| 58 | 4 | +{ map { $self->{column_names}[$_] => $row_aryref->[$_] } 0..$#{$self->{column_names}} }; | |||||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 2 | ▶ | sub get_row_count { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_row_count: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 63 | 2 | scalar(@{ $self->{aoa} }); | |||||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 6 | ▶ | sub reset_iterator { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
reset_iterator: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 6 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 68 | 6 | $self->{pos} = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | sub get_iterator_pos { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_iterator_pos: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | $self->{pos}; | |||||||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 3 | ▶ | sub get_item_at_pos { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_item_at_pos: called CC=5 SCAR=20.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 3 | my ($self, $index) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||
| 79 | die "OutOfBounds" if | ||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | ▶ | $index < 0 && -$index > @{ $self->{aoa} } || | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$index >= 0 and $index >= @{$self->{"aoa"};}
MC/DC0%0/2
$index >= 0 and $index >= @{$self->{"aoa"};}
$index >= 0
$index >= @{$self->{"aoa"};}
Truth table33%1/3
A and B
A= $index >= 0B= $index >= @{$self->{"aoa"};}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 3 | ▶ | $index >= 0 && $index >= @{ $self->{aoa} }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$index < 0 and -$index > @{$self->{"aoa"};} or $index >= 0 and $index >= @{$self->{"aoa"};}
$index < 0 and -$index > @{$self->{"aoa"};}
MC/DC0%0/3
$index < 0 and -$index > @{$self->{"aoa"};} or $index >= 0 and $index >= @{$self->{"aoa"};}
$index < 0
-$index > @{$self->{"aoa"};}
$index >= 0 and $index >= @{$self->{"aoa"};}
Truth table20%1/5
A and B or C
A= $index < 0B= -$index > @{$self->{"aoa"};}C= $index >= 0 and $index >= @{$self->{"aoa"};}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 3 | $self->{aoa}->[$index]; | |||||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | sub get_row_at_pos_hashref { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_row_at_pos_hashref: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | my ($self, $index) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | my $row_aryref = $self->get_item_at_pos($index); | |||||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | +{ map { $self->{column_names}[$_] => $row_aryref->[$_] } 0..$#{$self->{column_names}} }; | |||||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | sub has_item_at_pos { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
has_item_at_pos: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | my ($self, $index) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||
| 94 | return 0 if | ||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | ▶ | $index < 0 && -$index > @{ $self->{aoa} } || | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$index >= 0 and $index >= @{$self->{"aoa"};}
MC/DC0%0/2
$index >= 0 and $index >= @{$self->{"aoa"};}
$index >= 0
$index >= @{$self->{"aoa"};}
Truth table0%0/3
A and B
A= $index >= 0B= $index >= @{$self->{"aoa"};}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | $index >= 0 && $index >= @{ $self->{aoa} }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$index < 0 and -$index > @{$self->{"aoa"};} or $index >= 0 and $index >= @{$self->{"aoa"};}
$index < 0 and -$index > @{$self->{"aoa"};}
MC/DC0%0/3
$index < 0 and -$index > @{$self->{"aoa"};} or $index >= 0 and $index >= @{$self->{"aoa"};}
$index < 0
-$index > @{$self->{"aoa"};}
$index >= 0 and $index >= @{$self->{"aoa"};}
Truth table0%0/5
A and B or C
A= $index < 0B= -$index > @{$self->{"aoa"};}C= $index >= 0 and $index >= @{$self->{"aoa"};}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 10 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 101 | # ABSTRACT: Get table data from an array of arrays | ||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||
| 103 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||