lib/PDF/FromHTML/Template/Container/Section.pm untested

filter: Statementstmt 0.0% 0 / 39 Branchbran 0.0% 0 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 64 CC 7 SCAR 29.8
CC
7
Cov
0%
should_render
42.0
render
6.0
BEGIN
2.0
CRAP 19.7
1 package PDF::FromHTML::Template::Container::Section;
2  
3 use strict;
4  
5 BEGIN {
6 use vars qw(@ISA);
7 @ISA = qw(PDF::FromHTML::Template::Container);
8  
9 use PDF::FromHTML::Template::Container;
10 }
11  
12 # Sections are used to keep text together and not allow page-breaking
13 # within this branch of the tree, if possible.
14  
15 sub new
16 {
17 my $class = shift;
18 my $self = $class->SUPER::new(@_);
19  
20 $self->{__CHECK_FOR_SPACE__} = 1;
21  
22 return $self;
23 }
24  
25 sub reset
26 {
27 my $self = shift;
28  
29 $self->{__CHECK_FOR_SPACE__} = 1;
30  
31 return $self->SUPER::reset;
32 }
33  
34 sub render
35 {
36 my $self = shift;
37 my ($context) = @_;
38  
39 return 0 unless $self->should_render($context);
40  
41 my $child_success = $self->iterate_over_children($context);
42  
43 $self->{__CHECK_FOR_SPACE__} = $child_success;
44  
45 return $child_success;
46 }
47  
48 sub should_render
49 {
50 my $self = shift;
51 my ($context) = @_;
52  
53 return 0 if $context->pagebreak_tripped;
54  
55 unless ($self->{__CHECK_FOR_SPACE__})
56 {
57 $self->{__CHECK_FOR_SPACE__} = 1;
58 return 1;
59 }
60  
61 my $y_shift = $self->total_of($context, 'H');
62 my $end_y = $context->get($self, 'END_Y');
63  
64 if ($context->{Y} - $y_shift < $end_y)
65 {
66 my $start_y = $context->get($self, 'START_Y');
67  
68 $self->{__CHECK_FOR_SPACE__} = 0 if $y_shift > ($start_y - $end_y);
69  
70 return 1 if $context->{Y} == $start_y;
71  
72 $context->trip_pagebreak;
73 return 0;
74 }
75  
76 return 1;
77 }
78  
79 1;
80 __END__