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   40 use parent 'Khonsu::Text';
  5         13  
  5         37  
4              
5             sub attributes {
6 8     8 0 20 my ($a) = shift;
7             return (
8             $a->SUPER::attributes(),
9 8     8   21 active => {$a->RW, $a->BOOL, default => sub { 1 }},
10 8         47 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 128     128 0 381 my ($self, $file) = @_;
19 128 100       866 return unless $self->active;
20 125         729 my $y = ($self->h / 2) - ($self->font->size / 2);
21 125 50       825 my $w = $file->page->w - ($self->padding ? ( $self->padding * 2 ) : $self->padding);
22 125   50     741 my $x = $self->padding || 0;
23              
24 125 50       684 if ($self->show_page_num) {
25 125         672 $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 125 50       1181 $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 250     250 0 745 my ($self, $file) = @_;
46 250 50       1289 if ($self->page_num_text) {
47 250         1171 my $num = $file->page->num;
48 250         1466 (my $text = $self->page_num_text) =~ s/\{num\}/$num/g;
49 250         2259 return $text;
50             }
51 0         0 return $file->page->num;
52             }
53              
54             sub clone {
55 248     248 0 654 my ($self) = @_;
56 248         1195 $self = $self->SUPER::clone();
57 248         2405 $self->active(1);
58 248         1835 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;