blib/lib/WebService/Europeana.pm

filter: Statementstmt 83.5% 76 / 91 Branchbran 41.6% 15 / 36 Conditioncond 23.3% 7 / 30 MC/DCmcdc 0.0% 0 / 20 Subroutinesub 86.6% 13 / 15 Podpod n/a totaltotal 57.8% 111 / 192 CC 30 SCAR 45.2
CC
30
Cov
62%
search
134.3
__ANON__
2.0
__ANON__
2.0
CRAP 92.0
↑ Summary
1 package WebService::Europeana;
2  
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use version; our $VERSION = qv('0.0.3');
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Log::Any;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use Method::Signatures;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use URL::Encode qw(url_encode);
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 2 has 'api_url' => ( is => 'ro', default => 'http://www.europeana.eu/api/v2/' );
17 2 has 'wskey' => ( is => 'ro', required => 1 );
18  
19 has log => (
20 is => 'ro',
21 1 ▶ default => sub { Log::Any->get_logger },
Subroutine __ANON__: called CC=1 SCAR=0.0
22 2 );
23  
24 2 ▶method search(Str :$query, Str :$profile = "standard", Int :$rows = 12, Int :$start = 1, Str :$reusability, Str|ArrayRef :$qf ) {
Subroutine BEGIN: called CC=1 SCAR=0.7
Subroutine search: called CC=30 SCAR=49.0
Branch: 11 branches
BranchTrueFalseTotal
if exists $args{"query"} and not +($Method::Signatures::mutc{"cache"}{"Str"} ||= "Method::Signatures"->_make_constraint("Str"))->check($query) 0 1 1
exists $args{'profile'} ? : 0 1 1
unless ($Method::Signatures::mutc{"cache"}{"Str"} ||= "Method::Signatures"->_make_constraint("Str"))->check($profile) 0 1 1
exists $args{'rows'} ? : 1 0 1
unless ($Method::Signatures::mutc{"cache"}{"Int"} ||= "Method::Signatures"->_make_constraint("Int"))->check($rows) 0 1 1
exists $args{'start'} ? : 0 1 1
unless ($Method::Signatures::mutc{"cache"}{"Int"} ||= "Method::Signatures"->_make_constraint("Int"))->check($start) 0 1 1
if exists $args{"reusability"} and not +($Method::Signatures::mutc{"cache"}{"Str"} ||= "Method::Signatures"->_make_constraint("Str"))->check($reusability) 0 1 1
if exists $args{"qf"} and not +($Method::Signatures::mutc{"cache"}{"Str|ArrayRef"} ||= "Method::Signatures"->_make_constraint("Str|ArrayRef"))->check($qf) 0 1 1
if keys %args 0 1 1
if scalar @_ > 12 0 1 1
Condition25%7/27
exists $args{"query"} and not +($Method::Signatures::mutc{"cache"}{"Str"} ||= "Method::Signatures"->_make_constraint("Str"))->check($query)
!ll&&!rl&&r
010
$Method::Signatures::mutc{"cache"}{"Str"} ||= "Method::Signatures"->_make_constraint("Str")
l!l&&r!l&&!r
010
$Method::Signatures::mutc{"cache"}{"Str"} ||= "Method::Signatures"->_make_constraint("Str")
l!l&&r!l&&!r
100
$Method::Signatures::mutc{"cache"}{"Int"} ||= "Method::Signatures"->_make_constraint("Int")
l!l&&r!l&&!r
010
$Method::Signatures::mutc{"cache"}{"Int"} ||= "Method::Signatures"->_make_constraint("Int")
l!l&&r!l&&!r
100
exists $args{"reusability"} and not +($Method::Signatures::mutc{"cache"}{"Str"} ||= "Method::Signatures"->_make_constraint("Str"))->check($reusability)
!ll&&!rl&&r
100
$Method::Signatures::mutc{"cache"}{"Str"} ||= "Method::Signatures"->_make_constraint("Str")
l!l&&r!l&&!r
000
exists $args{"qf"} and not +($Method::Signatures::mutc{"cache"}{"Str|ArrayRef"} ||= "Method::Signatures"->_make_constraint("Str|ArrayRef"))->check($qf)
!ll&&!rl&&r
100
$Method::Signatures::mutc{"cache"}{"Str|ArrayRef"} ||= "Method::Signatures"->_make_constraint("Str|ArrayRef")
l!l&&r!l&&!r
000
MC/DC0%0/2
exists $args{"query"} and not +($Method::Signatures::mutc{"cache"}{"Str"} ||= "Method::Signatures"->_make_constraint("Str"))->check($query)
exists $args{"query"} not +($Method::Signatures::mutc{"cache"}{"Str"} ||= "Method::Signatures"->_make_constraint("Str"))->check($query)
MC/DC0%0/2
$Method::Signatures::mutc{"cache"}{"Str"} ||= "Method::Signatures"->_make_constraint("Str")
$Method::Signatures::mutc{"cache"}{"Str"} "Method::Signatures"->_make_constraint("Str")
MC/DC0%0/2
$Method::Signatures::mutc{"cache"}{"Str"} ||= "Method::Signatures"->_make_constraint("Str")
$Method::Signatures::mutc{"cache"}{"Str"} "Method::Signatures"->_make_constraint("Str")
MC/DC0%0/2
$Method::Signatures::mutc{"cache"}{"Int"} ||= "Method::Signatures"->_make_constraint("Int")
$Method::Signatures::mutc{"cache"}{"Int"} "Method::Signatures"->_make_constraint("Int")
MC/DC0%0/2
$Method::Signatures::mutc{"cache"}{"Int"} ||= "Method::Signatures"->_make_constraint("Int")
$Method::Signatures::mutc{"cache"}{"Int"} "Method::Signatures"->_make_constraint("Int")
MC/DC0%0/2
exists $args{"reusability"} and not +($Method::Signatures::mutc{"cache"}{"Str"} ||= "Method::Signatures"->_make_constraint("Str"))->check($reusability)
exists $args{"reusability"} not +($Method::Signatures::mutc{"cache"}{"Str"} ||= "Method::Signatures"->_make_constraint("Str"))->check($reusability)
MC/DC0%0/2
$Method::Signatures::mutc{"cache"}{"Str"} ||= "Method::Signatures"->_make_constraint("Str")
$Method::Signatures::mutc{"cache"}{"Str"} "Method::Signatures"->_make_constraint("Str")
MC/DC0%0/2
exists $args{"qf"} and not +($Method::Signatures::mutc{"cache"}{"Str|ArrayRef"} ||= "Method::Signatures"->_make_constraint("Str|ArrayRef"))->check($qf)
exists $args{"qf"} not +($Method::Signatures::mutc{"cache"}{"Str|ArrayRef"} ||= "Method::Signatures"->_make_constraint("Str|ArrayRef"))->check($qf)
MC/DC0%0/2
$Method::Signatures::mutc{"cache"}{"Str|ArrayRef"} ||= "Method::Signatures"->_make_constraint("Str|ArrayRef")
$Method::Signatures::mutc{"cache"}{"Str|ArrayRef"} "Method::Signatures"->_make_constraint("Str|ArrayRef")
Truth table33%1/3
A and not(B)
A= exists $args{"query"}B= not +($Method::Signatures::mutc{"cache"}{"Str"} ||= "Method::Signatures"->_make_constraint("Str"))->check($query)
ABresult
0X0
100
111
Truth table33%1/3
A ||= B
A= $Method::Signatures::mutc{"cache"}{"Str"}B= "Method::Signatures"->_make_constraint("Str")
ABresult
1X1
011
000
Truth table33%1/3
A ||= B
A= $Method::Signatures::mutc{"cache"}{"Str"}B= "Method::Signatures"->_make_constraint("Str")
ABresult
1X1
011
000
Truth table33%1/3
A ||= B
A= $Method::Signatures::mutc{"cache"}{"Int"}B= "Method::Signatures"->_make_constraint("Int")
ABresult
1X1
011
000
Truth table33%1/3
A ||= B
A= $Method::Signatures::mutc{"cache"}{"Int"}B= "Method::Signatures"->_make_constraint("Int")
ABresult
1X1
011
000
Truth table33%1/3
A and not(B)
A= exists $args{"reusability"}B= not +($Method::Signatures::mutc{"cache"}{"Str"} ||= "Method::Signatures"->_make_constraint("Str"))->check($reusability)
ABresult
0X0
100
111
Truth table0%0/3
A ||= B
A= $Method::Signatures::mutc{"cache"}{"Str"}B= "Method::Signatures"->_make_constraint("Str")
ABresult
1X1
011
000
Truth table33%1/3
A and not(B)
A= exists $args{"qf"}B= not +($Method::Signatures::mutc{"cache"}{"Str|ArrayRef"} ||= "Method::Signatures"->_make_constraint("Str|ArrayRef"))->check($qf)
ABresult
0X0
100
111
Truth table0%0/3
A ||= B
A= $Method::Signatures::mutc{"cache"}{"Str|ArrayRef"}B= "Method::Signatures"->_make_constraint("Str|ArrayRef")
ABresult
1X1
011
000
25  
26 1 my $ua = LWP::UserAgent->new();
27 1 my $query_string = undef;
28 1 my $response = undef;
29 1 my $json_result = undef;
30 1 my $result_ref = undef;
31  
32 1 $query_string = sprintf( "%s%s?wskey=%s&rows=%s&query=%s&profile=%s",
33 $self->api_url, "search.json", $self->wskey, $rows, url_encode($query), $profile );
34  
35 1 ▶ $query_string .= "&reusability=".$reusability if ($reusability);
Branch: 1 branch
BranchTrueFalseTotal
if $reusability 0 1 1
36  
37 # qf can be an ArrayRef
38 1 ▶ if (ref($qf) eq 'ARRAY'){
Branch: 1 branch
BranchTrueFalseTotal
if (ref $qf eq 'ARRAY') { } 0 1 1
39 0 foreach my $f (@{$qf}){
40 0 $query_string .= "&qf=".$f;
41 }
42 }else{
43 1 ▶ $query_string .= "&qf=".$qf if ($qf);
Branch: 1 branch
BranchTrueFalseTotal
if $qf 0 1 1
44 }
45  
46 1 $self->log->infof( "Query String: %s", $query_string );
47  
48 1 $response = $ua->get($query_string);
49  
50 1 ▶ if ($response->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->is_success) { } 0 1 1
51 0 $json_result = $response->decoded_content; # or whatever
52 }
53 else {
54 1 $self->log->errorf("Problem accessing the API: %s!",
55 $response->status_line);
56 1 $result_ref->{success} = 0;
57 1 $result_ref->{error_msg} = $response->status_line;
58 1 return $result_ref;
59 }
60  
61 0 ▶ try {
Subroutine __ANON__: not called CC=1 SCAR=6.9
62 0 $result_ref = decode_json($json_result);
63 }
64 0 ▶ catch {
Subroutine __ANON__: not called CC=1 SCAR=6.9
65 0 $self->log->errorf( "Decoding of response '%s' failed: %s",
66 $json_result, $_ );
67 0 };
68  
69 0 ▶ if ($result_ref) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result_ref) 0 0 0
70 0 ▶ if (( $result_ref->{success} )
Branch: 1 branch
BranchTrueFalseTotal
if ($result_ref->{"success"} and $result_ref->{"success"} == 1) 0 0 0
Condition0%0/3
$result_ref->{"success"} and $result_ref->{"success"} == 1
!ll&&!rl&&r
000
MC/DC0%0/2
$result_ref->{"success"} and $result_ref->{"success"} == 1
$result_ref->{"success"} $result_ref->{"success"} == 1
Truth table0%0/3
A and B
A= $result_ref->{"success"}B= $result_ref->{"success"} == 1
ABresult
0X0
100
111
71 && ( $result_ref->{success} == 1 )
72 ){
73 0 $self->log->info("Search was a success!");
74 }
75
76 0 ▶ if ($result_ref->{itemsCount}){
Branch: 1 branch
BranchTrueFalseTotal
if ($result_ref->{'itemsCount'}) { } 0 0 0
77 $self->log->infof("%d item(s) of a total of %d results returned",
78 $result_ref->{itemsCount},
79 $result_ref->{totalResults}
80 0 );
81 }else{
82 0 $self->log->info("No results found");
83 # add zero count
84 0 $result_ref->{itemsCount} = 0;
85 }
86
87 0 return $result_ref;
88 }
89 }
90  
91 2 1;
92  
93  
94 __END__
↑ Summary