File Coverage

blib/lib/Astro/ADS/QTree.pm
Criterion Covered Total %
statement 32 32 100.0
branch n/a
condition n/a
subroutine 11 11 100.0
pod 1 1 100.0
total 44 44 100.0


line stmt bran cond sub pod time code
1             package Astro::ADS::QTree;
2             $Astro::ADS::QTree::VERSION = '1.92';
3 4     4   29 use Moo;
  4         9  
  4         41  
4              
5 4     4   1722 use Carp;
  4         8  
  4         384  
6 4     4   27 use Data::Dumper::Concise;
  4         92  
  4         317  
7 4     4   64 use Mojo::Base -strict; # do we want -signatures
  4         8  
  4         45  
8 4     4   1197 use Mojo::DOM;
  4         8  
  4         162  
9 4     4   19 use Mojo::File qw( path );
  4         7  
  4         2439  
10 4     4   28 use Mojo::URL;
  4         7  
  4         35  
11 4     4   155 use Mojo::Util qw( quote );
  4         19  
  4         274  
12 4     4   34 use PerlX::Maybe;
  4         6  
  4         38  
13 4     4   222 use Types::Standard qw( Int Str HashRef InstanceOf );
  4         6  
  4         45  
14              
15             #TODO are these required?
16             has [qw/q fq fl sort/] => (
17             is => 'rw',
18             isa => Str,
19             );
20             #TODO are these required?
21             has [qw/start rows/] => (
22             is => 'rw',
23             isa => Int->where( '$_ >= 0' ),
24             );
25             has qtree => (
26             is => 'rw',
27             isa => Str,
28             );
29             has [qw/qtime status/] => (
30             is => 'rw',
31             isa => Int->where( '$_ >= 0' ),
32             );
33             has error => (
34             is => 'rw',
35             isa => HashRef[]
36             );
37             has asset => (
38             is => 'rw',
39             isa => InstanceOf ['Mojo::Asset::Memory'],
40             );
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             before [qw/qtree qtime status asset/] => sub {
45             my ($self) = @_;
46             if ($self->error ) {
47             carp 'Empty Result object: ', $self->error->{message};
48             }
49             };
50              
51             sub move_to {
52 1     1 1 2159 my ($self, $file) = @_;
53              
54 1         30 return $self->asset->move_to( $file );
55             }
56              
57             1;
58              
59             =pod
60              
61             =encoding UTF-8
62              
63             =head1 NAME
64              
65             Astro::ADS::QTree - A class for the results of a Search Query Tree
66              
67             =head1 VERSION
68              
69             version 1.92
70              
71             =head1 SYNOPSIS
72              
73             my $search = Astro::ADS::Search->new(...);
74              
75             my $result = $search->query_tree();
76             say $result->qtree;
77              
78             $result->move_to( 'qtree.json' );
79              
80             =head1 DESCRIPTION
81              
82             The QTree class holds the
83             L<response|https://ui.adsabs.harvard.edu/help/api/api-docs.html#get-/search/qtree>
84             from an ADS search query tree. It will create attributes for the qtree and
85             responseHeader OR it will hold the error returned by the
86             L<UserAgent|Astro::ADS>. If an error was returned, any calls to attribute methods
87             will raise a polite warning that no fields will be available for that object.
88              
89             =head1 Methods
90              
91             =head2 move_to
92              
93             This method takes advantage of the Mojo::Asset's C<move_to> function to save the
94             content to a file. Currently, it saves the whole body of the response, whereas
95             the qtree value looks like it wants to be its own file, given the number of C<\n>
96             in the string.
97              
98             =head1 See Also
99              
100             =over 4
101              
102             =item * L<Astro::ADS>
103              
104             =item * L<Astro::ADS::Search>
105              
106             =item * L<ADS API|https://ui.adsabs.harvard.edu/help/api/>
107              
108             =back
109              
110             =head1 COPYRIGHT AND LICENSE
111              
112             This software is Copyright (c) 2025 by Boyd Duffee.
113              
114             This is free software, licensed under:
115              
116             The MIT (X11) License
117              
118             =cut