| 1 | =head1 NAME | ||||||||||
| 2 | |||||||||||
| 3 | WWW::Link::Reporter::HTML - Report on status of links in HTML | ||||||||||
| 4 | |||||||||||
| 5 | =head1 SYNOPSIS | ||||||||||
| 6 | |||||||||||
| 7 | use WWW::Link; | ||||||||||
| 8 | use WWW::Link::Reporter::HTML; | ||||||||||
| 9 | |||||||||||
| 10 | $link=new WWW::Link; | ||||||||||
| 11 | #over time do things to the link ...... | ||||||||||
| 12 | |||||||||||
| 13 | $::reporter=new WWW::Link::Reporter::HTML; | ||||||||||
| 14 | $::reporter->examine($link) | ||||||||||
| 15 | |||||||||||
| 16 | or see WWW::Link::Selector for a way to recurse through all of the links. | ||||||||||
| 17 | |||||||||||
| 18 | =head1 DESCRIPTION | ||||||||||
| 19 | |||||||||||
| 20 | This class will output information about any link that it is given. | ||||||||||
| 21 | |||||||||||
| 22 | If it's constructor is given an index (CDB_File::BiIndex or BiIndex) then it | ||||||||||
| 23 | can use that to generate lists of urls containing links being reported | ||||||||||
| 24 | on. | ||||||||||
| 25 | |||||||||||
| 26 | =cut | ||||||||||
| 27 | |||||||||||
| 28 | package WWW::Link::Reporter::HTML; | ||||||||||
| 29 | 1 | $REVISION=q$Revision: 1.7 $ ; $VERSION = sprintf ( "%d.%02d", $REVISION =~ /(\d+).(\d+)/ ); | |||||||||
| 30 | |||||||||||
| 31 | 1 | ▶ | use WWW::Link; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 32 | 1 | ▶ | use HTML::Stream; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 33 | 1 | ▶ | use WWW::Link::Reporter; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 34 | 1 | @ISA=qw(WWW::Link::Reporter); | |||||||||
| 35 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 36 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 37 | |||||||||||
| 38 | =head1 new | ||||||||||
| 39 | |||||||||||
| 40 | This | ||||||||||
| 41 | |||||||||||
| 42 | =cut | ||||||||||
| 43 | |||||||||||
| 44 | 0 | ▶ | sub new ($$;$){ | ||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 45 | 0 | my ($class,$stream, $index)=@_; | |||||||||
| 46 | 0 | my $self=WWW::Link::Reporter::new($class, $index); | |||||||||
| 47 | 0 | $self->{"hstr"} = new HTML::Stream::LinkReport $stream; | |||||||||
| 48 | 0 | $self->{"docurl"} = "http://localhost/linkcontroler/docs/"; | |||||||||
| 49 | 0 | return $self; | |||||||||
| 50 | } | ||||||||||
| 51 | |||||||||||
| 52 | 0 | ▶ | sub heading ($) { | ||||||||
|
Subroutine
heading: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 53 | 0 | my $self=shift; | |||||||||
| 54 | 0 | $self->{"hstr"}->Heading; | |||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | 0 | ▶ | sub footer ($) { | ||||||||
|
Subroutine
footer: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 58 | 0 | my $self=shift; | |||||||||
| 59 | 0 | $self->{"hstr"}->Footer; | |||||||||
| 60 | } | ||||||||||
| 61 | |||||||||||
| 62 | 0 | ▶ | sub not_found { | ||||||||
|
Subroutine
not_found: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 63 | 0 | my $self=shift; | |||||||||
| 64 | 0 | my $url=shift; | |||||||||
| 65 | 0 | $self->{"hstr"}-> P | |||||||||
| 66 | -> t("Sorry, the link $url is not in the database.\n") | ||||||||||
| 67 | -> _P; | ||||||||||
| 68 | } | ||||||||||
| 69 | |||||||||||
| 70 | 0 | ▶ | sub broken { | ||||||||
|
Subroutine
broken: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 71 | 0 | my ($self, $link, $redir)=@_; | |||||||||
| 72 | |||||||||||
| 73 | 0 | my $url=$link->url(); | |||||||||
| 74 | 0 | my $hstr=$self->{"hstr"}; | |||||||||
| 75 | |||||||||||
| 76 | 0 | $hstr-> P; | |||||||||
| 77 | |||||||||||
| 78 | 0 | $hstr -> STRONG -> nl | |||||||||
| 79 | ->Link_Heading($url, "Link found BROKEN") | ||||||||||
| 80 | -> _STRONG -> nl; | ||||||||||
| 81 | |||||||||||
| 82 | 0 | ▶ | $redir && $self->redirections($link); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 83 | 0 | $self->suggestions($link); | |||||||||
| 84 | |||||||||||
| 85 | 0 | ▶ | if ($self->{"index"}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 86 | 0 | $hstr->page_list( $self->{"index"}->lookup_second($url) ); | |||||||||
| 87 | } | ||||||||||
| 88 | |||||||||||
| 89 | 0 | $hstr-> _P; | |||||||||
| 90 | } | ||||||||||
| 91 | |||||||||||
| 92 | 0 | ▶ | sub okay { | ||||||||
|
Subroutine
okay: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 93 | 0 | my ($self, $link, $redir)=@_; | |||||||||
| 94 | |||||||||||
| 95 | 0 | my $url=$link->url(); | |||||||||
| 96 | 0 | my $hstr=$self->{"hstr"}; | |||||||||
| 97 | |||||||||||
| 98 | 0 | $hstr -> P; | |||||||||
| 99 | |||||||||||
| 100 | 0 | $hstr->Link_Heading($url, "Link tested okay"); | |||||||||
| 101 | |||||||||||
| 102 | 0 | ▶ | $redir && $self->redirections($link); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 103 | 0 | $self->suggestions($link); | |||||||||
| 104 | |||||||||||
| 105 | 0 | ▶ | if ($self->{"index"}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 106 | 0 | $hstr->page_list( $self->{"index"}->lookup_second($url) ); | |||||||||
| 107 | } | ||||||||||
| 108 | |||||||||||
| 109 | 0 | $hstr -> _P; | |||||||||
| 110 | } | ||||||||||
| 111 | |||||||||||
| 112 | 0 | ▶ | sub damaged { | ||||||||
|
Subroutine
damaged: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 113 | 0 | my ($self, $link, $redir)=@_; | |||||||||
| 114 | |||||||||||
| 115 | 0 | my $url=$link->url(); | |||||||||
| 116 | 0 | my $hstr=$self->{"hstr"}; | |||||||||
| 117 | |||||||||||
| 118 | 0 | $hstr -> P; | |||||||||
| 119 | |||||||||||
| 120 | 0 | $hstr->Link_Heading($url, "Link may be broken"); | |||||||||
| 121 | |||||||||||
| 122 | 0 | ▶ | $redir && $self->redirections($link); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 123 | 0 | $self->suggestions($link); | |||||||||
| 124 | |||||||||||
| 125 | 0 | ▶ | if ($self->{"index"}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 126 | 0 | $hstr->page_list( $self->{"index"}->lookup_second($url) ); | |||||||||
| 127 | } | ||||||||||
| 128 | |||||||||||
| 129 | 0 | $hstr -> _P; | |||||||||
| 130 | } | ||||||||||
| 131 | |||||||||||
| 132 | 0 | ▶ | sub not_checked { | ||||||||
|
Subroutine
not_checked: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 133 | 0 | my ($self, $link )=@_; | |||||||||
| 134 | |||||||||||
| 135 | 0 | my $url=$link->url(); | |||||||||
| 136 | 0 | my $hstr=$self->{"hstr"}; | |||||||||
| 137 | |||||||||||
| 138 | 0 | $hstr -> P; | |||||||||
| 139 | |||||||||||
| 140 | 0 | $hstr->Link_Heading($url, "Link not yet checked"); | |||||||||
| 141 | |||||||||||
| 142 | 0 | $self->suggestions($link); | |||||||||
| 143 | |||||||||||
| 144 | 0 | ▶ | if ($self->{"index"}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 145 | 0 | $hstr->page_list( $self->{"index"}->lookup_second($url) ); | |||||||||
| 146 | } | ||||||||||
| 147 | |||||||||||
| 148 | 0 | $hstr -> _P; | |||||||||
| 149 | } | ||||||||||
| 150 | |||||||||||
| 151 | 0 | ▶ | sub disallowed { | ||||||||
|
Subroutine
disallowed: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 152 | 0 | my ($self, $link)=@_; | |||||||||
| 153 | |||||||||||
| 154 | 0 | my $url=$link->url(); | |||||||||
| 155 | 0 | my $hstr=$self->{"hstr"}; | |||||||||
| 156 | |||||||||||
| 157 | 0 | $hstr -> P; | |||||||||
| 158 | |||||||||||
| 159 | 0 | $hstr->Link_Heading($url, "Link checking not allowed"); | |||||||||
| 160 | |||||||||||
| 161 | 0 | $self->suggestions($link); | |||||||||
| 162 | |||||||||||
| 163 | 0 | ▶ | if ($self->{"index"}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 164 | 0 | $hstr->page_list( $self->{"index"}->lookup_second($url) ); | |||||||||
| 165 | } | ||||||||||
| 166 | |||||||||||
| 167 | 0 | $hstr -> _P; | |||||||||
| 168 | } | ||||||||||
| 169 | |||||||||||
| 170 | 0 | ▶ | sub unsupported { | ||||||||
|
Subroutine
unsupported: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 171 | 0 | my ($self, $link)=@_; | |||||||||
| 172 | |||||||||||
| 173 | 0 | my $url=$link->url(); | |||||||||
| 174 | 0 | my $hstr=$self->{"hstr"}; | |||||||||
| 175 | |||||||||||
| 176 | 0 | $hstr -> P; | |||||||||
| 177 | |||||||||||
| 178 | 0 | $hstr->Link_Heading($url, "Link uses unsupported protocol"); | |||||||||
| 179 | |||||||||||
| 180 | 0 | $self->suggestions($link); | |||||||||
| 181 | |||||||||||
| 182 | 0 | ▶ | if ($self->{"index"}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 183 | 0 | $hstr->page_list( $self->{"index"}->lookup_second($url) ); | |||||||||
| 184 | } | ||||||||||
| 185 | |||||||||||
| 186 | 0 | $hstr -> _P; | |||||||||
| 187 | } | ||||||||||
| 188 | |||||||||||
| 189 | 0 | ▶ | sub unknown { | ||||||||
|
Subroutine
unknown: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 190 | 0 | my ($self, $link)=@_; | |||||||||
| 191 | |||||||||||
| 192 | 0 | my $url=$link->url(); | |||||||||
| 193 | 0 | my $hstr=$self->{"hstr"}; | |||||||||
| 194 | |||||||||||
| 195 | 0 | $hstr -> P; | |||||||||
| 196 | |||||||||||
| 197 | 0 | $hstr->Link_Heading($url, "Link status unknown; error?"); | |||||||||
| 198 | |||||||||||
| 199 | 0 | $self->suggestions($link); | |||||||||
| 200 | |||||||||||
| 201 | 0 | ▶ | if ($self->{"index"}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 202 | 0 | $hstr->page_list( $self->{"index"}->lookup_second($url) ); | |||||||||
| 203 | } | ||||||||||
| 204 | |||||||||||
| 205 | 0 | $hstr -> _P; | |||||||||
| 206 | } | ||||||||||
| 207 | |||||||||||
| 208 | #we should separately deal with temporary redirections (generally | ||||||||||
| 209 | #ignored) and long term redirections (should generally be applied) | ||||||||||
| 210 | |||||||||||
| 211 | 0 | ▶ | sub redirections { | ||||||||
|
Subroutine
redirections: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 212 | 0 | my ($self, $link)=@_; | |||||||||
| 213 | |||||||||||
| 214 | 0 | my $hstr=$self->{"hstr"}; | |||||||||
| 215 | |||||||||||
| 216 | 0 | my @redirects=$link->redirect_urls(); | |||||||||
| 217 | 0 | ▶ | if (@redirects) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 218 | 0 | $hstr -> DL; | |||||||||
| 219 | 0 | foreach my $redir ( @redirects ) { | |||||||||
| 220 | 0 | $hstr -> DT -> t("redirected to") -> _DT | |||||||||
| 221 | -> DD -> Link($redir) -> _DD -> nl; | ||||||||||
| 222 | } | ||||||||||
| 223 | 0 | $hstr -> _DL; | |||||||||
| 224 | } | ||||||||||
| 225 | } | ||||||||||
| 226 | |||||||||||
| 227 | 0 | ▶ | sub suggestions { | ||||||||
|
Subroutine
suggestions: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 228 | 0 | my ($self, $link)=@_; | |||||||||
| 229 | 0 | my $hstr=$self->{"hstr"}; | |||||||||
| 230 | |||||||||||
| 231 | 0 | $hstr -> DL; | |||||||||
| 232 | |||||||||||
| 233 | 0 | my $suggest; | |||||||||
| 234 | 0 | my $suggestions=$link->fix_suggestions(); | |||||||||
| 235 | 0 | ▶ | if ($suggestions) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 236 | 0 | foreach $suggest ( @{$suggestions} ) { | |||||||||
| 237 | 0 | $hstr -> DT -> t("suggest:") -> _DT | |||||||||
| 238 | -> DD -> Link($suggest) -> _DD -> nl; | ||||||||||
| 239 | } | ||||||||||
| 240 | } | ||||||||||
| 241 | 0 | $hstr -> _DL; | |||||||||
| 242 | |||||||||||
| 243 | } | ||||||||||
| 244 | |||||||||||
| 245 | package HTML::Stream::LinkReport; | ||||||||||
| 246 | |||||||||||
| 247 | 1 | our @ISA; | |||||||||
| 248 | 1 | @ISA=qw(HTML::Stream); | |||||||||
| 249 | |||||||||||
| 250 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 251 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 252 | |||||||||||
| 253 | 1 | ▶ | use HTML::Stream; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 254 | |||||||||||
| 255 | 0 | ▶ | sub Heading { | ||||||||
|
Subroutine
Heading: not called CC=1 SCAR=6.9
| |||||||||||
| 256 | 0 | my $self=shift; | |||||||||
| 257 | 0 | $self->HTML | |||||||||
| 258 | ->HEAD | ||||||||||
| 259 | ->TITLE ->t("Link Controller Report.") -> _TITLE | ||||||||||
| 260 | ->_HEAD | ||||||||||
| 261 | ->BODY | ||||||||||
| 262 | ->H1 ->t("Report Contents") -> _H1; | ||||||||||
| 263 | 0 | return $self; | |||||||||
| 264 | } | ||||||||||
| 265 | |||||||||||
| 266 | 0 | ▶ | sub Footer { | ||||||||
|
Subroutine
Footer: not called CC=1 SCAR=6.9
| |||||||||||
| 267 | 0 | my $self=shift; | |||||||||
| 268 | 0 | $self->_BODY | |||||||||
| 269 | ->_HTML; | ||||||||||
| 270 | 0 | return $self; | |||||||||
| 271 | } | ||||||||||
| 272 | |||||||||||
| 273 | =head2 Link_heading | ||||||||||
| 274 | |||||||||||
| 275 | This function simply prints a heading for a link with the url and text | ||||||||||
| 276 | given as arguments. | ||||||||||
| 277 | |||||||||||
| 278 | =cut | ||||||||||
| 279 | |||||||||||
| 280 | 0 | ▶ | sub Link_Heading ($$$) { | ||||||||
|
Subroutine
Link_Heading: not called CC=1 SCAR=6.9
| |||||||||||
| 281 | 0 | my ($self, $url, $text) = @_; | |||||||||
| 282 | 0 | $self -> nl->H2 -> t($text . " ") | |||||||||
| 283 | -> Link($url)-> _H2->nl; | ||||||||||
| 284 | } | ||||||||||
| 285 | |||||||||||
| 286 | =head2 page_list | ||||||||||
| 287 | |||||||||||
| 288 | This takes a list of urls as an argument and generates a unnumbered | ||||||||||
| 289 | html list consisting of those urls inside links to those urls. It is | ||||||||||
| 290 | for use for refering to pages on which urls occur. | ||||||||||
| 291 | |||||||||||
| 292 | Obviously, if the URLs are file urls, then the machine they are being | ||||||||||
| 293 | read on must be the same as the one the file urls refer to. | ||||||||||
| 294 | |||||||||||
| 295 | =cut | ||||||||||
| 296 | |||||||||||
| 297 | 0 | ▶ | sub page_list { | ||||||||
|
Subroutine
page_list: not called CC=2 SCAR=17.9
| |||||||||||
| 298 | 0 | my $self=shift; | |||||||||
| 299 | 0 | my $array=shift; | |||||||||
| 300 | 0 | $self->UL; | |||||||||
| 301 | 0 | foreach (@$array) { | |||||||||
| 302 | 0 | $self -> LI | |||||||||
| 303 | -> Link($_) | ||||||||||
| 304 | -> _LI -> nl; | ||||||||||
| 305 | } | ||||||||||
| 306 | 0 | $self->_UL; | |||||||||
| 307 | 0 | return $self; | |||||||||
| 308 | } | ||||||||||
| 309 | |||||||||||
| 310 | =head2 $LR->Link() | ||||||||||
| 311 | |||||||||||
| 312 | This method puts out a url inside a link refering to that url. I | ||||||||||
| 313 | don't want to encourage this for general use: it's much better to use | ||||||||||
| 314 | a description generally. This program, however, deals directly with | ||||||||||
| 315 | links so it suits us here. | ||||||||||
| 316 | |||||||||||
| 317 | =cut | ||||||||||
| 318 | |||||||||||
| 319 | 0 | ▶ | sub Link { | ||||||||
|
Subroutine
Link: not called CC=1 SCAR=6.9
| |||||||||||
| 320 | 0 | my $self=shift; | |||||||||
| 321 | 0 | my $url=shift; | |||||||||
| 322 | 0 | $self -> A(HREF=>$url) | |||||||||
| 323 | -> t($url) | ||||||||||
| 324 | -> _A ; | ||||||||||
| 325 | 0 | return $self; | |||||||||
| 326 | } | ||||||||||