File Coverage

blib/lib/Term/Table/CellStack.pm
Criterion Covered Total %
statement 49 55 89.0
branch 2 2 100.0
condition 1 2 50.0
subroutine 14 16 87.5
pod 0 8 0.0
total 66 83 79.5


line stmt bran cond sub pod time code
1             package Term::Table::CellStack;
2 1     1   91835 use strict;
  1         2  
  1         54  
3 1     1   6 use warnings;
  1         3  
  1         68  
4              
5             our $VERSION = '0.028';
6              
7 1     1   7 use Term::Table::HashBase qw/-cells -idx/;
  1         2  
  1         10  
8              
9 1     1   36 use List::Util qw/max/;
  1         3  
  1         376  
10              
11             sub init {
12 2     2 0 6 my $self = shift;
13 2   50     11 $self->{+CELLS} ||= [];
14             }
15              
16             sub add_cell {
17 0     0 0 0 my $self = shift;
18 0         0 push @{$self->{+CELLS}} => @_;
  0         0  
19             }
20              
21             sub add_cells {
22 0     0 0 0 my $self = shift;
23 0         0 push @{$self->{+CELLS}} => @_;
  0         0  
24             }
25              
26             sub sanitize {
27 2     2 0 5 my $self = shift;
28 2         20 $_->sanitize(@_) for @{$self->{+CELLS}};
  2         13  
29             }
30              
31             sub mark_tail {
32 2     2 0 3 my $self = shift;
33 2         5 $_->mark_tail(@_) for @{$self->{+CELLS}};
  2         8  
34             }
35              
36             my @proxy = qw{
37             border_left border_right border_color value_color reset_color
38             border_left_width border_right_width
39             };
40              
41             for my $meth (@proxy) {
42 1     1   8 no strict 'refs';
  1         3  
  1         124  
43             *$meth = sub {
44 105     105   175 my $self = shift;
45 105         316 $self->{+CELLS}->[$self->{+IDX}]->$meth;
46             };
47             }
48              
49             for my $meth (qw{value_width width}) {
50 1     1   8 no strict 'refs';
  1         3  
  1         431  
51             *$meth = sub {
52 2     2   5 my $self = shift;
53 2         4 return max(map { $_->$meth } @{$self->{+CELLS}});
  6         79  
  2         6  
54             };
55             }
56              
57             sub next {
58 38     38 0 62 my $self = shift;
59 38         68 my ($cw) = @_;
60              
61 38         70 while ($self->{+IDX} < @{$self->{+CELLS}}) {
  44         120  
62 27         67 my $cell = $self->{+CELLS}->[$self->{+IDX}];
63              
64 27         82 my $lw = $cell->border_left_width;
65 27         182 my $rw = $cell->border_right_width;
66 27         134 my $vw = $cw - $lw - $rw;
67 27         71 my $it = $cell->break->next($vw);
68              
69 27 100       118 return ($it, $vw) if $it;
70 6         17 $self->{+IDX}++;
71             }
72              
73 17         99 return;
74             }
75              
76 38     38 0 102 sub break { $_[0] }
77              
78             sub reset {
79 2     2 0 4 my $self = shift;
80 2         5 $self->{+IDX} = 0;
81 2         3 $_->reset for @{$self->{+CELLS}};
  2         8  
82             }
83              
84             1;
85              
86             __END__