| 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
| |||||||||||
| 28 | |||||||||||
| 29 | 0 | $self->{'BASE'} = $Base; | |||||||||
| 30 | 0 | ▶ | $self->{'ARG'} = $Arg if $Arg; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 31 | |||||||||||
| 32 | 0 | ▶ | if ($total <= 1) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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
| |||||||||||
| 39 | 0 | ▶ | $current = $total if $current > $total; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | 0 | ▶ | $np=0 if !$np; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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
| |||||||||||
| 61 | 0 | $out .= "<a href=\"" . | |||||||||
| 62 | $self->_url($prev) . | ||||||||||
| 63 | "\"> [Prev] </a>\n"; | ||||||||||
| 64 | } else { | ||||||||||
| 65 | 0 | ▶ | if ($np > 0) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 66 | 0 | $out .= " [Prev] \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
| |||||||||||
| 75 | 0 | ▶ | if ($i == $current) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 76 | 0 | $out .= "<b> $i</b> \n"; | |||||||||
| 77 | } else { | ||||||||||
| 78 | 0 | $out .= "<a href=\"" . | |||||||||
| 79 | $self->_url($i) . | ||||||||||
| 80 | "\"> $i </a>\n"; | ||||||||||
| 81 | } | ||||||||||
| 82 | } | ||||||||||
| 83 | |||||||||||
| 84 | # Display [Next] unless on last page | ||||||||||
| 85 | |||||||||||
| 86 | 0 | ▶ | if ($current < $total) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 87 | 0 | $out .= "<a href=\"" . | |||||||||
| 88 | $self->_url($next) . | ||||||||||
| 89 | "\"> [Next] </a>\n"; | ||||||||||
| 90 | } else { | ||||||||||
| 91 | 0 | ▶ | if ($np > 0) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 92 | 0 | $out .= " [Next] \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
| |||||||||||
| 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
| |||||||||||
| 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__ | ||||||||||