| 1 | package Data::TableReader::Decoder::Mock; | ||||||||||||||||||||
| 2 | 7 | ▶ | use Moo 2; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | 7 | ▶ | use Carp 'croak'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 7 | ▶ | use IO::Handle; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 7 | ▶ | require MRO::Compat if $] < '5.010'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 7 | extends 'Data::TableReader::Decoder'; | |||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | # ABSTRACT: Decoder that returns supplied data without decoding anything | ||||||||||||||||||||
| 10 | 7 | our $VERSION = '0.023'; # VERSION | |||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | 40 | ▶ | sub BUILDARGS { | ||||||||||||||||||
|
Subroutine
BUILDARGS: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||
| 14 | 40 | my $args= $_[0]->next::method(@_[1..$#_]); | |||||||||||||||||||
| 15 | # back-compat with earlier versions | ||||||||||||||||||||
| 16 | 40 | ▶ | $args->{datasets}= delete $args->{data} if defined $args->{data}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 17 | # allow simple way for user to specify a single table | ||||||||||||||||||||
| 18 | 40 | ▶ | $args->{datasets}= [ delete $args->{table} ] if defined $args->{table}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 19 | 40 | $args; | |||||||||||||||||||
| 20 | } | ||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | 7 | has datasets => ( is => 'rw', isa => \&_arrayref_3_deep ); | |||||||||||||||||||
| 23 | 7 | *data= *datasets; | |||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | 40 | ▶ | sub _arrayref_3_deep { | ||||||||||||||||||
|
Subroutine
_arrayref_3_deep: called CC=8 SCAR=21.4
| |||||||||||||||||||||
| 26 | 40 | ▶ | ref $_[0] eq 'ARRAY' or return 'Not an arrayref'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 27 | 40 | ▶ | return undef unless @{$_[0]}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 28 | 39 | ▶ | ref $_[0][0] eq 'ARRAY' or return 'Not an arrayref of tables'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 29 | 39 | ▶ | return undef unless @{$_[0][0]}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 30 | 38 | ▶ | ref $_[0][0][0] eq 'ARRAY' or return 'Not an arrayref of tables of rows'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 31 | 38 | ▶ | return undef unless @{$_[0][0][0]}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 32 | 38 | ▶ | ref $_[0][0][0][0] ne 'ARRAY' | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 33 | or return 'Expected plain cell value at ->[$dataset][$table][$cell] depth of arrayrefs'; | ||||||||||||||||||||
| 34 | 38 | undef; | |||||||||||||||||||
| 35 | } | ||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | 44 | ▶ | sub iterator { | ||||||||||||||||||
|
Subroutine
iterator: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 38 | 44 | my $self= shift; | |||||||||||||||||||
| 39 | 44 | my $data= $self->datasets; | |||||||||||||||||||
| 40 | 44 | my $table= $data->[0]; | |||||||||||||||||||
| 41 | 44 | ▶ | my $rowmax= $table? $#$table : -1; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 42 | 44 | my $row= -1; | |||||||||||||||||||
| 43 | Data::TableReader::Decoder::Mock::_Iter->new( | ||||||||||||||||||||
| 44 | 161 | ▶ | sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||
| 45 | 161 | my $slice= shift; | |||||||||||||||||||
| 46 | 161 | ▶ | return undef unless $row < $rowmax; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 47 | 126 | my $datarow= $table->[++$row]; | |||||||||||||||||||
| 48 | 126 | ▶ | return [ @{$datarow}[@$slice] ] if $slice; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 49 | 52 | return $datarow; | |||||||||||||||||||
| 50 | }, | ||||||||||||||||||||
| 51 | { | ||||||||||||||||||||
| 52 | 44 | data => $data, | |||||||||||||||||||
| 53 | table_idx => 0, | ||||||||||||||||||||
| 54 | table_ref => \$table, | ||||||||||||||||||||
| 55 | row_ref => \$row, | ||||||||||||||||||||
| 56 | rowmax_ref => \$rowmax, | ||||||||||||||||||||
| 57 | origin => [ 0, $row ], | ||||||||||||||||||||
| 58 | } | ||||||||||||||||||||
| 59 | ); | ||||||||||||||||||||
| 60 | } | ||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | # If you need to subclass this iterator, don't. Just implement your own. | ||||||||||||||||||||
| 63 | # i.e. I'm not declaring this implementation stable, yet. | ||||||||||||||||||||
| 64 | 7 | ▶ | use Data::TableReader::Iterator; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 65 | 7 | ▶ | BEGIN { @Data::TableReader::Decoder::Mock::_Iter::ISA= ('Data::TableReader::Iterator'); } | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | 55 | ▶ | sub Data::TableReader::Decoder::Mock::_Iter::position { | ||||||||||||||||||
|
Subroutine
position: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 68 | 55 | my $f= shift->_fields; | |||||||||||||||||||
| 69 | 55 | 'row '.(1 + ${ $f->{row_ref} }); | |||||||||||||||||||
| 70 | } | ||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | 30 | ▶ | sub Data::TableReader::Decoder::Mock::_Iter::row { | ||||||||||||||||||
|
Subroutine
row: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 73 | 30 | 1 + ${ shift->_fields->{row_ref} }; | |||||||||||||||||||
| 74 | } | ||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | 9 | ▶ | sub Data::TableReader::Decoder::Mock::_Iter::dataset_idx { | ||||||||||||||||||
|
Subroutine
dataset_idx: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 77 | shift->_fields->{table_idx} | ||||||||||||||||||||
| 78 | 9 | } | |||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | 0 | ▶ | sub Data::TableReader::Decoder::Mock::_Iter::progress { | ||||||||||||||||||
|
Subroutine
progress: not called CC=2 SCAR=17.9
| |||||||||||||||||||||
| 81 | 0 | my $f= shift->_fields; | |||||||||||||||||||
| 82 | 0 | ▶ | return ${ $f->{row_ref} } / (${ $f->{rowmax_ref} } || 1); | ||||||||||||||||||
|
Condition0%0/2
${$f->{'rowmax_ref'};} || 1
MC/DC0%0/1
${$f->{'rowmax_ref'};} || 1
${$f->{'rowmax_ref'};}
Truth table0%0/2
A
A= ${$f->{'rowmax_ref'};}
| |||||||||||||||||||||
| 83 | } | ||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | 51 | ▶ | sub Data::TableReader::Decoder::Mock::_Iter::tell { | ||||||||||||||||||
|
Subroutine
tell: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 86 | 51 | my $f= shift->_fields; | |||||||||||||||||||
| 87 | 51 | return [ $f->{table_idx}, ${$f->{row_ref}} ]; | |||||||||||||||||||
| 88 | } | ||||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | 9 | ▶ | sub Data::TableReader::Decoder::Mock::_Iter::seek { | ||||||||||||||||||
|
Subroutine
seek: called CC=4 SCAR=13.9
| |||||||||||||||||||||
| 91 | 9 | my ($self, $to)= @_; | |||||||||||||||||||
| 92 | 9 | my $f= $self->_fields; | |||||||||||||||||||
| 93 | 9 | ▶ | $to ||= $f->{origin}; | ||||||||||||||||||
|
Condition66%2/3
$to ||= $f->{"origin"}
MC/DC0%0/2
$to ||= $f->{"origin"}
$to
$f->{"origin"}
Truth table66%2/3
A ||= B
A= $toB= $f->{"origin"}
| |||||||||||||||||||||
| 94 | 9 | my ($table_idx, $row)= @$to; | |||||||||||||||||||
| 95 | 9 | my $table= $f->{data}[$table_idx]; | |||||||||||||||||||
| 96 | 9 | ▶ | my $rowmax= $table? $#$table : -1; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 97 | 9 | ▶ | $row= -1 unless defined $row; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 98 | 9 | $f->{table_idx}= $table_idx; | |||||||||||||||||||
| 99 | 9 | ${$f->{table_ref}}= $table; | |||||||||||||||||||
| 100 | 9 | ${$f->{row_ref}}= $row; | |||||||||||||||||||
| 101 | 9 | ${$f->{rowmax_ref}}= $rowmax; | |||||||||||||||||||
| 102 | 9 | 1; | |||||||||||||||||||
| 103 | } | ||||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | 8 | ▶ | sub Data::TableReader::Decoder::Mock::_Iter::next_dataset { | ||||||||||||||||||
|
Subroutine
next_dataset: called CC=2 SCAR=7.0
| |||||||||||||||||||||
| 106 | 8 | my $self= shift; | |||||||||||||||||||
| 107 | 8 | my $f= $self->_fields; | |||||||||||||||||||
| 108 | return defined $f->{data}[ $f->{table_idx}+1 ] | ||||||||||||||||||||
| 109 | 8 | ▶ | && $self->seek([ $f->{table_idx}+1 ]); | ||||||||||||||||||
|
Condition66%2/3
defined $f->{'data'}[$f->{'table_idx'} + 1] && $self->seek([$f->{'table_idx'} + 1])
MC/DC50%1/2
defined $f->{'data'}[$f->{'table_idx'} + 1] && $self->seek([$f->{'table_idx'} + 1])
defined $f->{'data'}[$f->{'table_idx'} + 1]
$self->seek([$f->{'table_idx'} + 1])
Truth table66%2/3
A && B
A= defined $f->{'data'}[$f->{'table_idx'} + 1]B= $self->seek([$f->{'table_idx'} + 1])
| |||||||||||||||||||||
| 110 | } | ||||||||||||||||||||
| 111 | |||||||||||||||||||||
| 112 | 7 | 1; | |||||||||||||||||||
| 113 | |||||||||||||||||||||
| 114 | __END__ | ||||||||||||||||||||