| 1 | package SWISH::Prog::Aggregator::Spider; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use base qw( SWISH::Prog::Aggregator ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use Scalar::Util qw( blessed ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use URI; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use HTTP::Cookies; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use HTTP::Date; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use SWISH::Prog::Utils; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use SWISH::Prog::Queue; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use SWISH::Prog::Cache; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use SWISH::Prog::Aggregator::Spider::UA; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 2 | ▶ | use Search::Tools::UTF8; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 2 | ▶ | use XML::Feed; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 2 | ▶ | use WWW::Sitemap::XML; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 2 | ▶ | use File::Rules; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | # TODO tests for cookies, non-text urls needing filters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 2 | __PACKAGE__->mk_accessors( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | qw( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | agent | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | authn_callback | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | credential_timeout | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | credentials | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | delay | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | file_rules | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | follow_redirects | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | keep_alive | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | link_tags | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | max_depth | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | max_files | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | max_size | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | max_time | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | md5_cache | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | modified_since | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | queue | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | remove_leading_dots | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | same_hosts | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | timeout | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | ua | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | uri_cache | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | use_md5 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | #use LWP::Debug qw(+); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 2 | our $VERSION = '0.75'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | # TODO make these configurable | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 2 | my %parser_types = %SWISH::Prog::Utils::ParserTypes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 2 | my $default_ext = $SWISH::Prog::Utils::ExtRE; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 2 | my $utils = 'SWISH::Prog::Utils'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | =pod | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | SWISH::Prog::Aggregator::Spider - web aggregator | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | use SWISH::Prog::Aggregator::Spider; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | my $spider = SWISH::Prog::Aggregator::Spider->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | indexer => SWISH::Prog::Indexer->new | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | $spider->indexer->start; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | $spider->crawl( 'http://swish-e.org/' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | $spider->indexer->finish; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | SWISH::Prog::Aggregator::Spider is a web crawler similar to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | the spider.pl script in the Swish-e 2.4 distribution. Internally, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | SWISH::Prog::Aggregator::Spider uses LWP::RobotUA to do the hard work. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | See L<SWISH::Prog::Aggregator::Spider::UA>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | See L<SWISH::Prog::Aggregator>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | =head2 new( I<params> ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | All I<params> have their own get/set methods too. They include: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | =over | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | =item agent I<string> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | Get/set the user-agent string reported by the user agent. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | =item email I<string> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | Get/set the email string reported by the user agent. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | =item use_md5 I<1|0> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | Flag as to whether each URI's content should be fingerprinted | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | and compared. Useful if the same content is available under multiple | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | URIs and you only want to index it once. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | =item uri_cache I<cache_object> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | Get/set the SWISH::Prog::Cache-derived object used to track which URIs have | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | been fetched already. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | =item md5_cache I<cache_object> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | If use_md5() is true, this SWISH::Prog::Cache-derived object tracks | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | the URI fingerprints. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | =item file_rules I<File_Rules_or_ARRAY> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | Apply L<File::Rules> object in uri_ok(). I<File_Rules_or_ARRAY> should | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | be a L<File::Rules> object or an array of strings suitable to passing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | to File::Rules->new(). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | =item queue I<queue_object> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | Get/set the SWISH::Prog::Queue-derived object for tracking which URIs still | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | need to be fetched. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | =item ua I<lwp_useragent> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | Get/set the SWISH::Prog::Aggregagor::Spider::UA object. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | =item max_depth I<n> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | How many levels of links to follow. B<NOTE:> This value describes the number | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | of links from the first argument passed to I<crawl>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | Default is unlimited depth. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | =item max_time I<n> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | This optional key will set the max minutes to spider. Spidering | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | for this host will stop after C<max_time> seconds, and move on to the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | next server, if any. The default is to not limit by time. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | =item max_files I<n> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | This optional key sets the max number of files to spider before aborting. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | The default is to not limit by number of files. This is the number of requests | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | made to the remote server, not the total number of files to index (see C<max_indexed>). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | This count is displayted at the end of indexing as C<Unique URLs>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | This feature can (and perhaps should) be use when spidering a web site where dynamic | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | content may generate unique URLs to prevent run-away spidering. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | =item max_size I<n> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | This optional key sets the max size of a file read from the web server. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | This B<defaults> to 5,000,000 bytes. If the size is exceeded the resource is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | truncated per LWP::UserAgent. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | Set max_size to zero for unlimited size. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | =item modified_since I<date> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | This optional parameter will skip any URIs that do not report having | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | been modified since I<date>. The C<Last-Modified> HTTP header is used to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | determine modification time. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | =item keep_alive I<1|0> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | This optional parameter will enable keep alive requests. This can dramatically speed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | up spidering and reduce the load on server being spidered. The default is to not use | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | keep alives, although enabling it will probably be the right thing to do. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | To get the most out of keep alives, you may want to set up your web server to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | allow a lot of requests per single connection (i.e MaxKeepAliveRequests on Apache). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | Apache's default is 100, which should be good. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | When a connection is not closed the spider does not wait the "delay" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | time when making the next request. In other words, there is no delay in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | requesting documents while the connection is open. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | Note: you must have at least libwww-perl-5.53_90 installed to use this feature. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | =item delay I<n> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | Get/set the number of seconds to wait between making requests. Default is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 5 seconds (a very friendly delay). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | =item timeout I<n> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | Get/set the number of seconds to wait before considering the remote | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | server unresponsive. The default is 10. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | =item authn_callback I<code_ref> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | CODE reference to fetch username/password credentials when necessary. See also | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | C<credentials>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | =item credential_timeout I<n> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | Number of seconds to wait before skipping manual prompt for username/password. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | =item credentials I<user:pass> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | String with C<username>:C<password> pair to be used when prompted by | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | the server. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | =item follow_redirects I<1|0> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | By default, 3xx responses from the server will be followed when | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | they are on the same hostname. Set to false (0) to not follow | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | redirects. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | =item link_tags | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | TODO | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | =item remove_leading_dots I<1|0> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | Microsoft server hack. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | =item same_hosts I<array_ref> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | ARRAY ref of hostnames to be treated as identical to the original | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | host being spidered. By default the spider will not follow | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | links to different hosts. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | =head2 init | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | Initializes a new spider object. Called by new(). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 1 | ▶ | sub init { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=37 SCAR=50.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 1 | $self->SUPER::init(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | # defaults | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 1 | ▶ | $self->{agent} ||= 'swish-prog-spider http://swish-e.org/'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{"agent"} ||= "swish-prog-spider http://swish-e.org/"
MC/DC0%0/1
$self->{"agent"} ||= "swish-prog-spider http://swish-e.org/"
$self->{"agent"}
Truth table50%1/2
A
A= $self->{"agent"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 1 | ▶ | $self->{email} ||= 'swish@user.failed.to.set.email.invalid'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{"email"} ||= "swish\@user.failed.to.set.email.invalid"
MC/DC0%0/1
$self->{"email"} ||= "swish\@user.failed.to.set.email.invalid"
$self->{"email"}
Truth table50%1/2
A
A= $self->{"email"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 1 | ▶ | $self->{use_cookies} = 1 unless defined $self->{use_cookies}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 1 | ▶ | $self->{follow_redirects} = 1 unless defined $self->{follow_redirects}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 1 | ▶ | $self->{max_files} = 0 unless defined $self->{max_files}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 1 | ▶ | $self->{max_size} = 5_000_000 unless defined $self->{max_size}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 1 | ▶ | $self->{max_depth} = undef unless defined( $self->{max_depth} ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 1 | ▶ | $self->{delay} = 5 unless defined $self->{delay}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 1 | ▶ | croak "delay must be expressed in seconds" if $self->{delay} =~ m/\D/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 1 | ▶ | if ( $self->{modified_since} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | my $epoch | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | = $self->{modified_since} =~ m/\D/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | ? str2time( $self->{modified_since} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 1 | ▶ | : $self->{modified_since}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 1 | ▶ | if ( !defined $epoch ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | croak | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | "Invalid datetime in modified_since: $self->{modified_since}"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 1 | $self->{modified_since} = $epoch; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | $self->{credential_timeout} = 30 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 1 | ▶ | unless exists $self->{credential_timeout}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | croak "credential_timeout must be a number" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | if defined $self->{credential_timeout} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 1 | ▶ | and $self->{credential_timeout} =~ m/\D/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $self->{"credential_timeout"} and $self->{"credential_timeout"} =~ /\D/
MC/DC0%0/2
defined $self->{"credential_timeout"} and $self->{"credential_timeout"} =~ /\D/
defined $self->{"credential_timeout"}
$self->{"credential_timeout"} =~ /\D/
Truth table33%1/3
A and B
A= defined $self->{"credential_timeout"}B= $self->{"credential_timeout"} =~ /\D/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 1 | ▶ | $self->{queue} ||= SWISH::Prog::Queue->new; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$self->{"queue"} ||= "SWISH::Prog::Queue"->new
MC/DC0%0/2
$self->{"queue"} ||= "SWISH::Prog::Queue"->new
$self->{"queue"}
"SWISH::Prog::Queue"->new
Truth table33%1/3
A ||= B
A= $self->{"queue"}B= "SWISH::Prog::Queue"->new
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 1 | ▶ | $self->{uri_cache} ||= SWISH::Prog::Cache->new; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$self->{"uri_cache"} ||= "SWISH::Prog::Cache"->new
MC/DC0%0/2
$self->{"uri_cache"} ||= "SWISH::Prog::Cache"->new
$self->{"uri_cache"}
"SWISH::Prog::Cache"->new
Truth table33%1/3
A ||= B
A= $self->{"uri_cache"}B= "SWISH::Prog::Cache"->new
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 1 | $self->{_auth_cache} = SWISH::Prog::Cache->new; # ALWAYS inmemory cache | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | $self->{ua} ||= SWISH::Prog::Aggregator::Spider::UA->new( $self->{agent}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 1 | ▶ | $self->{email}, ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$self->{"ua"} ||= "SWISH::Prog::Aggregator::Spider::UA"->new($self->{"agent"}, $self->{"email"})
MC/DC0%0/2
$self->{"ua"} ||= "SWISH::Prog::Aggregator::Spider::UA"->new($self->{"agent"}, $self->{"email"})
$self->{"ua"}
"SWISH::Prog::Aggregator::Spider::UA"->new($self->{"agent"}, $self->{"email"})
Truth table33%1/3
A ||= B
A= $self->{"ua"}B= "SWISH::Prog::Aggregator::Spider::UA"->new($self->{"agent"}, $self->{"email"})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | # whitelist which HTML tags we consider "links" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | # should be subset of what HTML::LinkExtor considers links | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | $self->{link_tags} = [ 'a', 'frame', 'iframe' ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 1 | ▶ | unless ref $self->{link_tags} eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | $self->{ua} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 1 | ->set_link_tags( { map { lc($_) => 1 } @{ $self->{link_tags} } } ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 1 | ▶ | $self->{timeout} = 10 unless defined $self->{timeout}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 1 | ▶ | croak "timeout must be a number" if $self->{timeout} =~ m/\D/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | # we handle our own delay | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 1 | $self->{ua}->delay(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 1 | $self->{ua}->timeout( $self->{timeout} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | # TODO we test this using HEAD request. Set here too? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | #$self->{ua}->max_size( $self->{max_size} ) if $self->{max_size}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 1 | ▶ | if ( $self->{use_cookies} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 1 | $self->{ua}->cookie_jar( HTTP::Cookies->new() ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 1 | ▶ | if ( $self->{keep_alive} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | ▶ | if ( $self->{ua}->can('conn_cache') ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | my $keep_alive | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | = $self->{keep_alive} =~ m/^\d+$/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | ? $self->{keep_alive} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | ▶ | : 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | $self->{ua}->conn_cache( { total_capacity => $keep_alive } ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | warn | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | "can't use keep-alive: conn_cache() method not available on ua " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 0 | . ref( $self->{ua} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 1 | $self->{_current_depth} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 1 | ▶ | $self->{same_hosts} ||= []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{"same_hosts"} ||= []
MC/DC0%0/1
$self->{"same_hosts"} ||= []
$self->{"same_hosts"}
Truth table50%1/2
A
A= $self->{"same_hosts"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 1 | $self->{same_host_lookup} = { map { $_ => 1 } @{ $self->{same_hosts} } }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 1 | ▶ | if ( $self->{use_md5} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | ▶ | eval "require Digest::MD5" or croak $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | ▶ | $self->{md5_cache} ||= SWISH::Prog::Cache->new; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$self->{"md5_cache"} ||= "SWISH::Prog::Cache"->new
MC/DC0%0/2
$self->{"md5_cache"} ||= "SWISH::Prog::Cache"->new
$self->{"md5_cache"}
"SWISH::Prog::Cache"->new
Truth table0%0/3
A ||= B
A= $self->{"md5_cache"}B= "SWISH::Prog::Cache"->new
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | # if SWISH::Prog::Config defined, use that for some items | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 1 | ▶ | if ( $self->{indexer} and $self->config ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"indexer"} and $self->config
MC/DC0%0/2
$self->{"indexer"} and $self->config
$self->{"indexer"}
$self->config
Truth table33%1/3
A and B
A= $self->{"indexer"}B= $self->config
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | ▶ | if ( $self->config->FileRules && !$self->{file_rules} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->config->FileRules and not $self->{"file_rules"}
MC/DC0%0/2
$self->config->FileRules and not $self->{"file_rules"}
$self->config->FileRules
not $self->{"file_rules"}
Truth table0%0/3
A and not(B)
A= $self->config->FileRulesB= not $self->{"file_rules"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | $self->{file_rules} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | = File::Rules->new( $self->config->FileRules ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | # make it an object if it is just an array | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 1 | ▶ | if ( $self->{file_rules} and !blessed( $self->{file_rules} ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"file_rules"} and not builtin::blessed($self->{"file_rules"})
MC/DC0%0/2
$self->{"file_rules"} and not builtin::blessed($self->{"file_rules"})
$self->{"file_rules"}
not builtin::blessed($self->{"file_rules"})
Truth table33%1/3
A and not(B)
A= $self->{"file_rules"}B= not builtin::blessed($self->{"file_rules"})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 1 | $self->{file_rules} = File::Rules->new( $self->{file_rules} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | # from spider.pl. not sure if we need it or not. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | # Lame Microsoft | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 1 | ▶ | $URI::ABS_REMOTE_LEADING_DOTS = $self->{remove_leading_dots} ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 1 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | =head2 uri_ok( I<uri> ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | Returns true if I<uri> is acceptable for including in an index. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | The 'ok-ness' of the I<uri> is based on its base, robot rules, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | and the spider configuration. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 17 | ▶ | sub uri_ok { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
uri_ok: called CC=33 SCAR=41.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 17 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 17 | ▶ | my $uri = shift or croak "URI required"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 17 | my $str = $uri->canonical->as_string; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 17 | $str =~ s/#.*//; # target anchors create noise | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 17 | ▶ | if ( $self->verbose > 1 || $self->debug ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->verbose > 1 or $self->debug
MC/DC0%0/2
$self->verbose > 1 or $self->debug
$self->verbose > 1
$self->debug
Truth table33%1/3
A or B
A= $self->verbose > 1B= $self->debug
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | $self->write_log_line(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | $self->write_log( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | uri => $uri, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | msg => "checking if ok", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 17 | ▶ | if ( $uri->scheme !~ m,^http, ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 0 | ▶ | $self->debug and $self->write_log( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | uri => $uri, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | msg => "skipping, unsupported scheme" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | # check if we're on the same host. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 17 | ▶ | if ( $uri->rel( $self->{_base} ) eq $uri ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | # not on this host. check our aliases | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 3 | ▶ | if ( !exists $self->{same_host_lookup} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$uri->canonical->authority || ''
MC/DC0%0/1
$uri->canonical->authority || ''
$uri->canonical->authority
Truth table50%1/2
A
A= $uri->canonical->authority
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | ->{ $uri->canonical->authority || '' } ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 2 | my $host = $uri->canonical->authority; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 2 | ▶ | $self->debug | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | and $self->write_log( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | uri => $uri, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | msg => "skipping, different host $host", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 2 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | # in same host lookup, so proceed. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 15 | my $path = $uri->path; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 15 | my $mime = $utils->mime_type($path); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 15 | ▶ | if ( !exists $parser_types{$mime} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 0 | ▶ | $self->debug and $self->write_log( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | uri => $uri, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | msg => "skipping, no parser for $mime", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | # check regex | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 15 | ▶ | if ( $self->file_rules ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 15 | ▶ | if ( $self->_apply_file_rules( $uri->path_query, $self->file_rules ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->_apply_file_rules($uri->path_query, $self->file_rules) and not $self->_apply_file_match($uri->path_query, $self->file_rules)
MC/DC50%1/2
$self->_apply_file_rules($uri->path_query, $self->file_rules) and not $self->_apply_file_match($uri->path_query, $self->file_rules)
$self->_apply_file_rules($uri->path_query, $self->file_rules)
not $self->_apply_file_match($uri->path_query, $self->file_rules)
Truth table66%2/3
A and not(B)
A= $self->_apply_file_rules($uri->path_query, $self->file_rules)B= not $self->_apply_file_match($uri->path_query, $self->file_rules)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | && !$self->_apply_file_match( $uri->path_query, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | $self->file_rules ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 2 | ▶ | $self->debug and $self->write_log( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | uri => $uri, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | msg => "skipping, matched file_rules", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 2 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | # head request to check max_size and modified_since | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 13 | ▶ | if ( $self->max_size or $self->modified_since ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->max_size or $self->modified_since
MC/DC0%0/2
$self->max_size or $self->modified_since
$self->max_size
$self->modified_since
Truth table33%1/3
A or B
A= $self->max_sizeB= $self->modified_since
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 13 | my %head_args = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | uri => $uri, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | delay => 0, # assume each get() applies the delay | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | debug => $self->debug, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | verbose => $self->verbose, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 13 | ▶ | if ( my ( $user, $pass ) = $self->_get_user_pass($uri) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 13 | $head_args{user} = $user; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 13 | $head_args{pass} = $pass; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 13 | my $resp = $self->ua->head(%head_args); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | # early abort if resource doesn't exist | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 13 | ▶ | if ( $resp->status == 404 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 3 | ▶ | $self->debug | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | and $self->write_log( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | uri => $uri, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | msg => "skipping, 404 not found", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 3 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | # redirect? assume ok now and _make_request will check on it later. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 10 | ▶ | if ( $resp->is_redirect ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 3 | ▶ | $self->debug | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | and $self->write_log( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | uri => $uri, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | msg => "deferring, is_redirect", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 3 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 7 | my $last_mod = $resp->last_modified; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 7 | ▶ | if ( $last_mod | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$last_mod and $self->modified_since and $self->modified_since > $last_mod
$last_mod and $self->modified_since
MC/DC33%1/3
$last_mod and $self->modified_since and $self->modified_since > $last_mod
$last_mod
$self->modified_since
$self->modified_since > $last_mod
Truth table50%2/4
A and B and C
A= $last_modB= $self->modified_sinceC= $self->modified_since > $last_mod
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | and $self->modified_since | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | and $self->modified_since > $last_mod ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 1 | ▶ | $self->debug | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | and $self->write_log( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | uri => $uri, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | msg => sprintf( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | "skipping, last modified %s (%s < %s)", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | $resp->header('last-modified'), $last_mod, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | $self->modified_since | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 6 | ▶ | if ( $resp->content_length and $self->max_size ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$resp->content_length and $self->max_size
MC/DC50%1/2
$resp->content_length and $self->max_size
$resp->content_length
$self->max_size
Truth table66%2/3
A and B
A= $resp->content_lengthB= $self->max_size
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 1 | ▶ | if ( $resp->content_length > $self->max_size ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 1 | ▶ | $self->debug | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | and $self->write_log( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | uri => $uri, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | msg => sprintf( "skipping, %s > max_size", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | $resp->content_length ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | 5 | ▶ | ( $self->verbose > 1 || $self->debug ) and $self->write_log( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->verbose > 1 or $self->debug
MC/DC0%0/2
$self->verbose > 1 or $self->debug
$self->verbose > 1
$self->debug
Truth table33%1/3
A or B
A= $self->verbose > 1B= $self->debug
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | uri => $uri, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | msg => "ok", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 5 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | 9 | ▶ | sub _add_links { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_add_links: called CC=10 SCAR=23.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | 9 | my ( $self, $parent, @links ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | # calc depth | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | 9 | ▶ | if ( !$self->{_parent} || $self->{_parent} ne $parent ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $self->{"_parent"} or $self->{"_parent"} ne $parent
MC/DC0%0/2
not $self->{"_parent"} or $self->{"_parent"} ne $parent
not $self->{"_parent"}
$self->{"_parent"} ne $parent
Truth table66%2/3
not(A) or B
A= not $self->{"_parent"}B= $self->{"_parent"} ne $parent
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 9 | $self->{_current_depth}++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 9 | ▶ | $self->{_parent} ||= $parent; # first time. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$self->{"_parent"} ||= $parent
MC/DC0%0/2
$self->{"_parent"} ||= $parent
$self->{"_parent"}
$parent
Truth table66%2/3
A ||= B
A= $self->{"_parent"}B= $parent
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 9 | ▶ | $self->debug and $self->write_log( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | uri => $parent, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | msg => sprintf( 'evaluating %s links', scalar(@links) ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | 9 | for my $l (@links) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | 19 | ▶ | my $uri = $l->abs( $self->{_base} ) or next; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | 19 | $uri = $uri->canonical; # normalize | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | 19 | ▶ | if ( $self->uri_cache->has("$uri") ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | 2 | ▶ | $self->debug and $self->write_log( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | uri => $uri, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | msg => "skipping, already checked", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | 2 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | 17 | $self->uri_cache->add( "$uri" => $self->{_current_depth} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | 17 | ▶ | if ( $self->uri_ok($uri) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 8 | $self->add_to_queue($uri); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | # ported from spider.pl | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | # Do we need to authorize? If so, ask for password and request again. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | # First we try using any cached value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | # Then we try using the get_password callback | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | # Then we ask. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | 0 | ▶ | sub _authorize { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_authorize: not called CC=13 SCAR=52.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | 0 | my ( $self, $uri, $response ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 0 | delete $self->{last_auth}; # since we know that doesn't work | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | 0 | ▶ | if ( $response->header('WWW-Authenticate') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$response->header("WWW-Authenticate") and $response->header("WWW-Authenticate") =~ /realm="([^"]+)"/i
MC/DC0%0/2
$response->header("WWW-Authenticate") and $response->header("WWW-Authenticate") =~ /realm="([^"]+)"/i
$response->header("WWW-Authenticate")
$response->header("WWW-Authenticate") =~ /realm="([^"]+)"/i
Truth table0%0/3
A and B
A= $response->header("WWW-Authenticate")B= $response->header("WWW-Authenticate") =~ /realm="([^"]+)"/i
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | && $response->header('WWW-Authenticate') =~ /realm="([^"]+)"/i ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | 0 | my $realm = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | 0 | my $user_pass; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | # Do we have a cached user/pass for this realm? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | # only each URI only once | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | 0 | ▶ | unless ( $self->{_request}->{auth}->{$uri}++ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | 0 | my $key = $uri->canonical->host_port . ':' . $realm; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | 0 | ▶ | if ( $user_pass = $self->{_auth_cache}->get($key) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | # If we didn't just try it, try again | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | 0 | ▶ | unless ( $uri->userinfo && $user_pass eq $uri->userinfo ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$uri->userinfo and $user_pass eq $uri->userinfo
MC/DC0%0/2
$uri->userinfo and $user_pass eq $uri->userinfo
$uri->userinfo
$user_pass eq $uri->userinfo
Truth table0%0/3
A and B
A= $uri->userinfoB= $user_pass eq $uri->userinfo
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | # add the user/pass to the URI | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | 0 | $uri->userinfo($user_pass); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | #warn " >> set userinfo via _auth_cache\n" if $self->debug; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | # we've tried this before | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | #warn "tried $user_pass before"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | # now check for a callback password (if $user_pass not set) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | 0 | ▶ | unless ( $user_pass || $self->{_request}->{auth}->{callback}++ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$user_pass or $self->{"_request"}{"auth"}{"callback"}++
MC/DC0%0/2
$user_pass or $self->{"_request"}{"auth"}{"callback"}++
$user_pass
$self->{"_request"}{"auth"}{"callback"}++
Truth table0%0/3
A or B
A= $user_passB= $self->{"_request"}{"auth"}{"callback"}++
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | # Check for a callback function | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | 0 | ▶ | if ( $self->{authn_callback} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"authn_callback"} and ref $self->{"authn_callback"} eq "CODE"
MC/DC0%0/2
$self->{"authn_callback"} and ref $self->{"authn_callback"} eq "CODE"
$self->{"authn_callback"}
ref $self->{"authn_callback"} eq "CODE"
Truth table0%0/3
A and B
A= $self->{"authn_callback"}B= ref $self->{"authn_callback"} eq "CODE"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | and ref $self->{authn_callback} eq 'CODE' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | $user_pass = $self->{authn_callback} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | 0 | ->( $self, $uri, $response, $realm ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | 0 | $uri->userinfo($user_pass); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | #warn " >> set userinfo via authn_callback\n" if $self->debug; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | # otherwise, prompt (over and over) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | 0 | ▶ | if ( !$user_pass ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | 0 | $user_pass = $self->_get_basic_credentials( $uri, $realm ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | 0 | ▶ | if ($user_pass) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | 0 | $uri->userinfo($user_pass); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | 0 | $self->{cur_realm} = $realm; # save so we can cache if it's valid | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | # From spider.pl | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | 0 | ▶ | sub _get_basic_credentials { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_basic_credentials: not called CC=11 SCAR=48.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | 0 | my ( $self, $uri, $realm ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | # Exists but undefined means don't ask. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | return | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | if exists $self->{credential_timeout} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | 0 | ▶ | && !defined $self->{credential_timeout}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $self->{"credential_timeout"} and not defined $self->{"credential_timeout"}
MC/DC0%0/2
exists $self->{"credential_timeout"} and not defined $self->{"credential_timeout"}
exists $self->{"credential_timeout"}
not defined $self->{"credential_timeout"}
Truth table0%0/3
A and not(B)
A= exists $self->{"credential_timeout"}B= not defined $self->{"credential_timeout"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | 0 | my $netloc = $uri->canonical->host_port; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | 0 | my ( $user, $password ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | 0 | eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | 0 | ▶ | local $SIG{ALRM} = sub { die "timed out\n" }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | # a zero timeout means don't time out | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | 0 | ▶ | alarm( $self->{credential_timeout} ) unless $^O =~ /Win32/i; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | 0 | ▶ | if ( $uri->userinfo ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | 0 | print STDERR "\nSorry: invalid username/password\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | 0 | $uri->userinfo(undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | 0 | print STDERR | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | "Need Authentication for $uri at realm '$realm'\n(<Enter> skips)\nUsername: "; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | 0 | $user = <STDIN>; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | 0 | ▶ | chomp($user) if $user; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | 0 | ▶ | die "No Username specified\n" unless length $user; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | 0 | ▶ | alarm( $self->{credential_timeout} ) unless $^O =~ /Win32/i; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | 0 | print STDERR "Password: "; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | 0 | system("stty -echo"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | 0 | $password = <STDIN>; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | 0 | system("stty echo"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | 0 | print STDERR "\n"; # because we disabled echo | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | 0 | chomp($password); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | 0 | ▶ | alarm(0) unless $^O =~ /Win32/i; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | 0 | ▶ | alarm(0) unless $^O =~ /Win32/i; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | 0 | ▶ | return if $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | 0 | return join ':', $user, $password; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | =head2 add_to_queue( I<uri> ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | Add I<uri> to the queue. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | 9 | ▶ | sub add_to_queue { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_to_queue: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | 9 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | 9 | ▶ | my $uri = shift or croak "uri required"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | 9 | return $self->queue->put($uri); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | =head2 next_from_queue | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | Return next I<uri> from queue. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | 9 | ▶ | sub next_from_queue { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
next_from_queue: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | 9 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | 9 | return $self->queue->get(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | =head2 left_in_queue | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | Returns queue()->size(). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | 10 | ▶ | sub left_in_queue { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
left_in_queue: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | 10 | return shift->queue->size(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | =head2 remove_from_queue( I<uri> ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | Calls queue()->remove(I<uri>). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | 9 | ▶ | sub remove_from_queue { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
remove_from_queue: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | 9 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | 9 | ▶ | my $uri = shift or croak "uri required"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | 9 | return $self->queue->remove($uri); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | =head2 get_doc | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | Returns the next URI from the queue() as a SWISH::Prog::Doc object, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | or the error message if there was one. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | Returns undef if the queue is empty or max_depth() has been reached. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | 10 | ▶ | sub get_doc { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_doc: called CC=7 SCAR=21.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | 10 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | # return unless we have something in the queue | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | 10 | ▶ | return unless $self->left_in_queue(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | # pop the queue and make it a URI | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | 9 | my $uri = $self->next_from_queue(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | 9 | my $depth = $self->uri_cache->get("$uri"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | 9 | ▶ | $self->debug | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$self->max_depth || 'undef'
MC/DC0%0/1
$self->max_depth || 'undef'
$self->max_depth
Truth table0%0/2
A
A= $self->max_depth
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | and $self->write_log( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | uri => $uri, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | msg => sprintf( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | "depth:%d max_depth:%s", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | $depth, ( $self->max_depth || 'undef' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | 9 | ▶ | return if defined $self->max_depth && $depth > $self->max_depth; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $self->max_depth and $depth > $self->max_depth
MC/DC0%0/2
defined $self->max_depth and $depth > $self->max_depth
defined $self->max_depth
$depth > $self->max_depth
Truth table33%1/3
A and B
A= defined $self->max_depthB= $depth > $self->max_depth
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | 9 | $self->{_cur_depth} = $depth; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | 9 | my $doc = $self->_make_request($uri); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | 9 | ▶ | if ($doc) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | 9 | $self->remove_from_queue($uri); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | 9 | return $doc; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 734 | =head2 get_authorized_doc( I<uri>, I<response> ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 735 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 736 | Called internally when the server returns a 401 or 403 response. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 737 | Will attempt to determine the correct credentials for I<uri> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 738 | based on the previous attempt in I<response> and what you | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 739 | have configured in B<credentials>, B<authn_callback> or when | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 740 | manually prompted. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 741 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 742 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 743 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 744 | 0 | ▶ | sub get_authorized_doc { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_authorized_doc: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 745 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 746 | 0 | ▶ | my $uri = shift or croak "uri required"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 747 | 0 | ▶ | my $response = shift or croak "response required"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 748 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 749 | # set up credentials | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 750 | 0 | ▶ | $self->_authorize( $uri, $response->http_response ) or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 751 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 752 | 0 | return $self->_make_request($uri); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 753 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 754 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 755 | 9 | ▶ | sub _make_request { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_make_request: called CC=43 SCAR=57.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 756 | 9 | my ( $self, $uri ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 757 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 758 | # get our useragent | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 759 | 9 | my $ua = $self->ua; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 760 | 9 | my $delay = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 761 | 9 | ▶ | if ( $self->{keep_alive} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 762 | 0 | $delay = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 763 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 764 | ▶ | elsif ( !$self->{delay} or !$self->{_last_response_time} ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$self->{'delay'} && $self->{'_last_response_time'}
MC/DC0%0/2
$self->{'delay'} && $self->{'_last_response_time'}
$self->{'delay'}
$self->{'_last_response_time'}
Truth table33%1/3
A && B
A= $self->{'delay'}B= $self->{'_last_response_time'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 765 | 9 | $delay = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 766 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 767 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 768 | 0 | my $elapsed = time() - $self->{_last_response_time}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 769 | 0 | $delay = $self->{delay} - $elapsed; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 770 | 0 | ▶ | $delay = 0 if $delay < 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 771 | 0 | ▶ | $self->debug | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 772 | and $self->write_log( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 773 | uri => $uri, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 774 | msg => "elapsed:$elapsed delay:$delay", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 775 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 776 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 777 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 778 | 9 | ▶ | $self->write_log( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 779 | uri => $uri, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 780 | msg => "GET delay:$delay", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 781 | ) if $self->verbose; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 782 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 783 | 9 | my %get_args = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 784 | uri => $uri, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 785 | delay => $delay, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 786 | debug => $self->debug, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 787 | verbose => $self->verbose, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 788 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 789 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 790 | 9 | ▶ | if ( my ( $user, $pass ) = $self->_get_user_pass($uri) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 791 | 9 | $get_args{user} = $user; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 792 | 9 | $get_args{pass} = $pass; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 793 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 794 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 795 | # fetch the uri. $ua handles delay internally. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 796 | 9 | my $response = $ua->get(%get_args); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 797 | 9 | my $http_response = $response->http_response; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 798 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 799 | # flag current time for next delay calc. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 800 | 9 | $self->{_last_response_time} = time(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 801 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 802 | # redirect? follow, conditionally. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 803 | 9 | ▶ | if ( $response->is_redirect ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 804 | 3 | my $location = $response->header('location'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 805 | 3 | ▶ | if ( !$location ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 806 | 0 | $self->write_log( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 807 | uri => $uri, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 808 | msg => "skipping, redirect without a Location header", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 809 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 810 | 0 | return $response->status; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 811 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 812 | $self->debug | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 813 | 3 | ▶ | and $self->write_log( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 814 | uri => $uri, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 815 | msg => "redirect: $location", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 816 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 817 | 3 | ▶ | if ( $self->follow_redirects ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 818 | 3 | $self->_add_links( $uri, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 819 | URI->new_abs( $location, $http_response->base ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 820 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 821 | 3 | return $response->status; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 822 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 823 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 824 | 6 | ▶ | if ( $response->ct ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 825 | 6 | ▶ | $self->debug and $self->write_log( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 826 | uri => $uri, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 827 | msg => 'content-type: ' . $response->ct, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 828 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 829 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 830 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 831 | # add its links to the queue. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 832 | # If the resource looks like an XML feed of some kind, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 833 | # glean its links differently than if it is an HTML response. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 834 | 6 | ▶ | if ( my $feed = $self->looks_like_feed($http_response) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 835 | 0 | ▶ | $self->debug and $self->write_log( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 836 | uri => $uri, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 837 | msg => 'looks like feed' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 838 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 839 | 0 | my @links; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 840 | 0 | for my $entry ( $feed->entries ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 841 | 0 | push @links, URI->new( $entry->link ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 842 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 843 | 0 | $self->_add_links( $uri, @links ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 844 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 845 | # we don't want the feed content, we want the links. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 846 | # TODO make this optional | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 847 | 0 | return $response->status; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 848 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 849 | elsif ( my $sitemap = $self->looks_like_sitemap($http_response) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 850 | 0 | ▶ | $self->debug and $self->write_log( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 851 | uri => $uri, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 852 | msg => 'looks like sitemap', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 853 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 854 | 0 | my @links; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 855 | 0 | for my $url ( $sitemap->urls ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 856 | 0 | push @links, URI->new( $url->loc ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 857 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 858 | 0 | $self->_add_links( $uri, @links ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 859 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 860 | # we don't want the feed content, we want the links. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 861 | # TODO make this optional | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 862 | 0 | return $response->status; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 863 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 864 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 865 | 6 | $self->_add_links( $uri, $response->links ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 866 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 867 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 868 | # return $uri as a Doc object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 869 | 6 | ▶ | my $use_uri = $response->success ? $ua->uri : $uri; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 870 | my $meta = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 871 | org_uri => $uri, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 872 | ret_uri => ( $use_uri || $uri ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 873 | depth => delete $self->{_cur_depth}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 874 | 6 | ▶ | status => $response->status, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition60%3/5
$use_uri || $uri
$response->title or "No title: $use_uri"
MC/DC0%0/2
$use_uri || $uri
$use_uri
$uri
MC/DC100%1/1
$response->title or "No title: $use_uri"
$response->title
Truth table33%1/3
A || B
A= $use_uriB= $uri
Truth table100%2/2
A
A= $response->title
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 875 | success => $response->success, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 876 | is_html => $response->is_html, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 877 | title => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 878 | $response->success | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 879 | ? ( $response->is_html | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 880 | ? ( $response->title || "No title: $use_uri" ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 881 | : $use_uri | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 882 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 883 | : "Failed: $use_uri" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 884 | ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 885 | ct => ( $response->success ? $response->ct : "Unknown" ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 886 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 887 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 888 | 6 | my $headers = $http_response->headers; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 889 | 6 | my $buf = $response->content; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 890 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 891 | 6 | ▶ | if ( $self->{use_md5} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 892 | 0 | ▶ | my $fingerprint = $response->header('Content-MD5') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$response->header('Content-MD5') || Digest::MD5::md5_base64($buf)
MC/DC0%0/2
$response->header('Content-MD5') || Digest::MD5::md5_base64($buf)
$response->header('Content-MD5')
Digest::MD5::md5_base64($buf)
Truth table0%0/3
A || B
A= $response->header('Content-MD5')B= Digest::MD5::md5_base64($buf)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 893 | || Digest::MD5::md5_base64($buf); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 894 | 0 | ▶ | if ( $self->md5_cache->has($fingerprint) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 895 | 0 | return "duplicate content for " | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 896 | . $self->md5_cache->get($fingerprint); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 897 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 898 | 0 | $self->md5_cache->add( $fingerprint => $uri ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 899 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 900 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 901 | 6 | ▶ | if ( $response->success ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 902 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 903 | 5 | my $content_type = $meta->{ct}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 904 | 5 | ▶ | if ( !exists $parser_types{$content_type} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 905 | 0 | $self->write_log( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 906 | uri => $uri, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 907 | msg => "no parser for $content_type", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 908 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 909 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 910 | 5 | my $charset = $headers->content_type; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 911 | 5 | $charset =~ s/;?$meta->{ct};?//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 912 | 5 | ▶ | my $encoding = $headers->content_encoding || $charset; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$headers->content_encoding || $charset
MC/DC0%0/2
$headers->content_encoding || $charset
$headers->content_encoding
$charset
Truth table33%1/3
A || B
A= $headers->content_encodingB= $charset
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 913 | my %doc = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 914 | url => $meta->{org_uri}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 915 | modtime => ( $headers->last_modified || $headers->date ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 916 | type => $meta->{ct}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 917 | 5 | ▶ | content => ( $encoding =~ m/utf-8/i ? to_utf8($buf) : $buf ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$headers->last_modified || $headers->date
$headers->content_length || length pack('C0a*', $buf)
MC/DC0%0/2
$headers->last_modified || $headers->date
$headers->last_modified
$headers->date
MC/DC0%0/2
$headers->content_length || length pack('C0a*', $buf)
$headers->content_length
length pack('C0a*', $buf)
Truth table33%1/3
A || B
A= $headers->last_modifiedB= $headers->date
Truth table33%1/3
A || B
A= $headers->content_lengthB= length pack('C0a*', $buf)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 918 | size => $headers->content_length || length( pack 'C0a*', $buf ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 919 | charset => $encoding, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 920 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 921 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 922 | # cache whatever credentials were used so we can re-use | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 923 | 5 | ▶ | if ( $self->{cur_realm} and $uri->userinfo ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"cur_realm"} and $uri->userinfo
MC/DC0%0/2
$self->{"cur_realm"} and $uri->userinfo
$self->{"cur_realm"}
$uri->userinfo
Truth table33%1/3
A and B
A= $self->{"cur_realm"}B= $uri->userinfo
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 924 | 0 | my $key = $uri->canonical->host_port . ':' . $self->{cur_realm}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 925 | 0 | $self->{_auth_cache}->add( $key => $uri->userinfo ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 926 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 927 | # not too sure of the best logic here | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 928 | 0 | my $path = $uri->path; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 929 | 0 | $path =~ s!/[^/]*$!!; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 930 | $self->{last_auth} = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 931 | 0 | path => $path, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 932 | auth => $uri->userinfo, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 933 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 934 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 935 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 936 | # return doc | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 937 | 5 | return $self->doc_class->new(%doc); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 938 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 939 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 940 | elsif ( $response->status == 401 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 941 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 942 | # authorize and try again | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 943 | 0 | $self->write_log( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 944 | uri => $uri, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 945 | msg => sprintf( "authn denied, retrying, %s", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 946 | $response->status_line ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 947 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 948 | 0 | ▶ | return $self->get_authorized_doc( $uri, $response ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$self->get_authorized_doc($uri, $response) || $response->status
MC/DC0%0/2
$self->get_authorized_doc($uri, $response) || $response->status
$self->get_authorized_doc($uri, $response)
$response->status
Truth table0%0/3
A || B
A= $self->get_authorized_doc($uri, $response)B= $response->status
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 949 | || $response->status; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 950 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 951 | ▶ | elsif ($response->status == 403 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$response->status == 403 and $http_response->status_line =~ /robots.txt/
MC/DC0%0/2
$response->status == 403 and $http_response->status_line =~ /robots.txt/
$response->status == 403
$http_response->status_line =~ /robots.txt/
Truth table33%1/3
A and B
A= $response->status == 403B= $http_response->status_line =~ /robots.txt/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 952 | && $http_response->status_line =~ m/robots.txt/ ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 953 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 954 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 955 | # ignore | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 956 | 0 | $self->write_log( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 957 | uri => $uri, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 958 | msg => sprintf( "skipped, %s", $http_response->status_line ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 959 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 960 | 0 | ▶ | return $self->get_authorized_doc( $uri, $response ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$self->get_authorized_doc($uri, $response) || $response->status
MC/DC0%0/2
$self->get_authorized_doc($uri, $response) || $response->status
$self->get_authorized_doc($uri, $response)
$response->status
Truth table0%0/3
A || B
A= $self->get_authorized_doc($uri, $response)B= $response->status
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 961 | || $response->status; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 962 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 963 | elsif ( $response->status == 403 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 964 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 965 | # authorize and try again | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 966 | 0 | $self->write_log( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 967 | uri => $uri, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 968 | msg => sprintf( "retrying, %s", $http_response->status_line ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 969 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 970 | 0 | return $self->get_authorized_doc( $uri, $response ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 971 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 972 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 973 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 974 | 1 | $self->write_log( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 975 | uri => $uri, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 976 | msg => $http_response->status_line, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 977 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 978 | 1 | return $response->status; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 979 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 980 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 981 | 0 | return; # never get here. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 982 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 983 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 984 | 22 | ▶ | sub _get_user_pass { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_user_pass: called CC=6 SCAR=24.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 985 | 22 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 986 | 22 | my $uri = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 987 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 988 | # Set basic auth if defined - use URI specific first, then credentials. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 989 | # this doesn't track what should have authorization | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 990 | 22 | my $last_auth; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 991 | 22 | ▶ | if ( $self->{last_auth} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 992 | 0 | my $path = $uri->path; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 993 | 0 | $path =~ s!/[^/]*$!!; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 994 | $last_auth = $self->{last_auth}->{auth} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 995 | 0 | ▶ | if $self->{last_auth}->{path} eq $path; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 996 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 997 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 998 | 22 | ▶ | my ( $user, $pass ) = split /:/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition37%3/8
$last_auth || $uri->userinfo || $self->credentials || ''
$last_auth or $uri->userinfo or $self->credentials
$last_auth or $uri->userinfo
MC/DC0%0/3
$last_auth || $uri->userinfo || $self->credentials || ''
$last_auth
$uri->userinfo
$self->credentials
Truth table25%1/4
A or B or C
A= $last_authB= $uri->userinfoC= $self->credentials
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 999 | ( $last_auth || $uri->userinfo || $self->credentials || '' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1000 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1001 | 22 | return ( $user, $pass ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1002 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1003 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1004 | =head2 looks_like_feed( I<http_response> ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1005 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1006 | Called internally to perform naive heuristics on I<http_response> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1007 | to determine whether it looks like an XML feed of some kind, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1008 | rather than a HTML page. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1009 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1010 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1011 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1012 | 6 | ▶ | sub looks_like_feed { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
looks_like_feed: called CC=8 SCAR=24.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1013 | 6 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1014 | 6 | ▶ | my $response = shift or croak "response required"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1015 | 6 | my $headers = $response->headers; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1016 | 6 | my $ct = $headers->content_type; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1017 | 6 | ▶ | if ( $ct eq 'text/html' or $ct eq 'application/xhtml+xml' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$ct eq "text/html" or $ct eq "application/xhtml+xml"
MC/DC50%1/2
$ct eq "text/html" or $ct eq "application/xhtml+xml"
$ct eq "text/html"
$ct eq "application/xhtml+xml"
Truth table66%2/3
A or B
A= $ct eq "text/html"B= $ct eq "application/xhtml+xml"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1018 | 4 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1019 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1020 | 2 | ▶ | if ( $ct eq 'text/xml' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%3/9
$ct eq "text/xml" or $ct eq "application/rss+xml" or $ct eq "application/rdf+xml" or $ct eq "application/atom+xml"
$ct eq "text/xml" or $ct eq "application/rss+xml" or $ct eq "application/rdf+xml"
$ct eq "text/xml" or $ct eq "application/rss+xml"
MC/DC0%0/4
$ct eq "text/xml" or $ct eq "application/rss+xml" or $ct eq "application/rdf+xml" or $ct eq "application/atom+xml"
$ct eq "text/xml"
$ct eq "application/rss+xml"
$ct eq "application/rdf+xml"
$ct eq "application/atom+xml"
Truth table20%1/5
A or B or C or D
A= $ct eq "text/xml"B= $ct eq "application/rss+xml"C= $ct eq "application/rdf+xml"D= $ct eq "application/atom+xml"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1021 | or $ct eq 'application/rss+xml' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1022 | or $ct eq 'application/rdf+xml' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1023 | or $ct eq 'application/atom+xml' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1024 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1025 | 0 | my $xml = $response->decoded_content; # TODO or content() | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1026 | 0 | return XML::Feed->parse( \$xml ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1027 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1028 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1029 | 2 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1030 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1031 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1032 | =head2 looks_like_sitemap( I<http_response> ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1033 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1034 | Called internally to perform naive heuristics on I<http_response> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1035 | to determine whether it looks like a XML sitemap feed, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1036 | rather than a HTML page. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1037 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1038 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1039 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1040 | 6 | ▶ | sub looks_like_sitemap { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
looks_like_sitemap: called CC=7 SCAR=19.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1041 | 6 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1042 | 6 | ▶ | my $response = shift or croak "response required"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1043 | 6 | my $headers = $response->headers; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1044 | 6 | my $ct = $headers->content_type; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1045 | 6 | ▶ | if ( $ct eq 'text/html' or $ct eq 'application/xhtml+xml' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$ct eq "text/html" or $ct eq "application/xhtml+xml"
MC/DC50%1/2
$ct eq "text/html" or $ct eq "application/xhtml+xml"
$ct eq "text/html"
$ct eq "application/xhtml+xml"
Truth table66%2/3
A or B
A= $ct eq "text/html"B= $ct eq "application/xhtml+xml"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1046 | 4 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1047 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1048 | 2 | ▶ | if ( $ct eq 'text/xml' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$ct eq "text/xml" or $ct eq "application/xml"
MC/DC50%1/2
$ct eq "text/xml" or $ct eq "application/xml"
$ct eq "text/xml"
$ct eq "application/xml"
Truth table66%2/3
A or B
A= $ct eq "text/xml"B= $ct eq "application/xml"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1049 | or $ct eq 'application/xml' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1050 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1051 | 1 | my $xml = $response->decoded_content; # TODO or content() | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1052 | 1 | my $sitemap = WWW::Sitemap::XML->new(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1053 | 1 | eval { $sitemap->load( string => $xml ); }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1054 | 1 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1055 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1056 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1057 | 0 | return $sitemap; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1058 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1059 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1060 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1061 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1062 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1063 | =head2 crawl( I<uri> ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1064 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1065 | Implements the required crawl() method. Recursively fetches I<uri> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1066 | and its child links to a depth set in max_depth(). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1067 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1068 | Will quit after max_files() unless max_files==0. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1069 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1070 | Will quit after max_time() seconds unless max_time==0. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1071 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1072 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1073 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1074 | 1 | ▶ | sub crawl { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
crawl: called CC=11 SCAR=25.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1075 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1076 | 1 | my @urls = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1077 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1078 | 1 | my $indexer = $self->indexer; # may be undef | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1079 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1080 | 1 | for my $url (@urls) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1081 | 1 | my $started = time(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1082 | 1 | ▶ | $self->debug and $self->write_log( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1083 | uri => $url, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1084 | msg => "crawling", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1085 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1086 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1087 | 1 | my $uri = URI->new($url)->canonical; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1088 | 1 | $self->uri_cache->add( "$uri" => 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1089 | 1 | $self->add_to_queue($uri); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1090 | 1 | $self->{_base} = $uri->as_string; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1091 | 1 | ▶ | while ( my $doc = $self->get_doc ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1092 | 9 | ▶ | $self->debug and $self->write_log_line(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1093 | 9 | ▶ | next unless blessed($doc); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1094 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1095 | # indexer not required | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1096 | 5 | ▶ | $indexer->process($doc) if $indexer; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1097 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1098 | 5 | $self->_increment_count; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1099 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1100 | # abort if we've met any max_* conditions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1101 | 5 | ▶ | last if $self->max_files and $self->count >= $self->max_files; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->max_files and $self->count >= $self->max_files
MC/DC0%0/2
$self->max_files and $self->count >= $self->max_files
$self->max_files
$self->count >= $self->max_files
Truth table33%1/3
A and B
A= $self->max_filesB= $self->count >= $self->max_files
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1102 | last | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1103 | 5 | ▶ | if $self->max_time | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->max_time and time - $started > $self->max_time
MC/DC0%0/2
$self->max_time and time - $started > $self->max_time
$self->max_time
time - $started > $self->max_time
Truth table33%1/3
A and B
A= $self->max_timeB= time - $started > $self->max_time
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1104 | and ( time() - $started ) > $self->max_time; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1105 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1106 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1107 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1108 | 1 | return $self->count; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1109 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1110 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1111 | =head2 write_log( I<args> ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1112 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1113 | Passes I<args> to SWISH::Prog::Utils::write_log(). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1114 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1115 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1116 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1117 | 1 | ▶ | sub write_log { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
write_log: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1118 | 1 | SWISH::Prog::Utils::write_log(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1119 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1120 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1121 | =head2 write_log_line([I<char>, I<width>]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1122 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1123 | Pass through to SWISH::Prog::Utils::write_log_line(). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1124 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1125 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1126 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1127 | 0 | ▶ | sub write_log_line { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
write_log_line: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1128 | 0 | SWISH::Prog::Utils::write_log_line(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1129 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1130 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1131 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1132 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1133 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||