TableX/Row.pm

filter: Statementstmt 100% 70 / 70 Branchbran 70.0% 7 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 15 / 15 Podpod 100% 8 / 8 totaltotal 97.0% 100 / 103 CC 12 SCAR 9.9
CC
12
Cov
96%
draw_content
6.0
__ANON__
3.0
properties
2.0
CRAP 2.7
« TableX/Cell.pm ↑ Summary TableX/Column.pm »
1 package PDF::TableX::Row;
2  
3 8 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶use MooseX::Types;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 8 with 'PDF::TableX::Drawable';
7 8 with 'PDF::TableX::Stylable';
8  
9 8 ▶use PDF::TableX::Cell;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 8 has cols => (is => 'ro', isa => 'Int', default => 0);
12 8 has width => (is => 'rw', isa => 'Num');
13 8 has height => (is => 'rw', isa => 'Num');
14  
15 8 has _row_idx => (is => 'ro', isa => 'Int', default => 0);
16 8 has _parent => (is => 'ro', isa => 'Object');
17  
18 8 ▶use overload '@{}' => sub { return $_[0]->{_children} }, fallback => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
19  
20 40 ▶around 'height' => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
21 40 my $orig = shift;
22 40 my $self = shift;
23 40 ▶ return $self->$orig() unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 40 40
24 40 for (@{ $self->{_children} }) { $_->height(@_) };
25 40 $self->$orig(@_);
26 40 return $self;
27 8 };
28  
29  
30 34 ▶sub BUILD {
Subroutine BUILD: called CC=1 SCAR=0.0
Pod documented
31 34 my ($self) = @_;
32 34 $self->_create_children;
33 }
34  
35 34 ▶sub _create_children {
Subroutine _create_children: called CC=2 SCAR=6.9
36 34 my ($self) = @_;
37 34 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 _col_idx => $_,
42 _parent => $self,
43 $self->properties,
44 ));
45 }
46 }
47  
48 146 ▶sub add_cell {
Subroutine add_cell: called CC=1 SCAR=0.0
Pod documented
49 146 my ($self, $cell) = @_;
50 146 push @{$self->{_children}}, $cell;
51 }
52  
53 146 ▶sub properties {
Subroutine properties: called CC=2 SCAR=7.0
Pod documented
54 146 my ($self, @attrs) = @_;
55 146 ▶ @attrs = scalar(@attrs) ? @attrs : $self->attributes;
Branch: 1 branch
BranchTrueFalseTotal
scalar @attrs ? : 0 146 146
56 146 return ( map { $_ => $self->$_ } @attrs );
57 }
58  
59 40 ▶sub draw_content {
Subroutine draw_content: called CC=6 SCAR=17.9
Pod documented
60 40 my ($self, $x, $y, $gfx, $txt) = @_;
61 40 my $height = 0;
62 40 my $overflow = 0;
63 40 for (@{$self->{_children}}) {
64 158 my ($w, $h, $o) = $_->draw_content( $x, $y, $gfx, $txt );
65 158 ▶ $height = ($height > $h) ? $height : $h;
Branch: 1 branch
BranchTrueFalseTotal
$height > $h ? : 2 156 158
66 158 ▶ $x += ($w > $_->width ? $w : $_->width);
Branch: 1 branch
BranchTrueFalseTotal
$w > $_->width ? : 0 158 158
67 158 $overflow += $o;
68 }
69 40 ▶ if (! $overflow ) { for (@{$self->{_children}}) { $_->reset_content } }
Branch: 1 branch
BranchTrueFalseTotal
unless ($overflow) 37 3 40
70 40 return ($height, $overflow);
71 }
72  
73 40 ▶sub draw_borders {
Subroutine draw_borders: called CC=2 SCAR=6.9
Pod documented
74 40 my ($self, $x, $y, $gfx, $txt) = @_;
75 40 for (@{$self->{_children}}) {
76 158 $_->draw_borders( $x, $y, $gfx, $txt );
77 158 $x += $_->width;
78 }
79 }
80  
81 40 ▶sub draw_background {
Subroutine draw_background: called CC=2 SCAR=6.9
Pod documented
82 40 my ($self, $x, $y, $gfx, $txt) = @_;
83 40 for (@{$self->{_children}}) {
84 158 $_->draw_background( $x, $y, $gfx, $txt );
85 158 $x += $_->width;
86 }
87 }
88  
89 136 ▶sub is_last_in_row {
Subroutine is_last_in_row: called CC=1 SCAR=0.0
Pod documented
90 136 my ($self, $idx) = @_;
91 136 return ($idx == $self->cols-1); #index starts from 0
92 }
93  
94 152 ▶sub is_last_in_col {
Subroutine is_last_in_col: called CC=1 SCAR=0.0
Pod documented
95 152 my ($self, $idx) = @_;
96 152 return $self->{_parent}->is_last_in_col($idx);
97 }
98  
99 8 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
« TableX/Cell.pm ↑ Summary TableX/Column.pm »