blib/lib/HTML/Paginator.pm

filter: Statementstmt 3.3% 4 / 119 Branchbran 0.0% 0 / 82 Conditioncond 0.0% 0 / 78 MC/DCmcdc 0.0% 0 / 45 Subroutinesub 5.5% 1 / 18 Podpod 100% 13 / 13 totaltotal 5.0% 18 / 355 CC 68 SCAR 39.5
CC
68
Cov
1%
Page_Nav_HTML
132.0
new
110.0
Page_Header_HTML
72.0
CRAP 52.0
↑ Summary Paginator/test.pl »
1 package HTML::Paginator;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 # Preloaded methods go here.
5  
6 0 ▶sub new {
Subroutine new: not called CC=10 SCAR=47.0
Pod documented
7 0 ▶ my $pkg = shift or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $pkg = shift() or return undef 0 0 0
8 my $obj = { html=>{ pre_cap => '',
9 end_cap => '',
10 previous_icon => '<< ',
11 next_icon => ' >>',
12 singular => '',
13 plural => 's',
14 item_name => 'result',
15 seperator => ' | ',
16 0 href_link => $ENV{REQUEST_URI} }};
17 0 ▶ bless $obj, ref $pkg || $pkg;
Condition0%0/3
ref $pkg || $pkg
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $pkg || $pkg
ref $pkg $pkg
Truth table0%0/3
A || B
A= ref $pkgB= $pkg
ABresult
1X1
011
000
18 0 $obj->_Prep_HTML_Text;
19 0 ▶ if ($obj->{html}->{href_link} =~ /&page\=\d+&/) {
Branch: 5 branches
BranchTrueFalseTotal
if ($obj->{'html'}{'href_link'} =~ /&page\=\d+&/) { } 0 0 0
elsif ($obj->{'html'}{'href_link'} =~ /\?page\=\d+&/) { } 0 0 0
elsif ($obj->{'html'}{'href_link'} =~ /&page\=\d+$/) { } 0 0 0
elsif ($obj->{'html'}{'href_link'} =~ /\?page\=\d+$/) { } 0 0 0
elsif ($obj->{'html'}{'href_link'} =~ /\?/) { } 0 0 0
20 0 $obj->{html}->{href_link} =~ s/&page\=\d+&/&/g;
21 0 $obj->{html}->{href_link} .= '&page=';
22 }
23 elsif ($obj->{html}->{href_link} =~ /\?page\=\d+&/) {
24 0 $obj->{html}->{href_link} =~ s/\?page\=\d+&//g;
25 0 $obj->{html}->{href_link} .= '&page=';
26 }
27 elsif ($obj->{html}->{href_link} =~ /&page\=\d+$/) {
28 0 $obj->{html}->{href_link} =~ s/&page\=\d+$//g;
29 0 $obj->{html}->{href_link} .= '&page=';
30 }
31 elsif ($obj->{html}->{href_link} =~ /\?page\=\d+$/) {
32 0 $obj->{html}->{href_link} =~ s/\?page\=\d+$//g;
33 0 $obj->{html}->{href_link} .= '?page=';
34 }
35 elsif ($obj->{html}->{href_link} =~ /\?/) {
36 0 $obj->{html}{href_link} .= '&page=';
37 }
38 else {
39 0 $obj->{html}{href_link} .= '?page=';
40 }
41 $obj->{num_per_page} = shift
42 0 ▶ and $obj->{num_per_page} > 0
Branch: 1 branch
BranchTrueFalseTotal
$obj->{"num_per_page"} = shift() and $obj->{"num_per_page"} > 0 or return undef 0 0 0
Condition0%0/3
$obj->{"num_per_page"} = shift() and $obj->{"num_per_page"} > 0
!ll&&!rl&&r
000
MC/DC0%0/2
$obj->{"num_per_page"} = shift() and $obj->{"num_per_page"} > 0
$obj->{"num_per_page"} = shift() $obj->{"num_per_page"} > 0
Truth table0%0/3
A and B
A= $obj->{"num_per_page"} = shift()B= $obj->{"num_per_page"} > 0
ABresult
0X0
100
111
43 or return undef; # must have at least one item per page
44 0 $obj->{book} = \@_;
45 0 $obj->_Ginsoo;
46 0 return $obj;
47 }
48  
49 0 ▶sub _Ginsoo {
Subroutine _Ginsoo: not called CC=5 SCAR=34.0
50 0 my ($obj, @array);
51 0 ▶ $obj = shift and ref $obj and @array = @{$obj->{book}} or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$obj = shift() and ref $obj and @array = @{$obj->{"book"};} or return undef 0 0 0
Condition0%0/6
$obj = shift() and ref $obj and @array = @{$obj->{"book"};}
!ll&&!rl&&r
000
$obj = shift() and ref $obj
!ll&&!rl&&r
000
MC/DC0%0/3
$obj = shift() and ref $obj and @array = @{$obj->{"book"};}
$obj = shift() ref $obj @array = @{$obj->{"book"};}
Truth table0%0/4
A and B and C
A= $obj = shift()B= ref $objC= @array = @{$obj->{"book"};}
ABCresult
0XX0
10X0
1100
1111
52 0 $obj->{total} = scalar @array; # store total in array
53 0 my $i = 0;
54 0 ▶ while (my @slice = splice @array, 0, $obj->{num_per_page}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@slice) = splice(@array, 0, $obj->{"num_per_page"})) 0 0 0
55 0 push @{$obj->{page}}, \@slice; # one slice per page
56 0 $i++
57 }
58 0 $obj->{num_pages} = $i;
59 }
60  
61 0 ▶sub _Set_HTML_Text {
Subroutine _Set_HTML_Text: not called CC=5 SCAR=34.0
62 0 my $obj;
63 0 ▶ $obj = shift and ref $obj or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$obj = shift() and ref $obj or return undef 0 0 0
Condition0%0/3
$obj = shift() and ref $obj
!ll&&!rl&&r
000
MC/DC0%0/2
$obj = shift() and ref $obj
$obj = shift() ref $obj
Truth table0%0/3
A and B
A= $obj = shift()B= ref $obj
ABresult
0X0
100
111
64 0 ▶ my $what = shift or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $what = shift() or return undef 0 0 0
65 0 my $new_name = shift;
66 0 ▶ defined $new_name or return undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $new_name or return undef 0 0 0
67 0 $obj->{html}->{$what} = $new_name;
68 0 return $obj->_Prep_HTML_Text;
69 }
70  
71 0 ▶sub _Prep_HTML_Text {
Subroutine _Prep_HTML_Text: not called CC=3 SCAR=24.8
72 0 my $obj;
73 0 ▶ $obj = shift and ref $obj or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$obj = shift() and ref $obj or return undef 0 0 0
Condition0%0/3
$obj = shift() and ref $obj
!ll&&!rl&&r
000
MC/DC0%0/2
$obj = shift() and ref $obj
$obj = shift() ref $obj
Truth table0%0/3
A and B
A= $obj = shift()B= ref $obj
ABresult
0X0
100
111
74 0 $obj->{html}->{previous_text} = "Last %d $obj->{html}->{item_name}%s";
75 0 $obj->{html}->{next_text} = "Next %d $obj->{html}->{item_name}%s";
76 0 return 1;
77 }
78  
79 0 ▶sub Name_Item {
Subroutine Name_Item: not called CC=3 SCAR=24.8
Pod documented
80 0 my $obj;
81 0 ▶ $obj = shift and ref $obj or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$obj = shift() and ref $obj or return undef 0 0 0
Condition0%0/3
$obj = shift() and ref $obj
!ll&&!rl&&r
000
MC/DC0%0/2
$obj = shift() and ref $obj
$obj = shift() ref $obj
Truth table0%0/3
A and B
A= $obj = shift()B= ref $obj
ABresult
0X0
100
111
82 0 return $obj->_Set_HTML_Text('item_name', shift);
83 }
84  
85 0 ▶sub Set_Plural {
Subroutine Set_Plural: not called CC=3 SCAR=24.8
Pod documented
86 0 my $obj;
87 0 ▶ $obj = shift and ref $obj or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$obj = shift() and ref $obj or return undef 0 0 0
Condition0%0/3
$obj = shift() and ref $obj
!ll&&!rl&&r
000
MC/DC0%0/2
$obj = shift() and ref $obj
$obj = shift() ref $obj
Truth table0%0/3
A and B
A= $obj = shift()B= ref $obj
ABresult
0X0
100
111
88 0 return $obj->_Set_HTML_Text('plural', shift);
89 }
90  
91 0 ▶sub Set_Singular {
Subroutine Set_Singular: not called CC=3 SCAR=24.8
Pod documented
92 0 my $obj;
93 0 ▶ $obj = shift and ref $obj or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$obj = shift() and ref $obj or return undef 0 0 0
Condition0%0/3
$obj = shift() and ref $obj
!ll&&!rl&&r
000
MC/DC0%0/2
$obj = shift() and ref $obj
$obj = shift() ref $obj
Truth table0%0/3
A and B
A= $obj = shift()B= ref $obj
ABresult
0X0
100
111
94 0 return $obj->_Set_HTML_Text('singular', shift);
95 }
96  
97 0 ▶sub Contents {
Subroutine Contents: not called CC=6 SCAR=37.4
Pod documented
98 0 my ($obj, $page);
99 0 ▶ $obj = shift
Branch: 1 branch
BranchTrueFalseTotal
$obj = shift() and ref $obj and $page = shift() and $page > 0 or return undef 0 0 0
Condition0%0/9
$obj = shift() and ref $obj and $page = shift() and $page > 0
!ll&&!rl&&r
000
$obj = shift() and ref $obj and $page = shift()
!ll&&!rl&&r
000
$obj = shift() and ref $obj
!ll&&!rl&&r
000
MC/DC0%0/4
$obj = shift() and ref $obj and $page = shift() and $page > 0
$obj = shift() ref $obj $page = shift() $page > 0
Truth table0%0/5
A and B and C and D
A= $obj = shift()B= ref $objC= $page = shift()D= $page > 0
ABCDresult
0XXX0
10XX0
110X0
11100
11111
100 and ref $obj
101 and $page = shift
102 and $page > 0
103 or return undef;
104 0 $page--;
105 return exists $obj->{page}->[$page]?
106 0 ▶ @{$obj->{page}->[$page]}:
Branch: 1 branch
BranchTrueFalseTotal
exists $obj->{'page'}[$page] ? : 0 0 0
107 ();
108 }
109  
110 0 ▶sub Next { # next page index is current page number
Subroutine Next: not called CC=3 SCAR=24.8
Pod documented
111 0 my $obj;
112 0 ▶ $obj = shift and ref $obj or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$obj = shift() and ref $obj or return undef 0 0 0
Condition0%0/3
$obj = shift() and ref $obj
!ll&&!rl&&r
000
MC/DC0%0/2
$obj = shift() and ref $obj
$obj = shift() ref $obj
Truth table0%0/3
A and B
A= $obj = shift()B= ref $obj
ABresult
0X0
100
111
113 0 return $obj->_Item_Count(shift);
114 }
115  
116 0 ▶sub Previous { # previous page index is two less than page number
Subroutine Previous: not called CC=3 SCAR=24.8
Pod documented
117 0 my $obj;
118 0 ▶ $obj = shift and ref $obj or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$obj = shift() and ref $obj or return undef 0 0 0
Condition0%0/3
$obj = shift() and ref $obj
!ll&&!rl&&r
000
MC/DC0%0/2
$obj = shift() and ref $obj
$obj = shift() ref $obj
Truth table0%0/3
A and B
A= $obj = shift()B= ref $obj
ABresult
0X0
100
111
119 0 return $obj->_Item_Count(shift(@_) - 2);
120 }
121  
122 0 ▶sub Item_Count { # current page is one less than page number
Subroutine Item_Count: not called CC=3 SCAR=24.8
Pod documented
123 0 my $obj;
124 0 ▶ $obj = shift and ref $obj or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$obj = shift() and ref $obj or return undef 0 0 0
Condition0%0/3
$obj = shift() and ref $obj
!ll&&!rl&&r
000
MC/DC0%0/2
$obj = shift() and ref $obj
$obj = shift() ref $obj
Truth table0%0/3
A and B
A= $obj = shift()B= ref $obj
ABresult
0X0
100
111
125 0 return $obj->_Item_Count(shift(@_) - 1);
126 }
127  
128  
129 0 ▶sub _Item_Count {
Subroutine _Item_Count: not called CC=5 SCAR=34.0
130 0 my $obj;
131 0 ▶ $obj = shift and ref $obj or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$obj = shift() and ref $obj or return undef 0 0 0
Condition0%0/3
$obj = shift() and ref $obj
!ll&&!rl&&r
000
MC/DC0%0/2
$obj = shift() and ref $obj
$obj = shift() ref $obj
Truth table0%0/3
A and B
A= $obj = shift()B= ref $obj
ABresult
0X0
100
111
132  
133 0 my $page = shift;
134 0 ▶ $page > -1 or return undef; # no negative page numbers
Branch: 1 branch
BranchTrueFalseTotal
$page > -1 or return undef 0 0 0
135 return exists $obj->{page}->[$page]?
136 0 ▶ scalar @{$obj->{page}->[$page]}:
Branch: 1 branch
BranchTrueFalseTotal
exists $obj->{'page'}[$page] ? : 0 0 0
137 0;
138 }
139  
140 0 ▶sub Page_Count {
Subroutine Page_Count: not called CC=3 SCAR=24.8
Pod documented
141 0 my $obj;
142 0 ▶ $obj = shift and ref $obj or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$obj = shift() and ref $obj or return undef 0 0 0
Condition0%0/3
$obj = shift() and ref $obj
!ll&&!rl&&r
000
MC/DC0%0/2
$obj = shift() and ref $obj
$obj = shift() ref $obj
Truth table0%0/3
A and B
A= $obj = shift()B= ref $obj
ABresult
0X0
100
111
143 0 return scalar @{$obj->{page}};
144 }
145  
146 0 ▶sub First_Item {
Subroutine First_Item: not called CC=5 SCAR=34.0
Pod documented
147 0 my $obj;
148 0 ▶ $obj = shift and ref $obj or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$obj = shift() and ref $obj or return undef 0 0 0
Condition0%0/3
$obj = shift() and ref $obj
!ll&&!rl&&r
000
MC/DC0%0/2
$obj = shift() and ref $obj
$obj = shift() ref $obj
Truth table0%0/3
A and B
A= $obj = shift()B= ref $obj
ABresult
0X0
100
111
149 0 my $page = shift;
150 0 ▶ $page > 0 or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$page > 0 or return undef 0 0 0
151 0 $page--;
152 0 ▶ return undef unless $obj->_Item_Count($page);
Branch: 1 branch
BranchTrueFalseTotal
unless $obj->_Item_Count($page) 0 0 0
153 0 return ($obj->{num_per_page} * $page) + 1;
154 }
155  
156 0 ▶sub Last_Item {
Subroutine Last_Item: not called CC=5 SCAR=34.0
Pod documented
157 0 my $obj;
158 0 ▶ $obj = shift and ref $obj or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$obj = shift() and ref $obj or return undef 0 0 0
Condition0%0/3
$obj = shift() and ref $obj
!ll&&!rl&&r
000
MC/DC0%0/2
$obj = shift() and ref $obj
$obj = shift() ref $obj
Truth table0%0/3
A and B
A= $obj = shift()B= ref $obj
ABresult
0X0
100
111
159 0 my $page = shift;
160 0 ▶ $page > 0 or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$page > 0 or return undef 0 0 0
161 0 $page--;
162 0 ▶ return undef unless $obj->_Item_Count($page);
Branch: 1 branch
BranchTrueFalseTotal
unless $obj->_Item_Count($page) 0 0 0
163 0 return ($obj->{num_per_page} * $page) + scalar $obj->_Item_Count($page);
164 }
165  
166 0 ▶sub Page_Header_HTML {
Subroutine Page_Header_HTML: not called CC=8 SCAR=42.8
Pod documented
167 0 my ($obj, $page);
168 0 ▶ $obj = shift and ref $obj and $page = shift and $page > 0
Branch: 1 branch
BranchTrueFalseTotal
$obj = shift() and ref $obj and $page = shift() and $page > 0 or return "[An error occurred while forming the page header]" 0 0 0
Condition0%0/9
$obj = shift() and ref $obj and $page = shift() and $page > 0
!ll&&!rl&&r
000
$obj = shift() and ref $obj and $page = shift()
!ll&&!rl&&r
000
$obj = shift() and ref $obj
!ll&&!rl&&r
000
MC/DC0%0/4
$obj = shift() and ref $obj and $page = shift() and $page > 0
$obj = shift() ref $obj $page = shift() $page > 0
Truth table0%0/5
A and B and C and D
A= $obj = shift()B= ref $objC= $page = shift()D= $page > 0
ABCDresult
0XXX0
10XX0
110X0
11100
11111
169 or return "[An error occurred while forming the page header]";
170 0 $obj->{html}->{previous_text} = "Last %d $obj->{html}->{item_name}%s";
171 0 $obj->{html}->{next_text} = "Next %d $obj->{html}->{item_name}%s";
172 0 ▶ if ($obj->Page_Count > 1) { # Case more than one page
Branch: 3 branches
BranchTrueFalseTotal
if ($obj->Page_Count > 1) { } 0 0 0
elsif ($obj->_Item_Count($page - 1) == 1) { } 0 0 0
elsif ($obj->_Item_Count($page - 1) == 0) { } 0 0 0
173 return sprintf <<"eohtml",
174 %s%s %d to %d of %d (Page $page of %d)
175 eohtml
176 ucfirst $obj->{html}->{item_name},
177 $obj->{html}->{plural},
178 $obj->First_Item($page),
179 $obj->Last_Item($page),
180 0 $obj->{num_per_page} * ($obj->Page_Count - 1)
181 + $obj->_Item_Count($obj->Page_Count-1),
182 $obj->Page_Count;
183 }
184 elsif ($obj->_Item_Count($page-1) == 1) { # Case one page one item
185 return sprintf <<"eohtml",
186 The only %s%s
187 eohtml
188 $obj->{html}->{item_name},
189 0 $obj->{html}->{singular};
190 }
191 elsif ($obj->_Item_Count($page-1) == 0) { # Case no items
192 return sprintf <<"eohtml",
193 No %s%s
194 eohtml
195 $obj->{html}->{item_name},
196 0 $obj->{html}->{plural};
197 }
198 else { # Case one page multiple items
199 return sprintf <<"eohtml",
200 All %d %s%s
201 eohtml
202 $obj->_Item_Count($page-1),
203 $obj->{html}->{item_name},
204 0 $obj->{html}->{plural};
205 }
206 }
207  
208 0 ▶sub Page_Nav_HTML {
Subroutine Page_Nav_HTML: not called CC=11 SCAR=48.8
Pod documented
209 0 my ($obj, $page);
210 0 ▶ $obj = shift and ref $obj and $page = shift and $page > 0
Branch: 1 branch
BranchTrueFalseTotal
$obj = shift() and ref $obj and $page = shift() and $page > 0 or return "[An error occured while forming the page count]" 0 0 0
Condition0%0/9
$obj = shift() and ref $obj and $page = shift() and $page > 0
!ll&&!rl&&r
000
$obj = shift() and ref $obj and $page = shift()
!ll&&!rl&&r
000
$obj = shift() and ref $obj
!ll&&!rl&&r
000
MC/DC0%0/4
$obj = shift() and ref $obj and $page = shift() and $page > 0
$obj = shift() ref $obj $page = shift() $page > 0
Truth table0%0/5
A and B and C and D
A= $obj = shift()B= ref $objC= $page = shift()D= $page > 0
ABCDresult
0XXX0
10XX0
110X0
11100
11111
211 or return "[An error occured while forming the page count]";
212 0 $obj->{html}->{previous_text} = "Last %d $obj->{html}->{item_name}%s";
213 0 $obj->{html}->{next_text} = "Next %d $obj->{html}->{item_name}%s";
214 0 my $p_cap = $obj->{html}->{pre_cap};
215 0 my $n_cap = $obj->{html}->{end_cap};
216 0 my $p_icon = $obj->{html}->{previous_icon};
217 0 my $n_icon = $obj->{html}->{next_icon};
218 0 my $p_count = $obj->Previous($page);
219 0 my $n_count = $obj->Next($page);
220 0 my $p_page = $page - 1;
221 0 my $n_page = $page + 1;
222 my $p_text = sprintf $obj->{html}->{previous_text},
223 $p_count,
224 $p_count == 1?
225 $obj->{html}->{singular}:
226 0 ▶ $obj->{html}->{plural};
Branch: 1 branch
BranchTrueFalseTotal
$p_count == 1 ? : 0 0 0
227 my $n_text = sprintf $obj->{html}->{next_text},
228 $n_count,
229 $n_count == 1?
230 $obj->{html}->{singular}:
231 0 ▶ $obj->{html}->{plural};
Branch: 1 branch
BranchTrueFalseTotal
$n_count == 1 ? : 0 0 0
232 0 my $link = $obj->{html}->{href_link};
233 0 my $sep = $obj->{html}->{seperator};
234 0 ▶ my $nav_html = sprintf <<"eohtml",
Branch: 3 branches
BranchTrueFalseTotal
$p_count ? : 0 0 0
$p_count && $n_count ? : 0 0 0
$n_count ? : 0 0 0
Condition0%0/3
$p_count and $n_count
!ll&&!rl&&r
000
MC/DC0%0/2
$p_count and $n_count
$p_count $n_count
Truth table0%0/3
A and B
A= $p_countB= $n_count
ABresult
0X0
100
111
235 $p_cap%s%s%s$n_cap
236 eohtml
237 $p_count?
238 "<a href=\"$link$p_page\">$p_icon$p_text</a>":
239 '',
240 $p_count && $n_count?
241 $sep:
242 '',
243 $n_count?
244 "<a href=\"$link$n_page\">$n_text$n_icon</a>":
245 '';
246 0 return $nav_html;
247 }
248  
249 1 1;
250 __END__
↑ Summary Paginator/test.pl »