File Coverage

blib/lib/PDF/TableX/Row.pm
Criterion Covered Total %
statement 1 3 33.3
branch n/a
condition n/a
subroutine 1 1 100.0
pod n/a
total 2 4 50.0


line stmt bran cond sub pod time code
1             package PDF::TableX::Row;
2              
3 1     1   1134 use Moose;
  0            
  0            
4             use MooseX::Types;
5              
6             with 'PDF::TableX::Drawable';
7             with 'PDF::TableX::Stylable';
8              
9             use PDF::TableX::Cell;
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             use overload '@{}' => sub { return $_[0]->{_children} }, fallback => 1;
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             my ($self) = @_;
32             $self->_create_children;
33             }
34              
35             sub _create_children {
36             my ($self) = @_;
37             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             _col_idx => $_,
42             _parent => $self,
43             $self->properties,
44             ));
45             }
46             }
47              
48             sub add_cell {
49             my ($self, $cell) = @_;
50             push @{$self->{_children}}, $cell;
51             }
52              
53             sub properties {
54             my ($self, @attrs) = @_;
55             @attrs = scalar(@attrs) ? @attrs : $self->attributes;
56             return ( map { $_ => $self->$_ } @attrs );
57             }
58              
59             sub draw_content {
60             my ($self, $x, $y, $gfx, $txt) = @_;
61             my $height = 0;
62             my $overflow = 0;
63             for (@{$self->{_children}}) {
64             my ($w, $h, $o) = $_->draw_content( $x, $y, $gfx, $txt );
65             $height = ($height > $h) ? $height : $h;
66             $x += ($w > $_->width ? $w : $_->width);
67             $overflow += $o;
68             }
69             if (! $overflow ) { for (@{$self->{_children}}) { $_->reset_content } }
70             return ($height, $overflow);
71             }
72              
73             sub draw_borders {
74             my ($self, $x, $y, $gfx, $txt) = @_;
75             for (@{$self->{_children}}) {
76             $_->draw_borders( $x, $y, $gfx, $txt );
77             $x += $_->width;
78             }
79             }
80              
81             sub draw_background {
82             my ($self, $x, $y, $gfx, $txt) = @_;
83             for (@{$self->{_children}}) {
84             $_->draw_background( $x, $y, $gfx, $txt );
85             $x += $_->width;
86             }
87             }
88              
89             sub is_last_in_row {
90             my ($self, $idx) = @_;
91             return ($idx == $self->cols-1); #index starts from 0
92             }
93              
94             sub is_last_in_col {
95             my ($self, $idx) = @_;
96             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