File Coverage

blib/lib/Khonsu/Page/Header.pm
Criterion Covered Total %
statement 23 24 95.8
branch 6 10 60.0
condition 1 2 50.0
subroutine 6 6 100.0
pod 0 4 0.0
total 36 46 78.2


line stmt bran cond sub pod time code
1             package Khonsu::Page::Header;
2              
3 5     5   37 use parent 'Khonsu::Text';
  5         10  
  5         42  
4              
5             sub attributes {
6 8     8 0 27 my ($a) = shift;
7             return (
8             $a->SUPER::attributes(),
9 8     8   23 active => {$a->RW, $a->BOOL, default => sub { 1 }},
10 8         41 show_page_num => {$a->RW, $a->STR},
11             page_num_text => {$a->RW, $a->STR},
12             padding => {$a->RW, $a->NUM},
13             cb => {$a->RW, $a->CODE},
14             );
15             }
16              
17             sub render {
18 89     89 0 271 my ($self, $file) = @_;
19 89 100       374 return unless $self->active;
20 86         451 my $y = ($self->h / 2) - ($self->font->size / 2);
21 86 50       449 my $w = $file->page->w - ($self->padding ? ( $self->padding * 2 ) : $self->padding);
22 86   50     500 my $x = $self->padding || 0;
23              
24 86 50       484 if ($self->show_page_num) {
25 86         339 $self->add(
26             $file,
27             text => $self->process_page_num_text($file),
28             y => $y,
29             w => $w,
30             x => $x,
31             align => $self->show_page_num
32             );
33             }
34              
35 86 50       552 $self->cb->(
36             $self,
37             $file,
38             y => $y,
39             w => $w,
40             x => $x,
41             ) if ($self->cb);
42             }
43              
44             sub process_page_num_text {
45 172     172 0 335 my ($self, $file) = @_;
46 172 50       727 if ($self->page_num_text) {
47 172         641 my $num = $file->page->num;
48 172         787 (my $text = $self->page_num_text) =~ s/\{num\}/$num/g;
49 172         1227 return $text;
50             }
51 0         0 return $file->page->num;
52             }
53              
54             sub clone {
55 170     170 0 382 my ($self) = @_;
56 170         577 $self = $self->SUPER::clone();
57 170         1153 $self->active(1);
58 170         869 return $self;
59             }
60              
61             =pod
62             show_page_num => 'right',
63             page_num_text => 'page {num]',
64             h => 20,
65             cb => sub {
66             my ($self, %atts) = @_;
67             $self->add_text(
68             text => 'Khonsu',
69             align => 'center',
70             %attrs,
71             );
72             }
73             =cut
74              
75             1;