File Coverage

blib/lib/TableData/Test/Spec/Basic.pm
Criterion Covered Total %
statement 32 36 88.8
branch 5 8 62.5
condition n/a
subroutine 11 13 84.6
pod 0 9 0.0
total 48 66 72.7


line stmt bran cond sub pod time code
1             package TableData::Test::Spec::Basic;
2              
3 2     2   553472 use strict;
  2         5  
  2         121  
4 2     2   14 use warnings;
  2         4  
  2         161  
5              
6 2     2   1302 use Role::Tiny::With;
  2         17136  
  2         1364  
7              
8             with 'TableDataRole::Spec::Basic';
9              
10             our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
11             our $DATE = '2023-11-25'; # DATE
12             our $DIST = 'TableData'; # DIST
13             our $VERSION = '0.2.6'; # VERSION
14              
15             my $rows = [
16             {a=>1, b=>2},
17             {a=>3, b=>4},
18             {a=>"5 2", b=>"6,2"},
19             ];
20             my $columns = [qw/a b/];
21              
22             sub new {
23 1     1 0 373633 my $class = shift;
24 1         5 bless {pos=>0}, $class;
25             }
26              
27             sub _rows {
28 0     0   0 $rows;
29             }
30              
31             sub reset_iterator {
32 9     9 0 11242 my $self = shift;
33 9         23 $self->{pos} = 0;
34             }
35              
36             sub get_iterator_pos {
37 1     1 0 4 my $self = shift;
38 1         4 $self->{pos};
39             }
40              
41             sub has_next_item {
42 32     32 0 1324 my $self = shift;
43 32         91 $self->{pos} < @$rows;
44             }
45              
46             sub get_next_item {
47 18     18 0 42 my $self = shift;
48 18 50       38 die "StopIteration" if $self->{pos} >= @$rows;
49 18         29 my $row_hashref = $rows->[ $self->{pos}++ ];
50 18         31 [map {$row_hashref->{$_}} @$columns];
  36         88  
51             }
52              
53             sub get_next_row_hashref {
54 8     8 0 52 my $self = shift;
55 8 100       32 die "StopIteration" if $self->{pos} >= @$rows;
56 7         20 $rows->[ $self->{pos}++ ];
57             }
58              
59             sub get_row_hashref {
60 0     0 0 0 my $self = shift;
61 0 0       0 return unless $rows->[ $self->{index} ];
62 0         0 $rows->[ $self->{index}++ ];
63             }
64              
65             sub get_column_count {
66 1     1 0 8021 my $self = shift;
67 1         3 scalar(keys %{$rows->[0]});
  1         8  
68             }
69              
70             sub get_column_names {
71 4     4 0 4586 my $self = shift;
72 4         7 my @names = sort keys %{$rows->[0]};
  4         27  
73 4 100       29 wantarray ? @names : \@names;
74             }
75              
76             1;
77              
78             # ABSTRACT: A test table data
79              
80             __END__