blib/lib/HTML/PageIndex.pm

filter: Statementstmt 21.0% 12 / 57 Branchbran 0.0% 0 / 28 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 33.3% 2 / 6 Podpod 50.0% 1 / 2 totaltotal 16.1% 15 / 93 CC 15 SCAR 37.2
CC
15
Cov
14%
makeindex
56.0
_text_numbers
56.0
_url
12.0
CRAP 41.2
↑ Summary
1 package HTML::PageIndex;
2  
3 1 ▶use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 require Exporter;
7  
8 1 @ISA=qw(Exporter);
9 1 @EXPORT=qw();
10 1 @EXPORT_OK=qw();
11  
12 1 $VERSION = '0.3';
13  
14 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
15 0 my ($class) = @_;
16 0 my ($self) = {};
17 0 bless ($self, $class);
18 0 return $self;
19 }
20  
21 ################################################################################
22 # Public methods
23  
24 0 ▶sub makeindex {
Subroutine makeindex: not called CC=7 SCAR=40.3
Pod documented
25 0 my ($self, $total, $current, $Base, $Arg, $np) =@_;
26  
27 0 ▶ if (!$Base) { print __PACKAGE__.": Base URL not provided"; return;}
Branch: 1 branch
BranchTrueFalseTotal
unless ($Base) 0 0 0
28  
29 0 $self->{'BASE'} = $Base;
30 0 ▶ $self->{'ARG'} = $Arg if $Arg;
Branch: 1 branch
BranchTrueFalseTotal
if $Arg 0 0 0
31  
32 0 ▶ if ($total <= 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($total <= 1) 0 0 0
33 0 return "";
34 }
35
36 # Handle defaults and guard against absurd input values
37
38 0 ▶ $current = 1 if $current < 1;
Branch: 1 branch
BranchTrueFalseTotal
if $current < 1 0 0 0
39 0 ▶ $current = $total if $current > $total;
Branch: 1 branch
BranchTrueFalseTotal
if $current > $total 0 0 0
40 0 ▶ $np=0 if !$np;
Branch: 1 branch
BranchTrueFalseTotal
unless $np 0 0 0
41  
42 0 return $self->_text_numbers($total, $current,$np);
43 }
44  
45  
46  
47 ################################################################################
48 # Private methods
49  
50 0 ▶sub _text_numbers {
Subroutine _text_numbers: not called CC=7 SCAR=40.3
51 0 my ($self, $total, $current,$np) = @_;
52  
53 0 my ($prev) = $current - 1;
54 0 my ($next) = $current + 1;
55  
56 0 my ($out);
57  
58 # Display [Prev] unless on first page
59  
60 0 ▶ if ($current > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($current > 1) { } 0 0 0
61 0 $out .= "<a href=\"" .
62 $self->_url($prev) .
63 "\">&nbsp;[Prev]&nbsp;</a>\n";
64 } else {
65 0 ▶ if ($np > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($np > 0) 0 0 0
66 0 $out .= "&nbsp[Prev]&nbsp\n";
67 }
68 }
69  
70 # Display 1 2 3 etc...
71  
72 0 my ($i);
73  
74 0 ▶ for ($i = 1; $i<=$total; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $total) 0 0 0
75 0 ▶ if ($i == $current) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i == $current) { } 0 0 0
76 0 $out .= "<b>&nbsp;$i</b>&nbsp;\n";
77 } else {
78 0 $out .= "<a href=\"" .
79 $self->_url($i) .
80 "\">&nbsp;$i&nbsp;</a>\n";
81 }
82 }
83  
84 # Display [Next] unless on last page
85  
86 0 ▶ if ($current < $total) {
Branch: 1 branch
BranchTrueFalseTotal
if ($current < $total) { } 0 0 0
87 0 $out .= "<a href=\"" .
88 $self->_url($next) .
89 "\">&nbsp;[Next]&nbsp;</a>\n";
90 } else {
91 0 ▶ if ($np > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($np > 0) 0 0 0
92 0 $out .= "&nbsp[Next]&nbsp\n";
93 }
94 }
95  
96 0 return $out;
97 }
98  
99 0 ▶sub _url {
Subroutine _url: not called CC=3 SCAR=24.8
100 0 my ($self, $tagValue) = @_;
101  
102 0 my ($url) = $self->{'BASE'};
103 0 my ($arg) = $self->{'ARG'};
104  
105 0 ▶ if ($arg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg) 0 0 0
106  
107 0 $url =~ s/\&$arg=[^&]*//g;
108 0 $url =~ s/\?$arg=[^&]*&/?/g;
109 0 $url =~ s/\?$arg=[^&]*$//;
110  
111 0 ▶ if ($url =~ /\?/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($url =~ /\?/) { } 0 0 0
112 0 $url .= "&$arg=$tagValue";
113 } else {
114 0 $url .= "?$arg=$tagValue";
115 }
116 }
117  
118 0 return $url;
119 }
120  
121  
122 1 1; # wheeee;
123  
124 __END__
↑ Summary