line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Importer::ArXiv; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
102647
|
use Catmandu::Sane; |
|
2
|
|
|
|
|
236662
|
|
|
2
|
|
|
|
|
10
|
|
4
|
2
|
|
|
2
|
|
1318
|
use Catmandu::Importer::XML; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
use Catmandu::Fix::Condition::is_valid_orcid as => 'is_valid_orcid'; |
6
|
|
|
|
|
|
|
use Moo; |
7
|
|
|
|
|
|
|
use Furl; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
with 'Catmandu::Importer'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# INFO: |
12
|
|
|
|
|
|
|
# http://arxiv.org/help/api/index/ |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
use constant BASE_URL => 'http://export.arxiv.org/api/query?'; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
has base => ( is => 'ro', default => sub { return BASE_URL; } ); |
17
|
|
|
|
|
|
|
has query => ( is => 'ro' ); |
18
|
|
|
|
|
|
|
has id => ( is => 'ro' ); # can be a comma seperated list |
19
|
|
|
|
|
|
|
has start => ( is => 'ro' ); |
20
|
|
|
|
|
|
|
has limit => ( is => 'ro' ); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub BUILD { |
23
|
|
|
|
|
|
|
my $self = shift; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
Catmandu::BadVal->throw("Either id or query required.") |
26
|
|
|
|
|
|
|
unless $self->id || $self->query; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub _request { |
30
|
|
|
|
|
|
|
my ( $self, $url ) = @_; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
my $furl = Furl->new( |
33
|
|
|
|
|
|
|
agent => 'Mozilla/5.0', |
34
|
|
|
|
|
|
|
timeout => 20, |
35
|
|
|
|
|
|
|
); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
my $res = $furl->get($url); |
38
|
|
|
|
|
|
|
die $res->status_line unless $res->is_success; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
return $res; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub _call { |
44
|
|
|
|
|
|
|
my ($self) = @_; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
my $url; |
47
|
|
|
|
|
|
|
if ($self->query && is_valid_orcid({orcid => $self->query}, 'orcid')) { |
48
|
|
|
|
|
|
|
$url = "https://arxiv.org/a/" . $self->query . ".atom2"; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
else { |
51
|
|
|
|
|
|
|
$url = $self->base; |
52
|
|
|
|
|
|
|
$url .= 'search_query=' . $self->query if $self->query; |
53
|
|
|
|
|
|
|
$url .= '&id_list=' . $self->id if $self->id; |
54
|
|
|
|
|
|
|
$url .= '&start=' . $self->start if $self->start; |
55
|
|
|
|
|
|
|
$url .= '&max_results=' . $self->limit if $self->limit; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
my $res = $self->_request($url); |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
return $res->{content}; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub _parse { |
64
|
|
|
|
|
|
|
my ( $self, $in ) = @_; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
my $xml = Catmandu::Importer::XML->new( file => \$in, path => 'entry' ); |
67
|
|
|
|
|
|
|
return $xml->to_array; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub _get_record { |
71
|
|
|
|
|
|
|
my ($self) = @_; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
my $xml = $self->_call; |
74
|
|
|
|
|
|
|
my $stack = $self->_parse($xml); |
75
|
|
|
|
|
|
|
return $stack; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub generator { |
79
|
|
|
|
|
|
|
my ($self) = @_; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
return sub { |
82
|
|
|
|
|
|
|
state $stack = $self->_get_record; |
83
|
|
|
|
|
|
|
my $rec = pop @$stack; |
84
|
|
|
|
|
|
|
$rec->{entry} ? return $rec->{entry} : return undef; |
85
|
|
|
|
|
|
|
}; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
1; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 NAME |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
Catmandu::Importer::ArXiv - Package that imports data from http://arxiv.org/. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 SYNOPSIS |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
use Catmandu::Importer::ArXiv; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
my %attrs = ( |
99
|
|
|
|
|
|
|
query => 'all:electron' |
100
|
|
|
|
|
|
|
); |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
my $importer = Catmandu::Importer::ArXiv->new(%attrs); |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
my $n = $importer->each(sub { |
105
|
|
|
|
|
|
|
my $hashref = $_[0]; |
106
|
|
|
|
|
|
|
# ... |
107
|
|
|
|
|
|
|
}); |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head1 CONFIGURATION |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=over |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=item query |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
Search by query. |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=item id |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
Search by one or many arXiv ids. This parameter accepts a comma-separated list of ids. This parameter accepts also an ORCID ID. |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=item start |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Start parameter for pagination. |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=item limit |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
Limit parameter for pagination. |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=back |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head1 SEE ALSO |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
L<Catmandu::Iterable>, L<Catmandu::Importer::Inspire> |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=cut |