/usr/share/perl5/WWW/SearchResult.pm is in libwww-search-perl 2.51.30-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 | # SearchResult.pm
# by John Heidemann
# Copyright (C) 1996 by USC/ISI
# $Id: SearchResult.pm,v 2.78 2008/07/21 01:20:30 Martin Exp $
#
# Copyright (c) 1996 University of Southern California.
# All rights reserved.
#
# Redistribution and use in source and binary forms are permitted
# provided that the above copyright notice and this paragraph are
# duplicated in all such forms and that any documentation, advertising
# materials, and other materials related to such distribution and use
# acknowledge that the software was developed by the University of
# Southern California, Information Sciences Institute. The name of the
# University may not be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
=head1 NAME
WWW::SearchResult - class for results returned from WWW::Search
=head1 SYNOPSIS
require WWW::Search;
require WWW::SearchResult;
$search = new WWW::Search;
$search->native_query(WWW::Search::escape_query($query));
# Get first result:
$result = $search->next_result();
=head1 DESCRIPTION
A framework for returning the results of C<WWW::Search>.
=head1 SEE ALSO
L<WWW::Search>
=head1 REQUIRED RESULTS
The particular fields returned in a result are backend- (search
engine-) dependent. However, all search engines are required to
return a url and title. (This list may grow in the future.)
=head1 METHODS AND FUNCTIONS
=cut
#####################################################################
package WWW::SearchResult;
use strict;
use warnings;
use CGI;
use base 'LWP::MemberMixin';
our
$VERSION = do{ my @r = (q$Revision: 2.78 $ =~ /\d+/g); sprintf "%d."."%03d" x $#r, @r};
=head2 new
To create a new WWW::SearchResult, call
$result = new WWW::SearchResult();
=cut
sub new
{
my $class = shift;
my $self = bless { }, $class;
$self->{urls} = ();
return $self;
} # new
=head2 url
Returns the primary URL. Note that there may be a list of urls, see
also methods C<urls> and C<add_url>. Nothing special is guaranteed
about the primary URL other than that it is the first one returned by
the back end.
Every result is required to have at least one URL.
=cut
sub url
{
my $self = shift;
if (@_ < 1)
{
# No arguments, just return the current value:
return ${$self->{urls}}[0];
} # if no args
unshift @{$self->{urls}}, $_[0];
return $self->{urls}->[0];
} # url
sub _elem_array
{
my $self = shift;
my $elem = shift;
if (@_ < 1)
{
# No arguments
return wantarray ? @{$self->{$elem}} : $self->{$elem};
} # if
if (ref($_[0]))
{
# Trying to assign an arrayref:
$self->{$elem} = $_[0];
}
else
{
# Trying to set to a scalar (or list of scalars); make sure it's
# an array even if they give one element:
$self->{$elem} = undef;
push @{$self->{$elem}}, @_;
}
# Always return array refrence
return $self->{$elem};
} # _elem_array
sub _add_elem_array
{
my $self = shift;
my $elem = shift;
# No matter how many they're adding:
push(@{$self->{$elem}}, @_);
} # _add_elem_array
=head2 add_url
Add a URL to the list.
=cut
sub add_url { return shift->_add_elem_array('urls', @_); }
=head2 urls
Return a reference to the list of urls.
There is also a primary URL (C<url>).
=cut
sub urls { return shift->_elem_array('urls', @_); }
=head2 add_related_url
Add a URL to the related_url list.
=cut
sub add_related_url { return shift->_add_elem_array('related_urls', @_); }
=head2 related_urls
Return a reference to the list of related urls.
=cut
sub related_urls { return shift->_elem_array('related_urls', @_); }
=head2 add_related_title
Add a title to the list or related titles.
=cut
sub add_related_title { return shift->_add_elem_array('related_titles', @_); }
=head2 related_titles
Return a reference to the list of related titles.
=cut
sub related_titles { return shift->_elem_array('related_titles', @_); }
=head2 title, description, score, change_date, index_date, size, raw
Set or get attributes of the result.
None of these attributes is guaranteed to be provided by
a given backend. If an attribute is not provided
its method will return C<undef>.
Typical contents of these attributes:
=over 8
=item title
The title of the hit result (typically that provided by the 'TITLE'
HTML tag).
=cut
sub title { return shift->_elem('title', @_); }
=item description
A brief description of the result, as provided (or not) by the search engine.
Often the first few sentences of the document.
=cut
sub description { return shift->_elem('description', @_); }
=item source
Source is either the base url for this result (as listed on the search
engine's results page) or another copy of the full url path of the
result. It might also indicate the source site name or address whence
the result came, for example, 'CNN' or 'http://www.cnn.com' if the
search result page said "found at CNN.com".
This value is backend-specific; in fact very few backends set this
value.
=cut
sub source { return shift->_elem('source', @_); }
=item add_sources
Same meaning as source above, for adding sources in case there are
potentially multiple sources.
=cut
sub add_sources { return shift->_add_elem_array('sources', @_); }
=item sources
Returns a reference to the list of sources.
=cut
sub sources { return shift->_elem_array('sources', @_); }
=item score
A backend specific, numeric score of the search result.
The exact range of scores is search-engine specific.
Usually larger scores are better, but this is no longer required.
See normalized_score for a backend independent score.
=cut
sub score { return shift->_elem('score', @_); }
=item normalized_score
This is intended to be a backend-independent score of the search
result. The range of this score is between 0 and 1000. Higher values
indicate better quality results.
This is not really implemented since no one has created an
backend-independent ranking algorithm.
=cut
sub normalized_score { return shift->_elem('normalized_score', @_); }
=item change_date
When the result was last changed. Typically this is the modification
time of the destination web page.
=cut
sub change_date { return shift->_elem('change_date', @_); }
=item index_date
When the search engine indexed the result.
=cut
sub index_date { return shift->_elem('index_date', @_); }
=item size
The approximate size of the result, in bytes. This is only an
approximation because search backends often report the size as
"18.4K"; the best we can do with that number is return it as the value
of 18.4 * 1024.
=cut
sub size { return shift->_elem('size', @_); }
=item raw
The raw HTML for the entire result. Raw should be exactly the raw
HTML for one entry. It should not include list or table setup
commands (like ul or table tags), but it may include list item or
table data commands (like li, tr, or td). Whether raw contains a list
entry, table row, br-separated lines, or plain text is search-engine
dependent. In fact, many backends do not even return it at all.
=cut
sub raw { return shift->_elem('raw', @_); }
=item as_HTML
Convert the search result to a human-readable form,
decorated with HTML for pretty-printing.
=cut
sub as_HTML
{
my $self = shift;
my $cgi = new CGI;
my $s = $cgi->a({
href => $self->url,
},
$self->title || 'title unknown',
);
$s .= $cgi->br;
$s .= $self->description || 'no description available';
return $s;
} # as_HTML
=back
=head2 Others
More attributes of the result. Backend-specific.
Refer to the documentation of each backend for details.
=over
=item bid_amount
=cut
sub bid_amount { return shift->_elem('bid', @_); }
=item bid_count
=cut
sub bid_count { return shift->_elem('bids', @_); }
=item bidder
=cut
sub bidder { return shift->_elem('bidder', @_); }
=item category
=cut
sub category { return shift->_elem('category', @_); }
=item company
=cut
sub company { return shift->_elem('company', @_); }
=item end_date
=cut
sub end_date { return shift->_elem('end_date', @_); }
=item image_url
=cut
sub image_url { return shift->_elem('image_url', @_); }
=item item_number
=cut
sub item_number { return shift->_elem('item_number', @_); }
=item location
=cut
sub location { return shift->_elem('location', @_); }
=item question_count
=cut
sub question_count { return shift->_elem('question_count', @_); }
=item seller
=cut
sub seller { return shift->_elem('seller', @_); }
=item shipping
=cut
sub shipping { return shift->_elem('shipping', @_); }
=item sold
=cut
sub sold { return shift->_elem('sold', @_); }
=item start_date
=cut
sub start_date { return shift->_elem('start_date', @_); }
=item thumb_url
=cut
sub thumb_url { return shift->_elem('thumb_url', @_); }
=item watcher_count
=cut
sub watcher_count { return shift->_elem('seller', @_); }
=back
=head1 AUTHOR
WWW::SearchResult was written by John Heidemann.
WWW::SearchResult is maintained by Martin Thurn.
=cut
1;
__END__
|