line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Importer::ArXiv; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
98812
|
use Catmandu::Sane; |
|
2
|
|
|
|
|
220825
|
|
|
2
|
|
|
|
|
12
|
|
4
|
2
|
|
|
2
|
|
1274
|
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
|
|
|
|
|
|
|
my $rec = {id => $self->id}; |
48
|
|
|
|
|
|
|
if ($self->id && is_valid_orcid($rec, 'id')) { |
49
|
|
|
|
|
|
|
$url = "https://arxiv.org/a/" . $self->id . ".atom2"; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
else { |
52
|
|
|
|
|
|
|
$url = $self->base; |
53
|
|
|
|
|
|
|
$url .= 'search_query=' . $self->query if $self->query; |
54
|
|
|
|
|
|
|
$url .= '&id_list=' . $self->id if $self->id; |
55
|
|
|
|
|
|
|
$url .= '&start=' . $self->start if $self->start; |
56
|
|
|
|
|
|
|
$url .= '&max_results=' . $self->limit if $self->limit; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
my $res = $self->_request($url); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
return $res->{content}; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub _parse { |
65
|
|
|
|
|
|
|
my ( $self, $in ) = @_; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
my $xml = Catmandu::Importer::XML->new( file => \$in, path => 'entry' ); |
68
|
|
|
|
|
|
|
return $xml->to_array; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub _get_record { |
72
|
|
|
|
|
|
|
my ($self) = @_; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
my $xml = $self->_call; |
75
|
|
|
|
|
|
|
my $stack = $self->_parse($xml); |
76
|
|
|
|
|
|
|
return $stack; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub generator { |
80
|
|
|
|
|
|
|
my ($self) = @_; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
return sub { |
83
|
|
|
|
|
|
|
state $stack = $self->_get_record; |
84
|
|
|
|
|
|
|
my $rec = pop @$stack; |
85
|
|
|
|
|
|
|
$rec->{entry} ? return $rec->{entry} : return undef; |
86
|
|
|
|
|
|
|
}; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
1; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 NAME |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Catmandu::Importer::ArXiv - Package that imports data from http://arxiv.org/. |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 SYNOPSIS |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
use Catmandu::Importer::ArXiv; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
my %attrs = ( |
100
|
|
|
|
|
|
|
query => 'all:electron' |
101
|
|
|
|
|
|
|
); |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
my $importer = Catmandu::Importer::ArXiv->new(%attrs); |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
my $n = $importer->each(sub { |
106
|
|
|
|
|
|
|
my $hashref = $_[0]; |
107
|
|
|
|
|
|
|
# ... |
108
|
|
|
|
|
|
|
}); |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 CONFIGURATION |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=over |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=item query |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Search by query. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=item id |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Search by one or many arXiv ids. This parameter accepts a comma-separated list of ids. This parameter accepts also an ORCID ID. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=item start |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Start parameter for pagination. |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=item limit |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Limit parameter for pagination. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=back |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head1 SEE ALSO |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
L<Catmandu::Iterable>, L<Catmandu::Importer::Inspire> |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=cut |