- From: Ville Skytta via cvs-syncmail <cvsmail@w3.org>
- Date: Thu, 25 May 2006 14:07:54 +0000
- To: www-validator-cvs@w3.org
Update of /sources/public/perl/modules/W3C/LinkChecker/bin In directory hutz:/tmp/cvs-serv18018 Modified Files: checklink Log Message: Code cleanup: eliminate some magic numbers. Index: checklink =================================================================== RCS file: /sources/public/perl/modules/W3C/LinkChecker/bin/checklink,v retrieving revision 4.31 retrieving revision 4.32 diff -u -d -r4.31 -r4.32 --- checklink 25 May 2006 08:50:50 -0000 4.31 +++ checklink 25 May 2006 14:07:52 -0000 4.32 @@ -114,6 +114,8 @@ use constant RC_ROBOTS_TXT => -1; use constant RC_DNS_ERROR => -2; +use constant LINE_UNKNOWN => -1; + @W3C::LinkChecker::ISA = qw(HTML::Parser); BEGIN @@ -1285,7 +1287,7 @@ sub start { my ($self, $tag, $attr, $text, $line) = @_; - $line = -1 unless defined($line); + $line = LINE_UNKNOWN() unless defined($line); # Anchors my $anchor = $self->get_anchor($tag, $attr); @@ -1314,7 +1316,7 @@ sub declaration { my ($self, $text, $line) = @_; - $line = -1 unless defined($line); + $line = LINE_UNKNOWN() unless defined($line); # Extract the doctype my @declaration = split(/\s+/, $text, 4); @@ -1537,6 +1539,20 @@ # Print the results # ##################### +sub line_number ($) +{ + my $line = shift; + return $line if ($line >= 0); + return "(N/A)"; +} + +sub http_rc ($) +{ + my $rc = shift; + return $rc if ($rc >= 0); + return "(N/A)"; +} + sub anchors_summary (\%\%) { my ($anchors, $errors) = @_; @@ -1578,7 +1594,7 @@ foreach my $anchor (@errors) { my $format; - my @unique = &sort_unique(map { $_ < 0 ? "(N/A)" : $_ } + my @unique = &sort_unique(map { line_number($_) } keys %{$anchors->{$anchor}}); if ($Opts{HTML}) { $format = "<tr class=\"broken\"><td>%s</td><td>%s</td></tr>\n"; @@ -1613,7 +1629,7 @@ push (@total_lines, $l); } foreach my $f (keys %{$links->{$u}{fragments}}) { - next if ($f eq $u && defined($links->{$u}{$u}{-1})); + next if ($f eq $u && defined($links->{$u}{$u}{LINE_UNKNOWN()})); foreach my $l (keys %{$links->{$u}{fragments}{$f}}) { push (@total_lines, $l); } @@ -1663,14 +1679,14 @@ $whattodo = 'Add a trailing slash to the URL.'; } - my @unique = &sort_unique(map { $_ < 0 ? "(N/A)" : $_ } @total_lines); + my @unique = &sort_unique(map { line_number($_) } @total_lines); my $lines_list = join(', ', @unique); my $s = (scalar(@unique) > 1) ? 's' : ''; undef @unique; my @http_codes = ($currloc->{code}); unshift(@http_codes, $currloc->{orig}) if $currloc->{orig}; - @http_codes = map { $_ < 0 ? '(N/A)' : $_ } @http_codes; + @http_codes = map { http_rc($_) } @http_codes; if ($Opts{HTML}) { # Style stuff @@ -1944,7 +1960,7 @@ foreach my $code (sort(keys(%code_summary))) { printf('<tr%s>', &bgcolor($code)); printf('<td><a href="#d%scode_%s">%s</a></td>', - $doc_count, $code, $code < 0 ? '(N/A)' : $code); + $doc_count, $code, http_rc($code)); printf('<td>%s</td>', $code_summary{$code}); printf('<td>%s</td>', $todo{$code}); print "</tr>\n";
Received on Thursday, 25 May 2006 14:07:59 UTC