Khonsu/Page/Header.pm

filter: Statementstmt 96.0% 24 / 25 Branchbran 60.0% 6 / 10 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 4 totaltotal 77.0% 37 / 48 CC 7 SCAR 13.5
CC
7
Cov
84%
render
6.4
process_page_num_text
2.1
BEGIN
1.0
CRAP 3.9
« Khonsu/Shape/Line.pm ↑ Summary Khonsu/TOC/Outline.pm »
1 package Khonsu::Page::Header;
2  
3 3 ▶use parent 'Khonsu::Text';
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 sub attributes {
6 4 ▶ my ($a) = shift;
Subroutine attributes: called CC=1 SCAR=0.0
Pod undocumented
7 return (
8 $a->SUPER::attributes(),
9 4 ▶ active => {$a->RW, $a->BOOL, default => sub { 1 }},
Subroutine __ANON__: called CC=1 SCAR=0.0
10 4 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 121 ▶ my ($self, $file) = @_;
Subroutine render: called CC=6 SCAR=18.6
Pod undocumented
19 121 ▶ return unless $self->active;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->active 1 120 121
20 120 my $y = ($self->h / 2) - ($self->font->size / 2);
21 120 ▶ my $w = $file->page->w - ($self->padding ? ( $self->padding * 2 ) : $self->padding);
Branch: 1 branch
BranchTrueFalseTotal
$self->padding ? : 120 0 120
22 120 ▶ my $x = $self->padding || 0;
Condition50%1/2
$self->padding || 0
l!l
1200
MC/DC0%0/1
$self->padding || 0
$self->padding
Truth table50%1/2
A
A= $self->padding
Aresult
11
00
23  
24 120 ▶ if ($self->show_page_num) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->show_page_num) 120 0 120
25 120 $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 120 ▶ $self->cb->(
Branch: 1 branch
BranchTrueFalseTotal
if $self->cb 120 0 120
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 240 ▶ my ($self, $file) = @_;
Subroutine process_page_num_text: called CC=2 SCAR=7.2
Pod undocumented
46 240 ▶ if ($self->page_num_text) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->page_num_text) 240 0 240
47 240 my $num = $file->page->num;
48 240 (my $text = $self->page_num_text) =~ s/\{num\}/$num/g;
49 240 return $text;
50 }
51 0 return $file->page->num;
52 }
53  
54 sub clone {
55 238 ▶ my ($self) = @_;
Subroutine clone: called CC=1 SCAR=0.0
Pod undocumented
56 238 $self = $self->SUPER::clone();
57 238 $self->active(1);
58 238 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 3 1;
« Khonsu/Shape/Line.pm ↑ Summary Khonsu/TOC/Outline.pm »