lib/PDF/Boxer/Content/Grid.pm

filter: Statementstmt 13.7% 14 / 102 Branchbran 0.0% 0 / 36 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 28.5% 2 / 7 Podpod 0.0% 0 / 4 totaltotal 10.1% 16 / 157 CC 33 SCAR 46.0
CC
33
Cov
10%
__ANON__
182.0
update_kids_size
90.0
update_grand_kids
72.0
CRAP 99.2
↑ Summary lib/PDF/Boxer/Content/Box.pm »
1 package PDF::Boxer::Content::Grid;
2 {
3 3 $PDF::Boxer::Content::Grid::VERSION = '0.004';
4 }
5 3 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 # ABSTRACT: a box of rows with column widths aligned
7  
8 3 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 3 extends 'PDF::Boxer::Content::Column';
11  
12 3 has 'hborder' => ( isa => 'Int', is => 'rw', default => 0 );
13 3 has 'vborder' => ( isa => 'Int', is => 'rw', default => 0 );
14  
15 0 ▶around 'render' => sub {
Subroutine __ANON__: not called CC=13 SCAR=52.0
16 0 my ($orig, $self) = @_;
17  
18 0 my $kids = $self->children;
19 0 ▶ return unless @$kids;
Branch: 1 branch
BranchTrueFalseTotal
unless @$kids 0 0 0
20  
21 0 my $gfx = $self->boxer->doc->gfx;
22  
23 0 ▶ if ($self->hborder) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->hborder) 0 0 0
24 0 my @hlines;
25 0 my $top_pos = $kids->[0]->padding_top;
26 0 foreach my $kid (@$kids) {
27 0 ▶ next if $top_pos == $kid->padding_top;
Branch: 1 branch
BranchTrueFalseTotal
if $top_pos == $kid->padding_top 0 0 0
28 0 $top_pos = $kid->padding_top;
29 0 push @hlines, $top_pos;
30 }
31  
32 0 ▶ if (@hlines) {
Branch: 1 branch
BranchTrueFalseTotal
if (@hlines) 0 0 0
33 0 $gfx->linewidth($self->hborder);
34 0 for my $top (@hlines) {
35 0 $gfx->move($self->content_left, $top);
36 0 $gfx->line($self->content_right, $top);
37 0 $gfx->stroke;
38 }
39 }
40 }
41  
42 0 ▶ if ($self->vborder) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->vborder) 0 0 0
43 0 my @vlines;
44 0 my $grand_kids = $kids->[0]->children;
45 0 ▶ if (@$grand_kids) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$grand_kids) 0 0 0
46 0 my $left_pos = $grand_kids->[0]->padding_left;
47 0 foreach my $grand_kid (@$grand_kids) {
48 0 ▶ next if $left_pos == $grand_kid->padding_left;
Branch: 1 branch
BranchTrueFalseTotal
if $left_pos == $grand_kid->padding_left 0 0 0
49 0 $left_pos = $grand_kid->padding_left;
50 0 push @vlines, $left_pos;
51 }
52  
53 0 ▶ if (@vlines) {
Branch: 1 branch
BranchTrueFalseTotal
if (@vlines) 0 0 0
54 0 $gfx->linewidth($self->vborder);
55 0 for my $left (@vlines) {
56 0 $gfx->move($left, $self->content_top);
57 0 $gfx->line($left, $self->content_bottom);
58 0 $gfx->stroke;
59 }
60 }
61 }
62  
63 }
64  
65 0 $self->$orig();
66 3 };
67  
68 0 ▶sub update_children{
Subroutine update_children: not called CC=4 SCAR=30.0
Pod undocumented
69 0 my ($self) = @_;
70 0 ▶ $self->update_kids_size if $self->size_set;
Branch: 1 branch
BranchTrueFalseTotal
if $self->size_set 0 0 0
71 0 ▶ $self->update_kids_position if $self->position_set;
Branch: 1 branch
BranchTrueFalseTotal
if $self->position_set 0 0 0
72 0 $self->update_grand_kids;
73 0 foreach my $kid (@{$self->children}){
74 0 $kid->update;
75 }
76 0 return 1;
77 }
78  
79 0 ▶sub update_kids_position{
Subroutine update_kids_position: not called CC=3 SCAR=24.8
Pod undocumented
80 0 my ($self) = @_;
81 0 my $kids = $self->children;
82 0 ▶ if (@$kids){
Branch: 1 branch
BranchTrueFalseTotal
if (@$kids) 0 0 0
83 0 my $top = $self->content_top;
84 0 my $left = $self->content_left;
85 0 foreach my $kid (@$kids){
86 0 $kid->move($left, $top);
87 0 $top -= $kid->margin_height;
88 }
89 }
90 0 return 1;
91 }
92  
93 0 ▶sub update_kids_size{
Subroutine update_kids_size: not called CC=9 SCAR=45.0
Pod undocumented
94 0 my ($self) = @_;
95  
96 0 my ($width, $height) = $self->get_default_size;
97  
98 0 my $kids = $self->children;
99  
100 0 ▶ if (@$kids){
Branch: 1 branch
BranchTrueFalseTotal
if (@$kids) 0 0 0
101  
102 0 my $space = $self->height - $height;
103 0 my ($has_grow,$grow,$grow_all);
104 0 my ($space_each);
105 0 ▶ if ($space < $height/10){
Branch: 1 branch
BranchTrueFalseTotal
if ($space < $height / 10) 0 0 0
106 0 foreach my $kid (@$kids){
107 0 ▶ $has_grow++ if $kid->grow;
Branch: 1 branch
BranchTrueFalseTotal
if $kid->grow 0 0 0
108 }
109 0 ▶ if (!$has_grow){
Branch: 1 branch
BranchTrueFalseTotal
unless ($has_grow) 0 0 0
110 0 $grow_all = 1;
111 0 $has_grow = @$kids;
112 }
113 0 $space_each = int($space/$has_grow);
114 }
115  
116 0 my $kwidth = $self->content_width;
117  
118 0 foreach my $kid (@$kids){
119 0 my $kheight = $kid->margin_height;
120 0 ▶ if ($grow_all || $kid->grow){
Branch: 1 branch
BranchTrueFalseTotal
if ($grow_all or $kid->grow) 0 0 0
Condition0%0/3
$grow_all or $kid->grow
l!l&&r!l&&!r
000
MC/DC0%0/2
$grow_all or $kid->grow
$grow_all $kid->grow
Truth table0%0/3
A or B
A= $grow_allB= $kid->grow
ABresult
1X1
011
000
121 0 $kheight += $space_each;
122 }
123 0 $kid->set_margin_size($kwidth, $kheight);
124 }
125  
126 }
127  
128 0 return 1;
129 }
130  
131 0 ▶sub update_grand_kids{
Subroutine update_grand_kids: not called CC=8 SCAR=42.8
Pod undocumented
132 0 my ($self) = @_;
133  
134 0 my ($width, $height) = $self->get_default_size;
135  
136 0 my $kids = $self->children;
137  
138 0 ▶ if (@$kids){
Branch: 1 branch
BranchTrueFalseTotal
if (@$kids) 0 0 0
139 # calculate minumum widths of cells (kids)
140 0 my @row_highs;
141 0 foreach my $row (@$kids){
142 0 my @cells;
143 0 foreach my $cell (@{$row->children}){
144 0 push(@cells, $cell->margin_width);
145 }
146 0 my $idx = 0;
147 0 foreach my $val (@cells){
148 0 ▶ $row_highs[$idx] = $val if $val > ($row_highs[$idx] || 0);
Branch: 1 branch
BranchTrueFalseTotal
if $val > ($row_highs[$idx] || 0) 0 0 0
Condition0%0/2
$row_highs[$idx] || 0
l!l
00
MC/DC0%0/1
$row_highs[$idx] || 0
$row_highs[$idx]
Truth table0%0/2
A
A= $row_highs[$idx]
Aresult
11
00
149 0 $idx++;
150 }
151 }
152  
153 0 foreach (@$kids){
154 0 $_->set_kids_minimum_width({ min_widths => \@row_highs });
155 }
156 }
157  
158 0 return 1;
159 }
160  
161  
162  
163 3 __PACKAGE__->meta->make_immutable;
164  
165 3 1;
166  
167  
168 __END__
↑ Summary lib/PDF/Boxer/Content/Box.pm »