WoS/SearchBase.pm

filter: Statementstmt 39.7% 29 / 73 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 35.2% 6 / 17 Podpod 0.0% 0 / 1 totaltotal 33.0% 35 / 106 CC 8 SCAR 25.6
CC
8
Cov
34%
__ANON__
42.0
_soap_request
12.0
_auth_url
2.0
CRAP 13.0
« Importer/WoS.pm ↑ Summary Importer/WoSCitingArticles.pm »
1 package Catmandu::WoS::SearchBase;
2  
3 5 ▶use Catmandu::Sane;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 5 our $VERSION = '0.0303';
6  
7 5 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use URI::Escape qw(uri_escape);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use XML::LibXML;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 ▶use XML::LibXML::XPathContext;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 5 with 'Catmandu::Importer';
14  
15 5 has username => (is => 'ro');
16 5 has password => (is => 'ro');
17 5 has session_id => (is => 'lazy');
18  
19 5 requires '_search_content';
20 5 requires '_retrieve_content';
21 5 requires '_search_response_type';
22 5 requires '_retrieve_response_type';
23 5 requires '_find_records';
24  
25 0 ▶sub _auth_url {
Subroutine _auth_url: not called CC=1 SCAR=6.9
26 0 my ($self) = @_;
27  
28 0 'http://'
29 . uri_escape($self->username) . ':'
30 . uri_escape($self->password)
31 . '@search.webofknowledge.com/esti/wokmws/ws/WOKMWSAuthenticate';
32 }
33  
34 0 ▶sub _auth_ns {
Subroutine _auth_ns: not called CC=1 SCAR=6.9
35 0 state $ns = {
36 'soap' => 'http://schemas.xmlsoap.org/soap/envelope/',
37 'ns2' => 'http://auth.cxf.wokmws.thomsonreuters.com',
38 };
39 }
40  
41 0 ▶sub _auth_content {
Subroutine _auth_content: not called CC=1 SCAR=6.9
42 0 state $content = <<EOF;
43 <soapenv:Envelope
44 xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
45 xmlns:auth="http://auth.cxf.wokmws.thomsonreuters.com">
46 <soapenv:Header/>
47 <soapenv:Body>
48 <auth:authenticate/>
49 </soapenv:Body>
50 </soapenv:Envelope>
51 EOF
52 }
53  
54 0 ▶sub _search_url {
Subroutine _search_url: not called CC=1 SCAR=6.9
55 0 state $url = 'http://search.webofknowledge.com/esti/wokmws/ws/WokSearch';
56 }
57  
58 0 ▶sub _search_ns {
Subroutine _search_ns: not called CC=1 SCAR=6.9
59 0 state $ns = {
60 'soap' => 'http://schemas.xmlsoap.org/soap/envelope/',
61 'ns2' => 'http://woksearch.v3.wokmws.thomsonreuters.com',
62 };
63 }
64  
65 0 ▶sub _soap_request {
Subroutine _soap_request: not called CC=3 SCAR=24.8
66 0 my ($self, $url, $ns, $content, $session_id) = @_;
67  
68 0 my $headers = ['Content-Type' => "text/xml; charset=UTF-8"];
69  
70 0 ▶ if ($session_id) {
Branch: 1 branch
BranchTrueFalseTotal
if ($session_id) 0 0 0
71 0 push @$headers, 'Cookie', qq|SID="$session_id"|;
72 }
73  
74 0 my $res_content = $self->_http_request('POST', $url, $headers, $content,
75 $self->_http_timing_tries,);
76  
77 0 my $doc = XML::LibXML->new(huge => 1)->load_xml(string => $res_content);
78 0 my $xpc = XML::LibXML::XPathContext->new($doc);
79 0 $xpc->registerNs($_ => $ns->{$_}) for keys %$ns;
80 0 $xpc;
81 }
82  
83 0 ▶sub _build_session_id {
Subroutine _build_session_id: not called CC=1 SCAR=6.9
84 0 my ($self) = @_;
85  
86 0 my $xpc = $self->_soap_request($self->_auth_url, $self->_auth_ns,
87 $self->_auth_content,);
88  
89 0 my $session_id = $xpc->findvalue(
90 '/soap:Envelope/soap:Body/ns2:authenticateResponse/return');
91  
92 0 return $session_id;
93 }
94  
95 0 ▶sub _search {
Subroutine _search: not called CC=1 SCAR=6.9
96 0 my ($self, $start, $limit) = @_;
97  
98 0 my $response_type = $self->_search_response_type;
99  
100 0 my $xpc
101 = $self->_soap_request($self->_search_url, $self->_search_ns,
102 $self->_search_content($start, $limit),
103 $self->session_id);
104  
105 0 my $recs = $self->_find_records($xpc, $response_type);
106 0 my $total = $xpc->findvalue(
107 "/soap:Envelope/soap:Body/ns2:$response_type/return/recordsFound");
108 0 my $query_id = $xpc->findvalue(
109 "/soap:Envelope/soap:Body/ns2:$response_type/return/queryId");
110  
111 0 return $recs, $total, $query_id;
112 }
113  
114 0 ▶sub _retrieve {
Subroutine _retrieve: not called CC=1 SCAR=6.9
115 0 my ($self, $query_id, $start, $limit) = @_;
116  
117 0 my $xpc
118 = $self->_soap_request($self->_search_url, $self->_search_ns,
119 $self->_retrieve_content($query_id, $start, $limit),
120 $self->session_id);
121  
122 0 $self->_find_records($xpc, $self->_retrieve_response_type);
123 }
124  
125 0 ▶sub generator {
Subroutine generator: not called CC=1 SCAR=6.9
Pod undocumented
126 0 my ($self) = @_;
127  
128 0 ▶ sub {
Subroutine __ANON__: not called CC=6 SCAR=37.4
129 0 state $recs = [];
130 0 state $query_id;
131 0 state $start = 1;
132 0 state $limit = 100;
133 0 state $total;
134  
135 0 ▶ unless (@$recs) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@$recs) 0 0 0
136 0 ▶ return if defined $total && $start > $total;
Branch: 1 branch
BranchTrueFalseTotal
if defined $total and $start > $total 0 0 0
Condition0%0/3
defined $total and $start > $total
!ll&&!rl&&r
000
MC/DC0%0/2
defined $total and $start > $total
defined $total $start > $total
Truth table0%0/3
A and B
A= defined $totalB= $start > $total
ABresult
0X0
100
111
137  
138 0 ▶ if (defined $query_id) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $query_id) { } 0 0 0
139 0 $recs = $self->_retrieve($query_id, $start, $limit);
140 }
141 else {
142 0 ($recs, $total, $query_id) = $self->_search($start, $limit);
143 0 ▶ $total || return;
Branch: 1 branch
BranchTrueFalseTotal
$total or return 0 0 0
144 }
145  
146 0 $start += $limit;
147 }
148  
149 0 shift @$recs;
150 0 };
151 }
152  
153 5 1;
« Importer/WoS.pm ↑ Summary Importer/WoSCitingArticles.pm »