| 1 | package Astro::ADS::Role::ResultMapper; | ||||||||||||||||||||||||||||
| 2 | 4 | $Astro::ADS::Role::ResultMapper::VERSION = '1.92'; | |||||||||||||||||||||||||||
| 3 | 4 | ▶ | use Moo::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use strictures 2; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use Astro::ADS::Paper; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use Astro::ADS::QTree; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 4 | ▶ | use Astro::ADS::Result; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 6 | ▶ | sub parse_response { | ||||||||||||||||||||||||||
|
Subroutine
parse_response: called CC=6 SCAR=18.7
Pod
documented
| |||||||||||||||||||||||||||||
| 11 | 6 | my ($self, $json) = @_; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 6 | ▶ | unless ($json && exists $json->{responseHeader}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$json and exists $json->{"responseHeader"}
MC/DC0%0/2
$json and exists $json->{"responseHeader"}
$json
exists $json->{"responseHeader"}
Truth table33%1/3
A and B
A= $jsonB= exists $json->{"responseHeader"}
| |||||||||||||||||||||||||||||
| 14 | 0 | warn 'No response to parse'; | |||||||||||||||||||||||||||
| 15 | 0 | return; | |||||||||||||||||||||||||||
| 16 | } | ||||||||||||||||||||||||||||
| 17 | # re-map wanted hash keys | ||||||||||||||||||||||||||||
| 18 | 6 | my $result_params; | |||||||||||||||||||||||||||
| 19 | 6 | @{$result_params}{ qw<q rows fl> } = @{$json->{responseHeader}{params}}{ qw<q rows fl> }; | |||||||||||||||||||||||||||
| 20 | 6 | $result_params->{status} = @{$json->{responseHeader}}{ status }; | |||||||||||||||||||||||||||
| 21 | 6 | @{$result_params}{ qw<numFound start> } = @{$json->{response}}{ qw<numFound start> }; | |||||||||||||||||||||||||||
| 22 | 6 | ▶ | $result_params->{numFoundExact} = $json->{response}{numFoundExact} ? 1 : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 6 | my @papers; | |||||||||||||||||||||||||||
| 25 | 6 | for my $paper ( @{$json->{response}->{docs}} ) { | |||||||||||||||||||||||||||
| 26 | 60 | push @papers, Astro::ADS::Paper->new( $paper ); | |||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | 6 | ▶ | $result_params->{docs} = \@papers if @papers; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 6 | return Astro::ADS::Result->new( $result_params ); | |||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 1 | ▶ | sub parse_qtree_response { | ||||||||||||||||||||||||||
|
Subroutine
parse_qtree_response: called CC=3 SCAR=11.7
Pod
documented
| |||||||||||||||||||||||||||||
| 34 | 1 | my ($self, $response) = @_; | |||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 1 | my $json = $response->json; | |||||||||||||||||||||||||||
| 37 | 1 | ▶ | unless ($json && exists $json->{responseHeader}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$json and exists $json->{"responseHeader"}
MC/DC0%0/2
$json and exists $json->{"responseHeader"}
$json
exists $json->{"responseHeader"}
Truth table33%1/3
A and B
A= $jsonB= exists $json->{"responseHeader"}
| |||||||||||||||||||||||||||||
| 38 | 0 | warn 'No response to parse'; | |||||||||||||||||||||||||||
| 39 | 0 | return; | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | # re-map wanted hash keys | ||||||||||||||||||||||||||||
| 42 | 1 | my $result_params; | |||||||||||||||||||||||||||
| 43 | 1 | @{$result_params}{ qw<qtime status> } = @{$json->{responseHeader}}{ qw<QTime status> }; | |||||||||||||||||||||||||||
| 44 | 1 | $result_params->{qtree} = $json->{qtree}; | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 1 | $result_params->{asset} = $response->content->asset; | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 1 | return Astro::ADS::QTree->new( $result_params ); | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 4 | 1; | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | =pod | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | =encoding UTF-8 | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | =head1 NAME | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | Astro::ADS::Role::ResultMapper - Maps the JSON structure returned from an ADS search query | ||||||||||||||||||||||||||||
| 60 | to an Astro::ADS::Result object | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | =head1 VERSION | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | version 1.92 | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | use Moo; | ||||||||||||||||||||||||||||
| 69 | extends 'Astro::ADS'; | ||||||||||||||||||||||||||||
| 70 | with 'Astro::ADS::Role::ResultMapper'; | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | ... | ||||||||||||||||||||||||||||
| 73 | return $self->parse_response( $json ); | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | =head2 parse_response | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | Takes the Mojo Response JSON and maps it to the Result object parameters, | ||||||||||||||||||||||||||||
| 80 | returning a Result object with Papers in the B<docs> attribute. | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | =head2 parse_qtree_response | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | Takes the Mojo Response and maps it to the QTree object parameters, | ||||||||||||||||||||||||||||
| 85 | allocating the JSON fields to attributes and the C<content> to the C<asset> | ||||||||||||||||||||||||||||
| 86 | attribute to allow use of the Mojo::Asset::move_to function. | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | This interface is subject to change up to v2.0 to discover the best way | ||||||||||||||||||||||||||||
| 89 | to use the returned value. | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | This software is Copyright (c) 2025 by Boyd Duffee. | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | This is free software, licensed under: | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | The MIT (X11) License | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | =cut | ||||||||||||||||||||||||||||