| 1 | package WWW::Link::Test; | ||
| 2 | $REVISION=q$Revision: 1.6 $ ; $VERSION = sprintf ( "%d.%02d", $REVISION =~ /(\d+).(\d+)/ ); | ||
| 3 | |||
| 4 | =head1 NAME | ||
| 5 | |||
| 6 | WWW::Link::Test - functions for testing links. | ||
| 7 | |||
| 8 | =head1 SYNOPSIS | ||
| 9 | |||
| 10 | use WWW::Link::Test | ||
| 11 | $ua=create_a_user_agent(); | ||
| 12 | $link=get_a_link_object(); | ||
| 13 | WWW::Link::Test::test_link($ua, $link); | ||
| 14 | |||
| 15 | =head1 DESCRIPTION | ||
| 16 | |||
| 17 | At present this package only implements a single function which acts | ||
| 18 | as the glue between a link object and a robot user agent to use the | ||
| 19 | user agent to test a link. | ||
| 20 | |||
| 21 | The link is tested and then given information about what was | ||
| 22 | discovered. The link then records this information for future use.. | ||
| 23 | |||
| 24 | =head1 METHODS | ||
| 25 | |||
| 26 | Only one method currently impemented. The others were done | ||
| 27 | differently but may come back later.. | ||
| 28 | |||
| 29 | =head2 test_link | ||
| 30 | |||
| 31 | This function tests a link by going out to the world and checking it | ||
| 32 | and then telling the associated link object what happened. | ||
| 33 | |||
| 34 | =cut | ||
| 35 | |||
| 36 | use strict; | ||
| 37 | use URI; | ||
| 38 | use WWW::Link; | ||
| 39 | use HTTP::Request | ||
| 40 | |||
| 41 | use vars qw($warn_access); | ||
| 42 | |||
| 43 | sub test_link ($@) { | ||
| 44 | my $user_agent=shift; | ||
| 45 | my $link; | ||
| 46 | foreach $link (@_) { | ||
| 47 | my $url=URI->new($link->url); | ||
| 48 | my $request=new HTTP::Request ('HEAD',$url); | ||
| 49 | print STDERR "sending request\n"; | ||
| 50 | my $response=$user_agent->simple_request($request); | ||
| 51 | print STDERR "got response\n"; | ||
| 52 | #warn on client error | ||
| 53 | |||
| 54 | if ($warn_access) { # warn about links where we can't access it | ||
| 55 | # but someone might | ||
| 56 | print STDERR "didn't have authorisation\n"; | ||
| 57 | } | ||
| 58 | |||
| 59 | |||
| 60 | #examine server errror | ||
| 61 | $link->got_simple_response($response); #how much space is this? | ||
| 62 | if ($response->is_redirect()) { | ||
| 63 | print STDERR "have a redirect: " . $response->header('Location') . "\n"; | ||
| 64 | $response=$user_agent->request($request); | ||
| 65 | $link->got_end_response($response); | ||
| 66 | } | ||
| 67 | } | ||
| 68 | } | ||
| 69 | |||
| 70 | =head2 | ||
| 71 | |||
| 72 | Unconditionally tests all links. NOT IMPLEMENTED | ||
| 73 | |||
| 74 | =cut | ||
| 75 | |||
| 76 | sub test_all_links ($) { | ||
| 77 | my $link_database=shift; | ||
| 78 | while (%$link_database) { | ||
| 79 | die "test_all_links unimplemented"; | ||
| 80 | } | ||
| 81 | } | ||
| 82 | |||
| 83 | =head1 | ||
| 84 | |||
| 85 | Tests links which need it. NOT IMPLEMENTED | ||
| 86 | |||
| 87 | =cut | ||
| 88 | |||
| 89 | sub test_all_needed ($) { | ||
| 90 | my $link_database=shift; | ||
| 91 | #remember you can't alter the contents of the database while going | ||
| 92 | #through it | ||
| 93 | while (%$link_database) { | ||
| 94 | die "test_all_needed unimplemented"; | ||
| 95 | } | ||
| 96 | } | ||
| 97 | |||
| 98 | 1; #kEEp rEqUIrE HaPpY. | ||
| 99 | |||
| 100 |