Apache/JAF/Util.pm untested

filter: Statementstmt 0.0% 0 / 42 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 92 CC 12 SCAR 43.5
CC
12
Cov
0%
get_navigation
132.0
valid_html
6.0
escape_uri
2.0
CRAP 77.7
1 package Apache::JAF::Util;
2
3 use strict;
4 use Apache;
5 use Apache::Util ();
6
7 ### Content
8
9 sub escape_uri {
10 my $uri = shift;
11 return $uri && Apache::Util::escape_uri($uri);
12 }
13
14 sub unescape_uri {
15 my $uri = shift;
16 return $uri && Apache::Util::unescape_uri($uri);
17 }
18
19 sub escape_html {
20 my $html = shift;
21 return $html && Apache::Util::escape_html($html);
22 }
23
24 sub valid_html {
25 my $string = shift;
26 $string = escape_html($string) if $ENV{MOD_PERL};
27 $string =~ s/\</\&lt;/g;
28 $string =~ s/\>/\&gt;/g;
29 $string =~ s/\n{2,}/<p>/sg;
30 $string =~ s/\n/<br>/sg;
31 $string = '<p>' . $string;
32 return $string;
33 }
34
35 # Navigation
36 ################################################################################
37 sub get_navigation {
38 my ($start, $count, $records_per_page, $navigation_count) = @_;
39
40 my $return = { total => $count };
41 return $return if($count <= $records_per_page);
42
43 for (my ($i,$j) = (0, int -$navigation_count/2); $i < $navigation_count;) {
44 last if ($start + $j*$records_per_page > $count);
45
46 if ( $start + ($j+1)*$records_per_page > 1 ) {
47 push @{$return->{pages}}, {link => ($start + $j*$records_per_page > 0) ? $start + $j*$records_per_page : 1,
48 selected => !$j,
49 title => (($start + $j*$records_per_page > 0) ? $start + $j*$records_per_page : 1)
50 ."-".
51 (($start + ($j+1)*$records_per_page - 1 > $count) ? $count : $start + ($j+1)*$records_per_page - 1)};
52 $i++
53 }
54 $j++
55 }
56
57 $return->{first} = 1 if($return->{pages}->[0]->{link} > 1);
58 $return->{last} = $count - $records_per_page + 1 if($count - $records_per_page >= $return->{pages}->[-1]->{link});
59 $return->{prev} = $start - $records_per_page if ($start - $records_per_page > 0);
60 $return->{next} = $start + $records_per_page if ($start + $records_per_page <= $count);
61
62 $return;
63 }
64
65 1;