lib/Video/PlaybackMachine/FillProducer/TextFrame/TextTable.pm untested

filter: Statementstmt 0.0% 0 / 39 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 55 CC 2 SCAR 11.0
CC
2
Cov
0%
add_row
6.0
get_start_ycoord
2.0
get_start_xcoord
2.0
CRAP 3.0
1 package Video::PlaybackMachine::FillProducer::TextFrame::TextTable;
2  
3 our $VERSION = '0.09'; # VERSION
4  
5 use Video::PlaybackMachine::FillProducer::TextFrame::Row;
6  
7 use Moo;
8  
9 has 'image' => ( 'is' => 'ro' );
10  
11 has 'border' => ( 'is' => 'ro' );
12  
13 has 'rows' => ( 'is' => 'ro', default => sub { return [] } );
14  
15 has 'height' => ( 'is' => 'rw', 'default' => 0 );
16  
17 has 'width' => ( 'is' => 'rw', 'default' => 0 );
18  
19 sub add_row {
20 my $self = shift;
21 my (@columns) = @_;
22  
23 my $row =
24 Video::PlaybackMachine::FillProducer::TextFrame::Row->new(
25 $self->image(),
26 $self->border(),
27 @columns);
28
29 # Return undef if we're too long (vertically) for the screen
30 my $new_height = $self->height() + $row->get_height() + $self->border();
31 $new_height > $self->image()->get_height()
32 and return;
33 $self->height( $new_height );
34  
35 # Update maximum width
36 $self->width( $row->get_width() )
37 if $row->get_width() > $self->width();
38  
39 # Store the row
40 push(@{ $self->rows() }, $row);
41  
42 return 1;
43 }
44  
45 sub get_start_ycoord {
46 my $self = shift;
47  
48 return int(($self->image()->get_height() - $self->height()) / 2);
49 }
50  
51 sub get_start_xcoord {
52 my $self = shift;
53  
54 return int(($self->image()->get_width() - $self->width()) / 2);
55  
56 }
57  
58 sub draw {
59 my $self = shift;
60  
61 my $x = $self->get_start_xcoord();
62 my $y = $self->get_start_ycoord();
63 foreach my $row (@{ $self->rows() }) {
64 $row->draw($x, $y);
65 $y += $row->get_height();
66 }
67 }
68  
69 no Moo;
70  
71 1;