File Coverage

lib/PDF/Boxer/Content/Grid.pm
Criterion Covered Total %
statement 6 61 9.8
branch 0 20 0.0
condition 0 5 0.0
subroutine 2 6 33.3
pod 0 4 0.0
total 8 96 8.3


line stmt bran cond sub pod time code
1             package PDF::Boxer::Content::Grid;
2             {
3             $PDF::Boxer::Content::Grid::VERSION = '0.001'; # TRIAL
4             }
5 3     3   19 use Moose;
  3         7  
  3         36  
6             # ABSTRACT: a box of rows with column widths aligned
7              
8 3     3   18752 use namespace::autoclean;
  3         6  
  3         29  
9              
10             extends 'PDF::Boxer::Content::Column';
11              
12             sub update_children{
13 0     0 0   my ($self) = @_;
14 0 0         $self->update_kids_size if $self->size_set;
15 0 0         $self->update_kids_position if $self->position_set;
16 0           $self->update_grand_kids;
17 0           foreach my $kid (@{$self->children}){
  0            
18 0           $kid->update;
19             }
20 0           return 1;
21             }
22              
23             sub update_kids_position{
24 0     0 0   my ($self) = @_;
25 0           my $kids = $self->children;
26 0 0         if (@$kids){
27 0           my $top = $self->content_top;
28 0           my $left = $self->content_left;
29 0           foreach my $kid (@$kids){
30 0           $kid->move($left, $top);
31 0           $top -= $kid->margin_height;
32             }
33             }
34 0           return 1;
35             }
36              
37             sub update_kids_size{
38 0     0 0   my ($self) = @_;
39              
40 0           my ($width, $height) = $self->get_default_size;
41              
42 0           my $kids = $self->children;
43              
44 0 0         if (@$kids){
45              
46 0           my $space = $self->height - $height;
47 0           my ($has_grow,$grow,$grow_all);
48 0           my ($space_each);
49 0 0         if ($space < $height/10){
50 0           foreach my $kid (@$kids){
51 0 0         $has_grow++ if $kid->grow;
52             }
53 0 0         if (!$has_grow){
54 0           $grow_all = 1;
55 0           $has_grow = @$kids;
56             }
57 0           $space_each = int($space/$has_grow);
58             }
59              
60 0           my $kwidth = $self->content_width;
61              
62 0           foreach my $kid (@$kids){
63 0           my $kheight = $kid->margin_height;
64 0 0 0       if ($grow_all || $kid->grow){
65 0           $kheight += $space_each;
66             }
67 0           $kid->set_margin_size($kwidth, $kheight);
68             }
69              
70             }
71              
72 0           return 1;
73             }
74              
75             sub update_grand_kids{
76 0     0 0   my ($self) = @_;
77              
78 0           my ($width, $height) = $self->get_default_size;
79              
80 0           my $kids = $self->children;
81              
82 0 0         if (@$kids){
83             # calculate minumum widths of cells (kids)
84 0           my @row_highs;
85 0           foreach my $row (@$kids){
86 0           my @cells;
87 0           foreach my $cell (@{$row->children}){
  0            
88 0           push(@cells, $cell->margin_width);
89             }
90 0           my $idx = 0;
91 0           foreach my $val (@cells){
92 0 0 0       $row_highs[$idx] = $val if $val > ($row_highs[$idx] || 0);
93 0           $idx++;
94             }
95             }
96              
97 0           foreach (@$kids){
98 0           $_->set_kids_minimum_width({ min_widths => \@row_highs });
99             }
100             }
101              
102 0           return 1;
103             }
104              
105              
106              
107             __PACKAGE__->meta->make_immutable;
108              
109             1;
110              
111              
112             __END__
113             =pod
114              
115             =head1 NAME
116              
117             PDF::Boxer::Content::Grid - a box of rows with column widths aligned
118              
119             =head1 VERSION
120              
121             version 0.001
122              
123             =head1 AUTHOR
124              
125             Jason Galea <lecstor@cpan.org>
126              
127             =head1 COPYRIGHT AND LICENSE
128              
129             This software is copyright (c) 2011 by Jason Galea.
130              
131             This is free software; you can redistribute it and/or modify it under
132             the same terms as the Perl 5 programming language system itself.
133              
134             =cut
135