Спецификации:
Установлена libhttp-oai-perl
с помощью apt-get install
.
После попытки использовать модуль HTTP::OAI::Harvester со скриптом, расположенным в разделе Synopsis этой article:
use HTTP::OAI;
my $h = new HTTP::OAI::Harvester(baseURL=>'http://arXiv.org/oai2');
my $response = $h->repository($h->Identify)
if( $response->is_error ) {
print "Error requesting Identify:\n",
$response->code . " " . $response->message, "\n";
exit;
}
# Note: repositoryVersion will always be 2.0, $r->version returns
# the actual version the repository is running
print "Repository supports protocol version ", $response->version, "\n";
# Version 1.x repositories don't support metadataPrefix,
# but OAI-PERL will drop the prefix automatically
# if an Identify was requested first (as above)
$response = $h->ListIdentifiers(
metadataPrefix=>'oai_dc',
from=>'2001-02-03',
until=>'2001-04-10'
);
if( $response->is_error ) {
die("Error harvesting: " . $response->message . "\n");
}
print "responseDate => ", $response->responseDate, "\n",
"requestURL => ", $response->requestURL, "\n";
while( my $id = $response->next ) {
print "identifier => ", $id->identifier;
# Only available from OAI 2.0 repositories
print " (", $id->datestamp, ")" if $id->datestamp;
print " (", $id->status, ")" if $id->status;
print "\n";
# Only available from OAI 2.0 repositories
for( $id->setSpec ) {
print "\t", $_, "\n";
}
}
# Using a handler
$response = $h->ListRecords(
metadataPrefix=>'oai_dc',
handlers=>{metadata=>'HTTP::OAI::Metadata::OAI_DC'},
);
while( my $rec = $response->next ) {
print $rec->identifier, "\t",
$rec->datestamp, "\n",
$rec->metadata, "\n";
print join(',', @{$rec->metadata->dc->{'title'}}), "\n";
}
if( $rec->is_error ) {
die $response->message;
}
# Offline parsing
$I = HTTP::OAI::Identify->new();
$I->parse_string($content);
$I->parse_file($fh);
Я получил сообщение об ошибке:
Can't locate object method "is_error" via package "HTTP::OAI::Identify" at ./test.pl line 7.
Как заставить скрипт работать?
Любая помощь была бы признательна!
После контакта (скрыто), который сохраняет пакет сейчас вместо Tim Brody, некоторые изменения необходимы для вышеупомянутого примера.
Одной из модификаций которой я не уверен, действительно ли нужно было добавить
use HTTP::OAI::Metadata::OAI_DC;
основную модификацию, однако, это то, что вместо «следующего» - метод обратного вызова. Модифицированный код выглядит как
# Using a handler
$response = $h->ListRecords(
metadataPrefix=>'oai_dc',
handlers=>{metadata=>'HTTP::OAI::Metadata::OAI_DC'},
onRecord=>sub {
my $rec = shift;
printf"%s\t%s\t%s\n"
, $rec->identifier
, $rec->datestamp
, join(',', @{$rec->metadata->dc->{'title'}});
}
);