File Coverage

blib/lib/PDF/TableX/Row.pm
Criterion Covered Total %
statement 53 53 100.0
branch 6 8 75.0
condition n/a
subroutine 14 14 100.0
pod 8 8 100.0
total 81 83 97.5


line stmt bran cond sub pod time code
1             package PDF::TableX::Row;
2              
3 7     7   62 use Moose;
  7         14  
  7         93  
4 7     7   51978 use MooseX::Types;
  7         19  
  7         66  
5              
6             with 'PDF::TableX::Drawable';
7             with 'PDF::TableX::Stylable';
8              
9 7     7   33892 use PDF::TableX::Cell;
  7         29  
  7         68  
10              
11             has cols => (is => 'ro', isa => 'Int', default => 0);
12             has width => (is => 'rw', isa => 'Num');
13             has height => (is => 'rw', isa => 'Num');
14              
15             has _row_idx => (is => 'ro', isa => 'Int', default => 0);
16             has _parent => (is => 'ro', isa => 'Object');
17              
18 7     7   3874 use overload '@{}' => sub { return $_[0]->{_children} }, fallback => 1;
  7     260   16  
  7         86  
  260         986  
19              
20             around 'height' => sub {
21             my $orig = shift;
22             my $self = shift;
23             return $self->$orig() unless @_;
24             for (@{ $self->{_children} }) { $_->height(@_) };
25             $self->$orig(@_);
26             return $self;
27             };
28              
29              
30             sub BUILD {
31 34     34 1 272791 my ($self) = @_;
32 34         154 $self->_create_children;
33             }
34              
35             sub _create_children {
36 34     34   90 my ($self) = @_;
37 34         1141 for (0..$self->cols-1) {
38             $self->add_cell( PDF::TableX::Cell->new(
39             width => ($self->width/$self->cols),
40             _row_idx => $self->{_row_idx},
41 146         4157 _col_idx => $_,
42             _parent => $self,
43             $self->properties,
44             ));
45             }
46             }
47              
48             sub add_cell {
49 146     146 1 1309571 my ($self, $cell) = @_;
50 146         297 push @{$self->{_children}}, $cell;
  146         1144  
51             }
52              
53             sub properties {
54 146     146 1 379 my ($self, @attrs) = @_;
55 146 50       723 @attrs = scalar(@attrs) ? @attrs : $self->attributes;
56 146         5287 return ( map { $_ => $self->$_ } @attrs );
  1460         5039  
57             }
58              
59             sub draw_content {
60 40     40 1 156 my ($self, $x, $y, $gfx, $txt) = @_;
61 40         101 my $height = 0;
62 40         94 my $overflow = 0;
63 40         86 for (@{$self->{_children}}) {
  40         173  
64 158         693 my ($w, $h, $o) = $_->draw_content( $x, $y, $gfx, $txt );
65 158 100       596 $height = ($height > $h) ? $height : $h;
66 158 50       4004 $x += ($w > $_->width ? $w : $_->width);
67 158         541 $overflow += $o;
68             }
69 40 100       192 if (! $overflow ) { for (@{$self->{_children}}) { $_->reset_content } }
  37         88  
  37         282  
  152         442  
70 40         301 return ($height, $overflow);
71             }
72              
73             sub draw_borders {
74 40     40 1 148 my ($self, $x, $y, $gfx, $txt) = @_;
75 40         87 for (@{$self->{_children}}) {
  40         167  
76 158         599 $_->draw_borders( $x, $y, $gfx, $txt );
77 158         11184 $x += $_->width;
78             }
79             }
80              
81             sub draw_background {
82 40     40 1 174 my ($self, $x, $y, $gfx, $txt) = @_;
83 40         101 for (@{$self->{_children}}) {
  40         156  
84 158         569 $_->draw_background( $x, $y, $gfx, $txt );
85 158         9147 $x += $_->width;
86             }
87             }
88              
89             sub is_last_in_row {
90 136     136 1 315 my ($self, $idx) = @_;
91 136         3478 return ($idx == $self->cols-1); #index starts from 0
92             }
93              
94             sub is_last_in_col {
95 152     152 1 294 my ($self, $idx) = @_;
96 152         718 return $self->{_parent}->is_last_in_col($idx);
97             }
98              
99             1;
100              
101             =head1 NAME
102              
103             PDF::TableX::Row
104              
105             =head1 VERSION
106              
107             Version 0.01
108              
109             =head1 SYNOPSIS
110              
111             =head1 METHODS
112              
113             =head2 BUILD
114              
115             TODO
116              
117             =head2 add_cell
118              
119             TODO
120              
121             =head2 draw_background
122              
123             TODO
124              
125             =head2 draw_borders
126              
127             TODO
128              
129             =head2 draw_content
130              
131             TODO
132              
133             =head2 is_last_in_col
134              
135             TODO
136              
137             =head2 is_last_in_row
138              
139             TODO
140              
141             =head2 properties
142              
143             TODO
144              
145             =head1 AUTHOR
146              
147             Grzegorz Papkala, C<< <grzegorzpapkala at gmail.com> >>
148              
149             =head1 BUGS
150              
151             Please report any bugs or feature requests at: L<https://github.com/grzegorzpapkala/PDF-TableX/issues>
152              
153             =head1 SUPPORT
154              
155             PDF::TableX is hosted on GitHub L<https://github.com/grzegorzpapkala/PDF-TableX>
156              
157             =head1 ACKNOWLEDGEMENTS
158              
159             =head1 COPYRIGHT & LICENSE
160              
161             Copyright 2013 Grzegorz Papkala, all rights reserved.
162              
163             This program is free software; you can redistribute it and/or modify it
164             under the same terms as Perl itself.
165              
166             =cut