Apache-Wyrd
view release on metacpan or search on metacpan
Wyrd/Site/Index.pm view on Meta::CPAN
}
=pod
=item (hashref) C<lookup> (scalar)
or
=item (scalar) C<lookup> (scalar, scalar)
Look up and return data from the index. In both forms, the first argument
is a scalar representation of the page. This can be the page name, which
means the path after document root or the page's internal index ID (an
integer).
If the specific attribute is not given, the method returns a hashref of the
full data for the page. If the attribute is given, only the value of that
attribute is given.
=cut
sub lookup {
#universal lookup mechanism. Use attribute as well as page path to get a scalar.
my ($self, $name, $attribute) = @_;
my $index = $self->read_db;
#warn("looking up $attribute for $name");
my ($id, $new) = $self->get_id($name);
#warn("found id '$id' new: $new");
return {} if ($new and not($attribute));
return undef if ($new);
if ($attribute) {
my $key = $self->make_key($attribute, $id);
my $failed = $index->db_get($key, my $out);
#warn "failed" if $failed;
return undef if ($failed);
return $out;
} else {
return $self->get_entry($id);
}
}
=pod
=item (scalar) C<purge_missing> (Apache request handle)
like index_site, this is an obsolete method of removing deleted documents
from an index. Please use the more fault-tolerant
Apache::Wyrd::Site::IndexBot object.
It takes the Apache req object as an argument, and returns a scalar of the
text of the output from that purge.
=cut
sub purge_missing {
my ($self, $req) = @_;
die ("index site requires an Apache request object, not a: " . ref($req)) unless (ref($req) eq 'Apache');
my $root = $req->document_root;
my $result = "<P>First checking for deleted documents:";
my $index = $self->write_db;
my $cursor = $index->db_cursor;
my %exists = ();
$cursor->c_get(my $id, my $document, DB_FIRST);
do {
$exists{$id}=1 if ($id =~ /^\d\d/);
} until ($cursor->c_get($id, $document, DB_NEXT));
$cursor->c_get($id, $document, DB_FIRST);
do {
my ($current_id) = $id =~ /^[\x00-\xff]%(\d+)/;
if ($id =~ /^\d\d/) {
if (-f "$root$document") {
$result .= "<BR>keeping $root$document"
} else {
$result .= "<BR>destroying $root$document: " . $self->purge_entry($id);
}
} elsif (not($exists{$current_id})) {
my $error = $index->db_del($id);
$result .= "<br>warning: purged corrupt data for nonexistent id $current_id: ". ($error ? 'failed!' : 'succeeded.');
}
} until ($cursor->c_get($id, $document, DB_NEXT));
$cursor->c_close;
$self->close_db;
return "$result</p>";
}
=pod
=item (scalar) C<skip_file> (scalar)
Simple filter for removing files from consideration by the index. Intended
as an over-loadable handle. Returns 0 if the file should be indexed.
Defaults to 0.
=cut
sub skip_file {
my ($self, $file) = @_;
return 0;
}
=pod
=item (objectref) C<ua> (hashref)
Another over-loadable handle. Should return a handle to a LWP useragent
object (See LWP::UserAgent) appropriate for navigating the site, which is to
say it should have some way of handling access and authentication
appropriate to the site's construction. There is no default ua; the
webmaster will need to define it in order to use this object.
Note that this method is required by Apache::Wyrd::Services::IndexBot.
=cut
sub ua {
my ($self) = @_;
$self->_raise_exception('You need to privide a ua method appropriate to your web site.');
}
=pod
=back
=head1 BUGS/CAVEATS
An obsolete appendix to an obsolete mechanism. Reserves the new method,
which it passes unaltered to Apache::Wyrd::Services::Index. index_site,
skip_file, and purge_missing are obsolete and may be dropped in future
versions. See Apache::Wyrd::Services::Index for other bugs/warnings.
=cut
sub new {
return &Apache::Wyrd::Services::Index::new(@_);
}
=pod
=head1 AUTHOR
Barry King E<lt>wyrd@nospam.wyrdwright.comE<gt>
( run in 0.462 second using v1.01-cache-2.11-cpan-437f7b0c052 )