Subject: | Check link only once |
Hi,
Current test implementation collects all the link occurrences and then checks them all. If a link appears in the POD more than once, the test will check the same link more than once too.
Since checking URL involves network activity, it is not fast, and it would be very welcome to checks every unique link only once.
See attached patch.
Subject: | No404s-check-once.patch |
--- No404s.pm.ORIG 2014-11-02 05:37:26.000000000 +0300
+++ No404s.pm 2015-06-16 23:03:12.273750670 +0300
@@ -40,6 +40,7 @@
#pod
#pod =cut
+my %Checked_URLs;
sub pod_file_ok {
my $file = shift;
my $name = @_ ? shift : "404 test for $file";
@@ -101,12 +102,17 @@
my @errors;
my $ua = LWP::UserAgent->new;
foreach my $l ( @links ) {
- $Test->diag( "Checking $l->[0]" );
- my $response = $ua->head( $l->[0] );
+ my $url = $l->[0];
+ if ( exists( $Checked_URLs{ "$url" } ) ) {
+ next;
+ }
+ $Test->diag( "Checking $url" );
+ my $response = $ua->head( $url );
if ( $response->is_error ) {
$ok = 0;
push( @errors, [ $l->[1], $response->status_line ] );
}
+ $Checked_URLs{ "$url" } = 1;
}
$Test->ok( $ok, $name );