| 1 | package Astro::ADS::QTree; | ||||||||||
| 2 | 4 | $Astro::ADS::QTree::VERSION = '1.92'; | |||||||||
| 3 | 4 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 4 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 4 | ▶ | use Data::Dumper::Concise; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 4 | ▶ | use Mojo::Base -strict; # do we want -signatures | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 4 | ▶ | use Mojo::DOM; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 4 | ▶ | use Mojo::File qw( path ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 4 | ▶ | use Mojo::URL; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 4 | ▶ | use Mojo::Util qw( quote ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 4 | ▶ | use PerlX::Maybe; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 4 | ▶ | use Types::Standard qw( Int Str HashRef InstanceOf ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | |||||||||||
| 15 | #TODO are these required? | ||||||||||
| 16 | 4 | has [qw/q fq fl sort/] => ( | |||||||||
| 17 | is => 'rw', | ||||||||||
| 18 | isa => Str, | ||||||||||
| 19 | ); | ||||||||||
| 20 | #TODO are these required? | ||||||||||
| 21 | 4 | has [qw/start rows/] => ( | |||||||||
| 22 | is => 'rw', | ||||||||||
| 23 | isa => Int->where( '$_ >= 0' ), | ||||||||||
| 24 | ); | ||||||||||
| 25 | 4 | has qtree => ( | |||||||||
| 26 | is => 'rw', | ||||||||||
| 27 | isa => Str, | ||||||||||
| 28 | ); | ||||||||||
| 29 | 4 | has [qw/qtime status/] => ( | |||||||||
| 30 | is => 'rw', | ||||||||||
| 31 | isa => Int->where( '$_ >= 0' ), | ||||||||||
| 32 | ); | ||||||||||
| 33 | 4 | has error => ( | |||||||||
| 34 | is => 'rw', | ||||||||||
| 35 | isa => HashRef[] | ||||||||||
| 36 | ); | ||||||||||
| 37 | 4 | 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 | 2 | ▶ | before [qw/qtree qtime status asset/] => sub { | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=8.1
| |||||||||||
| 45 | 2 | my ($self) = @_; | |||||||||
| 46 | 2 | ▶ | if ($self->error ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 47 | 0 | carp 'Empty Result object: ', $self->error->{message}; | |||||||||
| 48 | } | ||||||||||
| 49 | 4 | }; | |||||||||
| 50 | |||||||||||
| 51 | 1 | ▶ | sub move_to { | ||||||||
|
Subroutine
move_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 52 | 1 | my ($self, $file) = @_; | |||||||||
| 53 | |||||||||||
| 54 | 1 | return $self->asset->move_to( $file ); | |||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | 4 | 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 | ||||||||||