ADS/Result.pm

filter: Statementstmt 91.0% 51 / 56 Branchbran 87.5% 7 / 8 Conditioncond 83.3% 5 / 6 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 92.8% 13 / 14 Podpod 100% 2 / 2 totaltotal 88.8% 80 / 90 CC 7 SCAR 10.0
CC
7
Cov
90%
next
6.2
__ANON__
2.0
get_papers
2.0
CRAP 2.7
« ADS/Role/ResultMapper.pm ↑ Summary ADS/Paper.pm »
1 package Astro::ADS::Result;
2 5 $Astro::ADS::Result::VERSION = '1.92';
3 5 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 5 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use Data::Dumper::Concise;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use Mojo::Base -strict; # do we want -signatures
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use Mojo::DOM;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use Mojo::File qw( path );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 ▶use Mojo::URL;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 ▶use Mojo::Util qw( quote );
Subroutine BEGIN: called CC=1 SCAR=0.0
12 5 ▶use PerlX::Maybe;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 5 ▶use Types::Standard qw( Int Str ArrayRef HashRef Bool ); # InstanceOf ConsumerOf
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 5 has [qw/q fq fl sort/] => (
16 is => 'rw',
17 isa => Str,
18 );
19 5 has numFound => (
20 is => 'rw',
21 isa => Int->where( '$_ >= 0' ),
22 );
23 5 has numFoundExact => (
24 is => 'rw',
25 isa => Bool,
26 );
27 5 has [qw/start rows/] => (
28 is => 'rw',
29 isa => Int->where( '$_ >= 0' ),
30 );
31 5 has error => (
32 is => 'rw',
33 isa => HashRef[]
34 );
35 has docs => (
36 is => 'rw',
37 isa => ArrayRef[],
38 #isa => ArrayRef[ InstanceOf ['Astro::ADS::Paper'] ],
39 1 ▶ default => sub { return [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
40 5 );
41  
42 # if the query failed, the Result has an error
43 # so warn the user if they try to access other returned attributes
44 18 ▶before [qw/numFound numFoundExact start rows docs/] => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
45 18 my ($self) = @_;
46 18 ▶ if ($self->error ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->error) 1 17 18
47 1 carp 'Empty Result object: ', $self->error->{message};
48 }
49 5 };
50  
51 4 ▶sub next {
Subroutine next: called CC=6 SCAR=18.3
Pod documented
52 4 my ($self, $num) = @_;
53 4 my $next_start = $self->start + $self->rows;
54  
55 4 ▶ if ( $next_start > $self->numFound ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($next_start > $self->numFound) { } 0 4 4
elsif ($num and not $num > 0) { } 2 3 5
56 0 carp "No more results for ", $self->q, "\n";
57 0 return;
58 }
59 ▶ elsif ( $num && !($num > 0) ) {
Condition100%3/3
$num and not $num > 0
!ll&&!rl&&r
112
MC/DC100%2/2
$num and not $num > 0
$num not $num > 0
Truth table100%3/3
A and not(B)
A= $numB= not $num > 0
ABresult
0X0
100
111
60 2 carp sprintf('Bad value for number of rows: %s. Defaulting to %d', $num, $self->rows);
61 2 $num = 0;
62 }
63  
64 4 ▶ my $next_search_terms = {
Condition66%2/3
$num || $self->rows
l!l&&r!l&&!r
130
MC/DC0%0/2
$num || $self->rows
$num $self->rows
Truth table66%2/3
A || B
A= $numB= $self->rows
ABresult
1X1
011
000
65 q => $self->q,
66 start => $next_start,
67 maybe fq => $self->fq,
68 maybe fl => $self->fl,
69 maybe rows => ($num || $self->rows),
70 maybe sort => $self->sort,
71 };
72 delete $next_search_terms->{rows}
73 4 ▶ if $next_search_terms->{rows} == 10; # don't send default
Branch: 1 branch
BranchTrueFalseTotal
if $next_search_terms->{"rows"} == 10 3 1 4
74  
75 4 return $next_search_terms;
76 }
77  
78 0 ▶sub get_papers {
Subroutine get_papers: not called CC=1 SCAR=6.9
Pod documented
79 0 my $self = shift;
80 0 return @{$self->docs};
81 }
82  
83 #To Be Decided:
84 #This is a hold over from v1.0 which gets the summary for each document.
85 #Should we ditch it?
86 #
87 #sub summary {
88 # my $self = shift;
89 # for my $paper ( $self->get_papers ) {
90 # $paper->summary;
91 # }
92 #}
93 #
94 #sub sizeof {
95 # my $self = shift;
96 # return $self->numFound; # or should it be $self->rows ?
97 #}
98  
99 5 1;
100  
101 =pod
102  
103 =encoding UTF-8
104  
105 =head1 NAME
106  
107 Astro::ADS::Result - A class for the results of a Search
108  
109 =head1 VERSION
110  
111 version 1.92
112  
113 =head1 SYNOPSIS
114  
115 my $search = Astro::ADS::Search->new(...);
116  
117 my $result = $search->query();
118 my @papers = $result->get_papers();
119  
120 my $next_q = $result->next();
121 $result = $ads->query( $next_q );
122  
123 =head1 DESCRIPTION
124  
125 The Result class holds the
126 L<response|https://ui.adsabs.harvard.edu/help/api/api-docs.html#get-/search/query>
127 from an ADS search query. It will create attributes for all the fields specified
128 in the C<fl> parameter of the search OR it will hold the error returned by the
129 L<UserAgent|Astro::ADS>. If an error was returned, any calls to attribute methods
130 will raise a polite warning that no fields will be available for that object.
131  
132 By default, a successful search returns up to 10 rows of results. If more exist,
133 the user iterates through them using the L</"next"> method to generate a search
134 query updated to start where the previous search left off.
135  
136 =head1 Methods
137  
138 =head2 get_papers
139  
140 This method gets a list of L<Astro::ADS::Paper>s from the last query executed.
141  
142 =head2 next
143  
144 Creates a new search query term hashref, suitable for fetching the next N papers
145 from the ADS. If not given as an argument, the default is 10 rows.
146 It returns C<undef> if you have already reached the end of the available results.
147  
148 This takes the values from the response header and updates the start position,
149 collects the original query C<q> and other params and returns the hashref,
150 ready for the next C<<$search->query>>.
151  
152 If given an argument, it takes that as the number of rows to fetch.
153  
154 =head1 See Also
155  
156 =over 4
157  
158 =item * L<Astro::ADS>
159  
160 =item * L<Astro::ADS::Search>
161  
162 =item * L<ADS API|https://ui.adsabs.harvard.edu/help/api/>
163  
164 =item * L<Available fields for Results|https://ui.adsabs.harvard.edu/help/search/comprehensive-solr-term-list>
165  
166 =back
167  
168 =head1 COPYRIGHT AND LICENSE
169  
170 This software is Copyright (c) 2025 by Boyd Duffee.
171  
172 This is free software, licensed under:
173  
174 The MIT (X11) License
175  
176 =cut
« ADS/Role/ResultMapper.pm ↑ Summary ADS/Paper.pm »