blib/lib/HTML/Paging/SQL.pm

filter: Statementstmt 4.4% 5 / 113 Branchbran 1.7% 1 / 56 Conditioncond 0.0% 0 / 14 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 25.0% 1 / 4 Podpod 100% 2 / 2 totaltotal 4.5% 9 / 198 CC 36 SCAR 58.7
CC
36
Cov
3%
number
552.0
_status
110.0
new
20.0
CRAP 355.9
↑ Summary
1 package HTML::Paging::SQL;
2
3 #
4 # PARAMETER README
5 #
6 # $hash->{"HP_A"} : all page(s) amount
7 # $hash->{"HP_C"} : curret page number
8 # $hash->{"HP_P"} : other user parameter
9 # $hash->{"HP_U"} : user script uri
10 #
11
12 #
13 # Set GET to POST method
14 #
15 1 ▶sub BEGIN {
Subroutine BEGIN: called CC=2 SCAR=8.5
16 # set version to ENV
17 1 $HTML::Paging::SQL::revision = '$Id: SQL.pm,v 1.17 2002/01/18 12:37:57 wangaocheng Exp $';
18 1 ($HTML::Paging::SQL::VERSION) = '$Revision: 1.17 $' =~ /(\d+\.\d+)/;
19 1 $ENV{"HTML_PAGING_SQL"} = $HTML::Paging::SQL::VERSION;
20 1 ▶ if ($ENV{"REQUEST_METHOD"} eq "POST") {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"REQUEST_METHOD"} eq "POST") 0 1 1
21 0 sysread(STDIN, $HTML::Paging::SQL::buffer, $ENV{"CONTENT_LENGTH"});
22 0 $ENV{"REQUEST_METHOD"} = "GET";
23 0 $ENV{"QUERY_STRING"} = "$HTML::Paging::SQL::buffer";
24 }
25 }
26
27 #
28 # Create a new object
29 #
30 0 ▶sub new {
Subroutine new: not called CC=4 SCAR=30.0
Pod documented
31 0 my $class = shift;
32 0 my $self = {};
33 # process user parameter
34 0 ▶ if (ref($_[0]) eq "HASH") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0] eq 'HASH') { } 0 0 0
35 0 $self = shift;
36 } else {
37 0 my %self = @_;
38 0 $self = \%self;
39 }
40 0 ▶ if ($self->{"all"} !~ m/^\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"all"} =~ /^\d+$/) 0 0 0
41 0 $self->{"all"} = 0; # process error here
42 }
43 0 ▶ if ($self->{"num"} !~ m/^\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"num"} =~ /^\d+$/) 0 0 0
44 0 $self->{"num"} = 10; # set per page default
45 }
46 0 return bless $self,$class;
47 }
48
49 #
50 # Format output with Number Mode
51 #
52 0 ▶sub number {
Subroutine number: not called CC=23 SCAR=63.1
Pod documented
53 0 my $self = shift;
54 0 my $hash = $self->_status();
55 0 my @result;
56 0 $result[1] = $self->{"num"} * ($hash->{"HP_C"}-1);
57 0 $result[2] = $self->{"num"};
58 0 ▶ if ($self->{"all"} < $self->{"num"}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"all"} < $self->{"num"}) 0 0 0
59 0 return @result; # output null to caller
60 }
61 0 my $param = {};
62 # process user parameter
63 0 ▶ if (ref($_[0]) eq "HASH") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0] eq 'HASH') { } 0 0 0
64 0 $param = shift;
65 } else {
66 0 my %param = @_;
67 0 $param = \%param;
68 }
69 # set default back & forward icon
70 0 ▶ if (!$param->{"bicon"}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($param->{"bicon"}) 0 0 0
71 0 $param->{"bicon"} = "&lt;&lt;";
72 }
73 0 ▶ if (!$param->{"ficon"}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($param->{"ficon"}) 0 0 0
74 0 $param->{"ficon"} = "&gt;&gt;";
75 }
76 0 ▶ if ($param->{"sub"} !~ /^\d+$/ or $param->{"sub"} >= $hash->{"HP_A"}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $param->{"sub"} =~ /^\d+$/ or $param->{"sub"} >= $hash->{"HP_A"}) 0 0 0
Condition0%0/3
not $param->{"sub"} =~ /^\d+$/ or $param->{"sub"} >= $hash->{"HP_A"}
l!l&&r!l&&!r
000
MC/DC0%0/2
not $param->{"sub"} =~ /^\d+$/ or $param->{"sub"} >= $hash->{"HP_A"}
not $param->{"sub"} =~ /^\d+$/ $param->{"sub"} >= $hash->{"HP_A"}
Truth table0%0/3
not(A) or B
A= not $param->{"sub"} =~ /^\d+$/B= $param->{"sub"} >= $hash->{"HP_A"}
ABresult
1X1
011
000
77 0 $param->{"sub"} = 0;
78 }
79 0 my ($current,$total);
80 0 ▶ if ($param->{"sub"}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($param->{'sub'}) { } 0 0 0
81 0 $current = $hash->{"HP_C"}/$param->{"sub"}; # start page number
82 # not current page end number
83 0 ▶ if ($current =~ /\d+\.\d+/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($current =~ /\d+\.\d+/) { } 0 0 0
84 0 $current = int($current) * $param->{"sub"} + 1;
85 } else {
86 # I think this is page end number :)
87 0 $current = $hash->{"HP_C"} - $param->{"sub"} + 1;
88 }
89 0 $total = $current + $param->{"sub"} - 1;
90 } else {
91 0 $current = 1;
92 0 $total = $hash->{"HP_A"};
93 }
94 # return HTML code
95 0 undef $result[0];
96 0 $result[0] .= "<!-- HTML::Paging::SQL $HTML::Paging::SQL::VERSION Begin -->\n";
97 0 ▶ if ($param->{"sub"} && $hash->{"HP_C"} > $param->{"sub"}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($param->{"sub"} and $hash->{"HP_C"} > $param->{"sub"}) 0 0 0
Condition0%0/3
$param->{"sub"} and $hash->{"HP_C"} > $param->{"sub"}
!ll&&!rl&&r
000
MC/DC0%0/2
$param->{"sub"} and $hash->{"HP_C"} > $param->{"sub"}
$param->{"sub"} $hash->{"HP_C"} > $param->{"sub"}
Truth table0%0/3
A and B
A= $param->{"sub"}B= $hash->{"HP_C"} > $param->{"sub"}
ABresult
0X0
100
111
98 0 $result[0] .= qq|<a href="$hash->{'HP_U'}?|;
99 0 ▶ $result[0] .= qq|$hash->{'HP_P'}&| if ($hash->{'HP_P'});
Branch: 1 branch
BranchTrueFalseTotal
if $hash->{"HP_P"} 0 0 0
100 0 $result[0] .= qq|HP_C=| . ($current-1) . qq|"|;
101 0 ▶ $result[0] .= qq| target="$param->{'target'}"| if ($param->{"target"});
Branch: 1 branch
BranchTrueFalseTotal
if $param->{"target"} 0 0 0
102 0 $result[0] .= qq|>|;
103 0 $result[0] .= qq|$param->{"bicon"}|;
104 0 $result[0] .= qq|</a>\n|;
105 }
106 # set number now
107 0 ▶ for (my $i=$current; $i<=$total ; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $total) 0 0 0
108 0 ▶ if ($i > $hash->{"HP_A"}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i > $hash->{"HP_A"}) 0 0 0
109 0 last;
110 }
111 0 ▶ if ($i == $hash->{"HP_C"}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i == $hash->{'HP_C'}) { } 0 0 0
112 0 $result[0] .= qq|$i \n|;
113 } else {
114 0 $result[0] .= qq|<a href="$hash->{'HP_U'}?|;
115 0 ▶ $result[0] .= qq|$hash->{'HP_P'}&| if ($hash->{'HP_P'});
Branch: 1 branch
BranchTrueFalseTotal
if $hash->{"HP_P"} 0 0 0
116 0 $result[0] .= qq|HP_C=$i"|;
117 0 ▶ $result[0] .= qq| target="$param->{'target'}"| if ($param->{"target"});
Branch: 1 branch
BranchTrueFalseTotal
if $param->{"target"} 0 0 0
118 0 $result[0] .= qq|>|;
119 0 $result[0] .= qq|$i|;
120 0 $result[0] .= qq|</a>\n|;
121 }
122 0 ▶ if ($i == $hash->{"HP_A"}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i == $hash->{"HP_A"}) 0 0 0
123 0 last;
124 }
125 }
126 0 ▶ if ($param->{"sub"} && ($current+$param->{"sub"}-1) < $hash->{"HP_A"}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($param->{"sub"} and $current + $param->{"sub"} - 1 < $hash->{"HP_A"}) 0 0 0
Condition0%0/3
$param->{"sub"} and $current + $param->{"sub"} - 1 < $hash->{"HP_A"}
!ll&&!rl&&r
000
MC/DC0%0/2
$param->{"sub"} and $current + $param->{"sub"} - 1 < $hash->{"HP_A"}
$param->{"sub"} $current + $param->{"sub"} - 1 < $hash->{"HP_A"}
Truth table0%0/3
A and B
A= $param->{"sub"}B= $current + $param->{"sub"} - 1 < $hash->{"HP_A"}
ABresult
0X0
100
111
127 0 $result[0] .= qq|<a href="$hash->{'HP_U'}?|;
128 0 ▶ $result[0] .= qq|$hash->{'HP_P'}&| if ($hash->{'HP_P'});
Branch: 1 branch
BranchTrueFalseTotal
if $hash->{"HP_P"} 0 0 0
129 0 $result[0] .= qq|HP_C=| . ($total+1) . qq|"|;
130 0 ▶ $result[0] .= qq| target="$param->{'target'}"| if ($param->{"target"});
Branch: 1 branch
BranchTrueFalseTotal
if $param->{"target"} 0 0 0
131 0 $result[0] .= qq|>|;
132 0 $result[0] .= qq|$param->{"ficon"}|;
133 0 $result[0] .= qq|</a>\n|;
134 }
135 0 $result[0] .= "<!-- HTML::Paging::SQL $HTML::Paging::SQL::VERSION End -->\n";
136 0 return @result;
137 }
138
139 #
140 # Get current status { private method }
141 #
142 0 ▶sub _status {
Subroutine _status: not called CC=10 SCAR=47.0
143 0 my $self = shift;
144 0 my $hash = {};
145 0 my $form = {};
146 0 $hash->{"HP_A"} = $self->{"all"}/$self->{"num"};
147 0 ▶ if ($hash->{"HP_A"} =~ /\d+\.\d+/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hash->{"HP_A"} =~ /\d+\.\d+/) 0 0 0
148 0 $hash->{"HP_A"} = int($hash->{"HP_A"}) + 1;
149 }
150 0 my $uri = $ENV{"REQUEST_URI"};
151 0 my ($script,$string) = split(/\?/,$uri);
152 0 my @param;
153 # process GET method
154 0 ▶ if (!$HTML::Paging::SQL::buffer) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $buffer) { } 0 0 0
155 0 @param = split('&',$string);
156 } else {
157 0 chomp($HTML::Paging::SQL::buffer);
158 0 @param = split('&',$HTML::Paging::SQL::buffer);
159 }
160 0 foreach (@param) {
161 0 $_ =~ s/\+/ /g;
162 0 my ($key, $val) = split(/=/,$_);
163 0 $key =~ s/%([A-Fa-f0-9]{2})/pack("c",hex($1))/ge;
164 0 $val =~ s/%([A-Fa-f0-9]{2})/pack("c",hex($1))/ge;
165 0 $form->{"$key"} = "$val";
166 }
167 0 $hash->{"HP_U"} = $script; #CALLER URI
168 0 ▶ $hash->{"HP_C"} = $form->{"HP_C"} || 1; #CURRENT PAGE
Condition0%0/2
$form->{'HP_C'} || 1
l!l
00
MC/DC0%0/1
$form->{'HP_C'} || 1
$form->{'HP_C'}
Truth table0%0/2
A
A= $form->{'HP_C'}
Aresult
11
00
169 # process overflow
170 0 ▶ if ($hash->{"HP_C"} > $hash->{"HP_A"}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hash->{"HP_C"} > $hash->{"HP_A"}) 0 0 0
171 0 $hash->{"HP_C"} = $hash->{"HP_A"};
172 }
173 0 ▶ if ($hash->{"HP_C"} < 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hash->{"HP_C"} < 1) 0 0 0
174 0 $hash->{"HP_C"} = 1;
175 }
176 0 undef @param;
177 0 foreach (keys %$form) {
178 0 ▶ next if ($_ eq "HP_C" or $_ eq "");
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "HP_C" or $_ eq "" 0 0 0
Condition0%0/3
$_ eq "HP_C" or $_ eq ""
l!l&&r!l&&!r
000
MC/DC0%0/2
$_ eq "HP_C" or $_ eq ""
$_ eq "HP_C" $_ eq ""
Truth table0%0/3
A or B
A= $_ eq "HP_C"B= $_ eq ""
ABresult
1X1
011
000
179 0 push(@param,$_."=".$form->{"$_"});
180 }
181 0 $hash->{"HP_P"} = join("&",@param); #OTHER PARAMETER
182 0 return $hash;
183 }
184
185 1 1;
186
187 __END__
↑ Summary