| 1 | =head1 NAME | ||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||
| 3 | Astro::SIMBAD::Client - Fetch astronomical data from SIMBAD 4. | ||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||
| 5 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||
| 7 | use Astro::SIMBAD::Client; | ||||||||||||||||||||||||||||||||||
| 8 | my $simbad = Astro::SIMBAD::Client->new (); | ||||||||||||||||||||||||||||||||||
| 9 | print $simbad->query (id => 'Arcturus'); | ||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||
| 11 | =head1 NOTICE | ||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||
| 13 | As of release 0.027_01 the SOAP interface is deprecated. The University | ||||||||||||||||||||||||||||||||||
| 14 | of Strasbourg has announced at | ||||||||||||||||||||||||||||||||||
| 15 | C<https://cds.unistra.fr/resources.gml?id=soap> that this | ||||||||||||||||||||||||||||||||||
| 16 | interface will not be maintained after April 1 2014, and that | ||||||||||||||||||||||||||||||||||
| 17 | B<this interface will be stopped on December 31 2018>. | ||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||
| 19 | As of November 155 2026 the SOAP stuff is still non-functional, and even | ||||||||||||||||||||||||||||||||||
| 20 | the above documentation link is 404. Since the queries do not work | ||||||||||||||||||||||||||||||||||
| 21 | anyway I will make them fatal in the first release after May 15 2027, | ||||||||||||||||||||||||||||||||||
| 22 | and remove all SOAP code six months after that. The C<query()> interface | ||||||||||||||||||||||||||||||||||
| 23 | and friends B<may> remain simply because I find the interface more | ||||||||||||||||||||||||||||||||||
| 24 | convenient. | ||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||
| 26 | The following text under this heading is retained to give the history of | ||||||||||||||||||||||||||||||||||
| 27 | this issue. | ||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||
| 29 | Because the SOAP interface is still sort of functional (except for | ||||||||||||||||||||||||||||||||||
| 30 | VO-format queries) as of June 4 2014, I have revised the transition plan | ||||||||||||||||||||||||||||||||||
| 31 | announced with the release of 0.027_01 on October 28 2014. | ||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||
| 33 | What I have done as of version 0.031_01 is to add attribute | ||||||||||||||||||||||||||||||||||
| 34 | C<emulate_soap_queries>. This was false by default. If this attribute is | ||||||||||||||||||||||||||||||||||
| 35 | true, the C<query()> method and friends, instead of issuing a SOAP | ||||||||||||||||||||||||||||||||||
| 36 | request to the SIMBAD server, will instead construct an equivalent | ||||||||||||||||||||||||||||||||||
| 37 | script query, and issue that. The deprecation warning will not be issued | ||||||||||||||||||||||||||||||||||
| 38 | if C<emulate_soap_queries> is true, since the SOAP interface is not | ||||||||||||||||||||||||||||||||||
| 39 | being used. | ||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||
| 41 | As of March 22 2021, SOAP queries started returning 404. Because of | ||||||||||||||||||||||||||||||||||
| 42 | this, I have made the default of C<emulate_soap_queries> true. Well, | ||||||||||||||||||||||||||||||||||
| 43 | actually I have made it the Boolean inverse of environment variable | ||||||||||||||||||||||||||||||||||
| 44 | L<ASTRO_SIMBAD_CLIENT_USE_SOAP|/ASTRO_SIMBAD_CLIENT_USE_SOAP>. This is | ||||||||||||||||||||||||||||||||||
| 45 | mostly for my benefit, so I can see if SOAP has come back. | ||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||
| 47 | If SOAP still has not come back after six months, SOAP queries will | ||||||||||||||||||||||||||||||||||
| 48 | become fatal, as will setting C<emulate_soap_queries> to a false value. | ||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||
| 50 | Eventually the SOAP code will be removed. In the meantime all tests are | ||||||||||||||||||||||||||||||||||
| 51 | skipped unless C<ASTRO_SIMBAD_CLIENT_USE_SOAP> is true, and are marked | ||||||||||||||||||||||||||||||||||
| 52 | TODO. Support of SOAP by this module will be on a best-effort basis; | ||||||||||||||||||||||||||||||||||
| 53 | that is, if I can make it work without a huge amount of work I will -- | ||||||||||||||||||||||||||||||||||
| 54 | otherwise SOAP will become unsupported. | ||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||
| 56 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||
| 58 | This package implements several query interfaces to version 4 of the | ||||||||||||||||||||||||||||||||||
| 59 | SIMBAD on-line astronomical database, as documented at | ||||||||||||||||||||||||||||||||||
| 60 | L<https://simbad.unistra.fr/simbad4.htx>. B<This package will not work | ||||||||||||||||||||||||||||||||||
| 61 | with SIMBAD version 3.> Its primary purpose is to obtain SIMBAD data, | ||||||||||||||||||||||||||||||||||
| 62 | though some rudimentary parsing functionality also exists. | ||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||
| 64 | There are three ways to access these data. | ||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||
| 66 | - URL queries are essentially page scrapers, but their use is | ||||||||||||||||||||||||||||||||||
| 67 | documented, and output is available as HTML, text, or VOTable. URL | ||||||||||||||||||||||||||||||||||
| 68 | queries are implemented by the url_query() method. | ||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||
| 70 | - Scripts may be submitted using the script() or script_file() methods. | ||||||||||||||||||||||||||||||||||
| 71 | The former takes as its argument the text of the script, the latter | ||||||||||||||||||||||||||||||||||
| 72 | takes a file name. | ||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||
| 74 | - Queries may be made using the web services (SOAP) interface. The | ||||||||||||||||||||||||||||||||||
| 75 | query() method implements this, and queryObjectByBib, | ||||||||||||||||||||||||||||||||||
| 76 | queryObjectByCoord, and queryObjectById have been provided as | ||||||||||||||||||||||||||||||||||
| 77 | convenience methods. As of version 0.027_01, SOAP queries are | ||||||||||||||||||||||||||||||||||
| 78 | deprecated. See the L<NOTICE|/NOTICE> section above for the deprecation | ||||||||||||||||||||||||||||||||||
| 79 | schedule. | ||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||
| 81 | Astro::SIMBAD::Client is object-oriented, with the object supplying not | ||||||||||||||||||||||||||||||||||
| 82 | only the URL scheme and SIMBAD server name, but the default format and | ||||||||||||||||||||||||||||||||||
| 83 | output type for URL and web service queries. | ||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||
| 85 | A simple command line client application is also provided, as are | ||||||||||||||||||||||||||||||||||
| 86 | various examples in the F<eg> directory. | ||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||
| 88 | =head2 Methods | ||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||
| 90 | The following methods should be considered public: | ||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||
| 92 | =over 4 | ||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||
| 94 | =cut | ||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||
| 96 | package Astro::SIMBAD::Client; | ||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||
| 98 | # We require Perl 5.008 because of MailTools, used by SOAP::Lite. | ||||||||||||||||||||||||||||||||||
| 99 | # Otherwise it would be 5.006 because of 'our'. | ||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||
| 101 | 5 | ▶ | use 5.008; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||
| 103 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 104 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||
| 106 | 5 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 107 | 5 | ▶ | use LWP::UserAgent; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 108 | 5 | ▶ | use LWP::Protocol; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 109 | 5 | ▶ | use HTTP::Request::Common qw{POST}; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 110 | 5 | ▶ | use Scalar::Util 1.01 qw{looks_like_number}; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 111 | 5 | ▶ | use URI::Escape (); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 112 | # use XML::DoubleEncodedEntities; | ||||||||||||||||||||||||||||||||||
| 113 | # use Astro::SIMBAD::Client::WSQueryInterfaceService; | ||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||
| 115 | 5 | ▶ | use constant DEFAULT_SERVER => 'simbad.unistra.fr'; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 116 | 5 | ▶ | use constant HAVE_DOUBLE_ENCODED => do { | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 117 | 5 | local $@ = undef; | |||||||||||||||||||||||||||||||||
| 118 | 5 | eval { ## no critic (RequireCheckingReturnValueOfEval) | |||||||||||||||||||||||||||||||||
| 119 | 5 | require XML::DoubleEncodedEntities; | |||||||||||||||||||||||||||||||||
| 120 | 0 | 1; | |||||||||||||||||||||||||||||||||
| 121 | }; | ||||||||||||||||||||||||||||||||||
| 122 | 5 | }; | |||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||
| 124 | 5 | ▶ | use constant ARRAY_REF => ref []; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 125 | 5 | ▶ | use constant CODE_REF => ref sub {}; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
__ANON__: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 126 | 5 | ▶ | use constant HASH_REF => ref {}; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||
| 128 | 5 | my $have_time_hires; | |||||||||||||||||||||||||||||||||
| 129 | 5 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=3 SCAR=13.0
| |||||||||||||||||||||||||||||||||||
| 130 | 5 | $have_time_hires = eval { | |||||||||||||||||||||||||||||||||
| 131 | 5 | require Time::HiRes; | |||||||||||||||||||||||||||||||||
| 132 | 5 | Time::HiRes->import (qw{time sleep}); | |||||||||||||||||||||||||||||||||
| 133 | 5 | 1; | |||||||||||||||||||||||||||||||||
| 134 | }; | ||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||
| 136 | *_escape_uri = URI::Escape->can( 'uri_escape_utf8' ) | ||||||||||||||||||||||||||||||||||
| 137 | || URI::Escape->can( 'uri_escape' ) | ||||||||||||||||||||||||||||||||||
| 138 | 0 | ▶ | || sub { return $_[0] }; | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=2.2
Condition33%2/6
'URI::Escape'->can('uri_escape_utf8') || 'URI::Escape'->can('uri_escape') || sub {
return $_[0];
}
"URI::Escape"->can("uri_escape_utf8") or "URI::Escape"->can("uri_escape")
MC/DC0%0/3
'URI::Escape'->can('uri_escape_utf8') || 'URI::Escape'->can('uri_escape') || sub {
return $_[0];
}
"URI::Escape"->can("uri_escape_utf8")
"URI::Escape"->can("uri_escape")
sub {
return $_[0];
}
Truth table25%1/4
A or B || C
A= "URI::Escape"->can("uri_escape_utf8")B= "URI::Escape"->can("uri_escape")C= sub {
return $_[0];
}
| |||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||
| 141 | 5 | our $VERSION = '0.050_01'; | |||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||
| 143 | 5 | our @CARP_NOT = qw{Astro::SIMBAD::Client::WSQueryInterfaceService}; | |||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||
| 145 | # TODO replace this with s///r if we ever get to the point where we | ||||||||||||||||||||||||||||||||||
| 146 | # require Perl 5.13.2 or greater. | ||||||||||||||||||||||||||||||||||
| 147 | 10 | ▶ | sub _strip_returns { | ||||||||||||||||||||||||||||||||
|
Subroutine
_strip_returns: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 148 | 10 | my ( $data ) = @_; | |||||||||||||||||||||||||||||||||
| 149 | 10 | $data =~ s/ \n //smxg; | |||||||||||||||||||||||||||||||||
| 150 | 10 | return $data; | |||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||
| 153 | 5 | ▶ | use constant FORMAT_TXT_SIMPLE_BASIC => _strip_returns( <<'EOD' ); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 154 | ---\n | ||||||||||||||||||||||||||||||||||
| 155 | name: %IDLIST(NAME|1)\n | ||||||||||||||||||||||||||||||||||
| 156 | type: %OTYPE\n | ||||||||||||||||||||||||||||||||||
| 157 | long: %OTYPELIST\n | ||||||||||||||||||||||||||||||||||
| 158 | ra: %COO(d;A)\n | ||||||||||||||||||||||||||||||||||
| 159 | dec: %COO(d;D)\n | ||||||||||||||||||||||||||||||||||
| 160 | plx: %PLX(V)\n | ||||||||||||||||||||||||||||||||||
| 161 | pmra: %PM(A)\n | ||||||||||||||||||||||||||||||||||
| 162 | pmdec: %PM(D)\n | ||||||||||||||||||||||||||||||||||
| 163 | radial: %RV(V)\n | ||||||||||||||||||||||||||||||||||
| 164 | redshift: %RV(Z)\n | ||||||||||||||||||||||||||||||||||
| 165 | spec: %SP(S)\n | ||||||||||||||||||||||||||||||||||
| 166 | bmag: %FLUXLIST(B)[%flux(F)]\n | ||||||||||||||||||||||||||||||||||
| 167 | vmag: %FLUXLIST(V)[%flux(F)]\n | ||||||||||||||||||||||||||||||||||
| 168 | ident: %IDLIST[%*,] | ||||||||||||||||||||||||||||||||||
| 169 | EOD | ||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||
| 171 | 5 | ▶ | use constant FORMAT_TXT_YAML_BASIC => _strip_returns( <<'EOD' ); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 172 | ---\n | ||||||||||||||||||||||||||||||||||
| 173 | name: '%IDLIST(NAME|1)'\n | ||||||||||||||||||||||||||||||||||
| 174 | type: '%OTYPE'\n | ||||||||||||||||||||||||||||||||||
| 175 | long: '%OTYPELIST'\n | ||||||||||||||||||||||||||||||||||
| 176 | ra: %COO(d;A)\n | ||||||||||||||||||||||||||||||||||
| 177 | dec: %COO(d;D)\n | ||||||||||||||||||||||||||||||||||
| 178 | plx: %PLX(V)\n | ||||||||||||||||||||||||||||||||||
| 179 | pm:\n | ||||||||||||||||||||||||||||||||||
| 180 | - %PM(A)\n | ||||||||||||||||||||||||||||||||||
| 181 | - %PM(D)\n | ||||||||||||||||||||||||||||||||||
| 182 | radial: %RV(V)\n | ||||||||||||||||||||||||||||||||||
| 183 | redshift: %RV(Z)\n | ||||||||||||||||||||||||||||||||||
| 184 | spec: %SP(S)\n | ||||||||||||||||||||||||||||||||||
| 185 | bmag: %FLUXLIST(B)[%flux(F)]\n | ||||||||||||||||||||||||||||||||||
| 186 | vmag: %FLUXLIST(V)[%flux(F)]\n | ||||||||||||||||||||||||||||||||||
| 187 | ident:\n%IDLIST[ - '%*'\n] | ||||||||||||||||||||||||||||||||||
| 188 | EOD | ||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||
| 190 | # Documentation errors/omissions: | ||||||||||||||||||||||||||||||||||
| 191 | # %PLX: | ||||||||||||||||||||||||||||||||||
| 192 | # P = something. Yields '2' for Arcturus | ||||||||||||||||||||||||||||||||||
| 193 | # %SP: is really %sptype | ||||||||||||||||||||||||||||||||||
| 194 | # B = bibcode? Yields '~' for Arcturus | ||||||||||||||||||||||||||||||||||
| 195 | # N = don't know -- yields 'S' for Arcturus | ||||||||||||||||||||||||||||||||||
| 196 | # Q = quality? Yields 'C' for Arcturus | ||||||||||||||||||||||||||||||||||
| 197 | # S = spectral type | ||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||
| 199 | 5 | ▶ | use constant FORMAT_VO_BASIC => join ',', qw{ | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 200 | id(NAME|1) otype ra(d) dec(d) plx_value pmra pmdec rv_value z_value | ||||||||||||||||||||||||||||||||||
| 201 | 5 | sp_type flux(B) flux(V)}; | |||||||||||||||||||||||||||||||||
| 202 | # Note that idlist was documented at one point as being the | ||||||||||||||||||||||||||||||||||
| 203 | # VOTable equivalent of %IDLIST. But it is no longer documented, | ||||||||||||||||||||||||||||||||||
| 204 | # and never returned anything but '<TD>?IDLIST</TD>'. | ||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||
| 206 | my %static = ( | ||||||||||||||||||||||||||||||||||
| 207 | autoload => 1, | ||||||||||||||||||||||||||||||||||
| 208 | debug => 0, | ||||||||||||||||||||||||||||||||||
| 209 | delay => 3, | ||||||||||||||||||||||||||||||||||
| 210 | emulate_soap_queries => ! $ENV{ASTRO_SIMBAD_CLIENT_USE_SOAP}, | ||||||||||||||||||||||||||||||||||
| 211 | format => { | ||||||||||||||||||||||||||||||||||
| 212 | txt => FORMAT_TXT_YAML_BASIC, | ||||||||||||||||||||||||||||||||||
| 213 | vo => FORMAT_VO_BASIC, | ||||||||||||||||||||||||||||||||||
| 214 | script => '', | ||||||||||||||||||||||||||||||||||
| 215 | }, | ||||||||||||||||||||||||||||||||||
| 216 | parser => { | ||||||||||||||||||||||||||||||||||
| 217 | txt => '', | ||||||||||||||||||||||||||||||||||
| 218 | vo => '', | ||||||||||||||||||||||||||||||||||
| 219 | script => '', | ||||||||||||||||||||||||||||||||||
| 220 | }, | ||||||||||||||||||||||||||||||||||
| 221 | post => 1, | ||||||||||||||||||||||||||||||||||
| 222 | # lc(...) per https://tools.ietf.org/html/rfc3986#section-3.1 | ||||||||||||||||||||||||||||||||||
| 223 | scheme => lc( $ENV{ASTRO_SIMBAD_CLIENT_SCHEME} || 'https' ), | ||||||||||||||||||||||||||||||||||
| 224 | ## server => 'simbad.unistra.fr', | ||||||||||||||||||||||||||||||||||
| 225 | 5 | ▶ | server => $ENV{ASTRO_SIMBAD_CLIENT_SERVER} || DEFAULT_SERVER, | ||||||||||||||||||||||||||||||||
|
Condition50%2/4
$ENV{'ASTRO_SIMBAD_CLIENT_SCHEME'} || 'https'
$ENV{'ASTRO_SIMBAD_CLIENT_SERVER'} || 'simbad.unistra.fr'
MC/DC0%0/1
$ENV{'ASTRO_SIMBAD_CLIENT_SCHEME'} || 'https'
$ENV{'ASTRO_SIMBAD_CLIENT_SCHEME'}
MC/DC0%0/1
$ENV{'ASTRO_SIMBAD_CLIENT_SERVER'} || 'simbad.unistra.fr'
$ENV{'ASTRO_SIMBAD_CLIENT_SERVER'}
Truth table50%1/2
A
A= $ENV{'ASTRO_SIMBAD_CLIENT_SCHEME'}
Truth table50%1/2
A
A= $ENV{'ASTRO_SIMBAD_CLIENT_SERVER'}
| |||||||||||||||||||||||||||||||||||
| 226 | timeout => LWP::UserAgent->new()->timeout(), | ||||||||||||||||||||||||||||||||||
| 227 | type => 'txt', | ||||||||||||||||||||||||||||||||||
| 228 | url_args => {}, | ||||||||||||||||||||||||||||||||||
| 229 | verbatim => 0, | ||||||||||||||||||||||||||||||||||
| 230 | ); | ||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||
| 232 | 5 | ▶ | if ( $static{server} eq 'random' ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 233 | 0 | __random_server( $static{server}, DEFAULT_SERVER ); | |||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||
| 236 | 5 | ▶ | if ( my $msg = _is_scheme_valid( | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 237 | $static{scheme}, | ||||||||||||||||||||||||||||||||||
| 238 | q<Unsupported ASTRO_SIMBAD_CLIENT_SCHEME '%s'; falling back to 'http'>, | ||||||||||||||||||||||||||||||||||
| 239 | ) ) { | ||||||||||||||||||||||||||||||||||
| 240 | 0 | carp $msg; | |||||||||||||||||||||||||||||||||
| 241 | 0 | $static{scheme} = 'http'; | |||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||
| 244 | =item $simbad = Astro::SIMBAD::Client->new (); | ||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||
| 246 | This method instantiates an Astro::SIMBAD::Client object. Any arguments will be | ||||||||||||||||||||||||||||||||||
| 247 | passed to the set() method once the object is instantiated. | ||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||
| 249 | =cut | ||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||
| 251 | # The set() method does the unpacking. CAVEAT: do _NOT_ modify the | ||||||||||||||||||||||||||||||||||
| 252 | # contents of @_, as this will be seen by the caller. Modifying @_ | ||||||||||||||||||||||||||||||||||
| 253 | # itself is fine. | ||||||||||||||||||||||||||||||||||
| 254 | 8 | ▶ | sub new { ## no critic (RequireArgUnpacking) | ||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 255 | 8 | my $class = shift; | |||||||||||||||||||||||||||||||||
| 256 | 8 | ▶ | $class = ref $class if ref $class; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 257 | 8 | my $self = bless {}, $class; | |||||||||||||||||||||||||||||||||
| 258 | 8 | $self->set (%static, @_); | |||||||||||||||||||||||||||||||||
| 259 | 8 | return $self; | |||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||
| 262 | =item $string = $simbad->agent (); | ||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||
| 264 | This method retrieves the user agent string used to identify this | ||||||||||||||||||||||||||||||||||
| 265 | package in queries to SIMBAD. This string will be the default string for | ||||||||||||||||||||||||||||||||||
| 266 | LWP::UserAgent, with this package name and version number appended in | ||||||||||||||||||||||||||||||||||
| 267 | parentheses. This method is exposed for the curious. | ||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||
| 269 | =cut | ||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||
| 271 | { | ||||||||||||||||||||||||||||||||||
| 272 | 5 | my $agent_string; | |||||||||||||||||||||||||||||||||
| 273 | 9 | ▶ | sub agent { | ||||||||||||||||||||||||||||||||
|
Subroutine
agent: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 274 | 9 | ▶ | return ($agent_string ||= join (' ', LWP::UserAgent->_agent, | ||||||||||||||||||||||||||||||||
|
Condition66%2/3
$agent_string ||= join(" ", "LWP::UserAgent"->_agent, 'Astro::SIMBAD::Client/' . $Astro::SIMBAD::Client::VERSION)
MC/DC0%0/2
$agent_string ||= join(" ", "LWP::UserAgent"->_agent, 'Astro::SIMBAD::Client/' . $Astro::SIMBAD::Client::VERSION)
$agent_string
join(" ", "LWP::UserAgent"->_agent, 'Astro::SIMBAD::Client/' . $Astro::SIMBAD::Client::VERSION)
Truth table66%2/3
A ||= B
A= $agent_stringB= join(" ", "LWP::UserAgent"->_agent, 'Astro::SIMBAD::Client/' . $Astro::SIMBAD::Client::VERSION)
| |||||||||||||||||||||||||||||||||||
| 275 | __PACKAGE__ . '/' . $VERSION)); | ||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||
| 279 | =item @attribs = $simbad->attributes (); | ||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||
| 281 | This method retrieves the names of all public attributes, in | ||||||||||||||||||||||||||||||||||
| 282 | alphabetical order. It can be called as a static method, or | ||||||||||||||||||||||||||||||||||
| 283 | even as a subroutine. | ||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||
| 285 | =cut | ||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||
| 287 | 5 | ▶ | sub attributes { | ||||||||||||||||||||||||||||||||
|
Subroutine
attributes: not called CC=2 SCAR=13.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 288 | 0 | ▶ | return wantarray ? sort keys %static : [sort keys %static] | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||
| 291 | =item $value = $simbad->get ($attrib); | ||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||
| 293 | This method retrieves the current value of the named | ||||||||||||||||||||||||||||||||||
| 294 | L<attribute|/Attributes>. It can be called as a static method to | ||||||||||||||||||||||||||||||||||
| 295 | retrieve the default value. | ||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||
| 297 | =cut | ||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||
| 299 | 80 | ▶ | sub get { | ||||||||||||||||||||||||||||||||
|
Subroutine
get: called CC=4 SCAR=14.8
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 300 | 80 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 301 | 0 | croak "Error - First argument must be an @{[__PACKAGE__]} object" | |||||||||||||||||||||||||||||||||
| 302 | 80 | ▶ | unless eval {$self->isa(__PACKAGE__)}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 303 | 80 | ▶ | $self = \%static unless ref $self; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 304 | 80 | my $name = shift; | |||||||||||||||||||||||||||||||||
| 305 | croak "Error - Attribute '$name' is unknown" | ||||||||||||||||||||||||||||||||||
| 306 | 80 | ▶ | unless exists $static{$name}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 307 | 80 | return $self->{$name}; | |||||||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||
| 310 | =item $result = Parse_TXT_Simple ($data); | ||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||
| 312 | This subroutine (B<not> method) parses the given text data under the | ||||||||||||||||||||||||||||||||||
| 313 | assumption that it was generated using FORMAT_TXT_SIMPLE_BASIC or | ||||||||||||||||||||||||||||||||||
| 314 | something similar. The data is expected to be formatted as follows: | ||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||
| 316 | A line consisting of exactly '---' separates objects. | ||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||
| 318 | Data appear on lines that look like | ||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||
| 320 | name: data | ||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||
| 322 | and are parsed into a hash keyed by the given name. If the line ends | ||||||||||||||||||||||||||||||||||
| 323 | with a comma, it is assumed to contain multiple items, and the data | ||||||||||||||||||||||||||||||||||
| 324 | portion of the line is split on the commas; the resultant hash value | ||||||||||||||||||||||||||||||||||
| 325 | is a list reference. | ||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||
| 327 | The user would normally not call this directly, but specify it as the | ||||||||||||||||||||||||||||||||||
| 328 | parser for 'txt'-type queries: | ||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||
| 330 | $simbad->set (parser => {txt => 'Parse_TXT_Simple'}); | ||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||
| 332 | =cut | ||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||
| 334 | 3 | ▶ | sub Parse_TXT_Simple { | ||||||||||||||||||||||||||||||||
|
Subroutine
Parse_TXT_Simple: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 335 | 3 | my $text = shift; | |||||||||||||||||||||||||||||||||
| 336 | 3 | my $obj = {}; | |||||||||||||||||||||||||||||||||
| 337 | 3 | my @data; | |||||||||||||||||||||||||||||||||
| 338 | 3 | foreach (split '\s*\n', $text) { | |||||||||||||||||||||||||||||||||
| 339 | 45 | ▶ | next unless $_; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 340 | 45 | ▶ | if (m/^-+$/) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 341 | 3 | $obj = {}; | |||||||||||||||||||||||||||||||||
| 342 | 3 | push @data, $obj; | |||||||||||||||||||||||||||||||||
| 343 | } else { | ||||||||||||||||||||||||||||||||||
| 344 | 42 | my ($name, $val) = split ':\s*', $_; | |||||||||||||||||||||||||||||||||
| 345 | 42 | ▶ | $val =~ s/,$// and $val = [split ',', $val]; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 346 | 42 | $obj->{$name} = $val; | |||||||||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||||||||
| 349 | 3 | return @data; | |||||||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||
| 352 | =item $result = Parse_VO_Table ($data); | ||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||
| 354 | This subroutine (B<not> method) parses the given VOTable data, | ||||||||||||||||||||||||||||||||||
| 355 | returning a list of anonymous hashes describing the data. The $data | ||||||||||||||||||||||||||||||||||
| 356 | value is split on '<?xml' before parsing, so that you get multiple | ||||||||||||||||||||||||||||||||||
| 357 | VOTables back (rather than a parse error) if that is what the input | ||||||||||||||||||||||||||||||||||
| 358 | contains. | ||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||
| 360 | This is B<not> a full-grown VOTable parser capable of handling | ||||||||||||||||||||||||||||||||||
| 361 | the full spec (see L<https://www.ivoa.net/documents/VOTable/>). | ||||||||||||||||||||||||||||||||||
| 362 | It is oriented toward returning E<lt>TABLEDATAE<gt> contents, and the | ||||||||||||||||||||||||||||||||||
| 363 | metadata that can reasonably be associated with those contents. | ||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||
| 365 | B<NOTE> that as of version 0.026_01, the requisite modules | ||||||||||||||||||||||||||||||||||
| 366 | to support VO format are B<not> required. If you need VO format you will | ||||||||||||||||||||||||||||||||||
| 367 | need to install L<XML::Parser|XML::Parser> or L<XML::Parser::Lite> | ||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||
| 369 | The return is a list of anonymous hashes, one per E<lt>TABLEE<gt>. Each | ||||||||||||||||||||||||||||||||||
| 370 | hash contains two keys: | ||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||
| 372 | {data} is the data contained in the table, and | ||||||||||||||||||||||||||||||||||
| 373 | {meta} is the metadata for the table. | ||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||
| 375 | The {meta} element for the table is a reference to a list of data | ||||||||||||||||||||||||||||||||||
| 376 | gathered from the E<lt>TABLEE<gt> tag. Element zero is the tag name | ||||||||||||||||||||||||||||||||||
| 377 | ('TABLE'), and element 1 is a reference to a hash containing the | ||||||||||||||||||||||||||||||||||
| 378 | attributes of the E<lt>TABLEE<gt> tag. Subsequent elements if any | ||||||||||||||||||||||||||||||||||
| 379 | represent metadata tags in the order encountered in the parse. | ||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||
| 381 | The {data} contains an anonymous list, each element of which is a row of | ||||||||||||||||||||||||||||||||||
| 382 | data from the E<lt>TABLEDATAE<gt> element of the E<lt>TABLEE<gt>, in the | ||||||||||||||||||||||||||||||||||
| 383 | order encountered by the parse. Each row is a reference to a list of | ||||||||||||||||||||||||||||||||||
| 384 | anonymous hashes, which represent the individual data of the row, in the | ||||||||||||||||||||||||||||||||||
| 385 | order encountered by the parse. The data hashes contain two keys: | ||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||
| 387 | {value} is the value of the datum with undef for '~', and | ||||||||||||||||||||||||||||||||||
| 388 | {meta} is a reference to the metadata for the datum. | ||||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||||
| 390 | The {meta} element for a datum is a reference to the metadata tag that | ||||||||||||||||||||||||||||||||||
| 391 | describes that datum. This will be an anonymous list, of which element 0 | ||||||||||||||||||||||||||||||||||
| 392 | is the tag ('FIELD'), element 1 is a reference to a hash containing that | ||||||||||||||||||||||||||||||||||
| 393 | tag's attributes, and subsequent elements will be the contents of the | ||||||||||||||||||||||||||||||||||
| 394 | tag (typically including a reference to the list representing the | ||||||||||||||||||||||||||||||||||
| 395 | E<lt>DESCRIPTIONE<gt> tag for that FIELD). | ||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||
| 397 | All values are returned as provided by the XML parser; no further | ||||||||||||||||||||||||||||||||||
| 398 | decoding is done. Specifically, the datatype and arraysize attributes | ||||||||||||||||||||||||||||||||||
| 399 | are ignored. | ||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||
| 401 | This parser is based on XML::Parser. | ||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||
| 403 | The user would normally not call this directly, but specify it as the | ||||||||||||||||||||||||||||||||||
| 404 | parser for 'vo'-type queries: | ||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||
| 406 | $simbad->set (parser => {vo => 'Parse_VO_Table'}); | ||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||
| 408 | =cut | ||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||
| 410 | { # Begin local symbol block. | ||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||
| 412 | 5 | my $xml_parser; | |||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||
| 414 | # TODO get rid of XML::Parser::Lite when you get rid of SOAP | ||||||||||||||||||||||||||||||||||
| 415 | 5 | foreach (qw{XML::Parser XML::Parser::Lite}) { | |||||||||||||||||||||||||||||||||
| 416 | 0 | ▶ | eval { _load_module( $_ ); 1 } or next; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 417 | 0 | $xml_parser = $_; | |||||||||||||||||||||||||||||||||
| 418 | 0 | last; | |||||||||||||||||||||||||||||||||
| 419 | } | ||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||
| 421 | 0 | ▶ | sub Parse_VO_Table { | ||||||||||||||||||||||||||||||||
|
Subroutine
Parse_VO_Table: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 422 | 0 | my $data = shift; | |||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||
| 424 | 0 | ▶ | defined $xml_parser | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 425 | or croak 'Error - No XML parser available. Need XML::Parser or XML::Parser::Lite'; | ||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||
| 427 | 0 | my $root; | |||||||||||||||||||||||||||||||||
| 428 | my @tree; | ||||||||||||||||||||||||||||||||||
| 429 | 0 | my @table; | |||||||||||||||||||||||||||||||||
| 430 | 0 | my @to_strip; | |||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||||
| 432 | # Arguments: | ||||||||||||||||||||||||||||||||||
| 433 | # Init ($class) | ||||||||||||||||||||||||||||||||||
| 434 | # Start ($class, $tag, $attr => $value ...) | ||||||||||||||||||||||||||||||||||
| 435 | # Char ($class, $text) | ||||||||||||||||||||||||||||||||||
| 436 | # End ($class, $tag) | ||||||||||||||||||||||||||||||||||
| 437 | # Final ($class) | ||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||
| 439 | my $psr = $xml_parser->new ( | ||||||||||||||||||||||||||||||||||
| 440 | Handlers => { | ||||||||||||||||||||||||||||||||||
| 441 | 0 | ▶ | Init => sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 442 | 0 | $root = []; | |||||||||||||||||||||||||||||||||
| 443 | 0 | @tree = ($root); | |||||||||||||||||||||||||||||||||
| 444 | 0 | @table = (); | |||||||||||||||||||||||||||||||||
| 445 | }, | ||||||||||||||||||||||||||||||||||
| 446 | 0 | ▶ | Start => sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 447 | 0 | shift; | |||||||||||||||||||||||||||||||||
| 448 | 0 | my $tag = shift; | |||||||||||||||||||||||||||||||||
| 449 | 0 | my $item = [$tag, {@_}]; | |||||||||||||||||||||||||||||||||
| 450 | 0 | push @{$tree[-1]}, $item; | |||||||||||||||||||||||||||||||||
| 451 | 0 | push @tree, $item; | |||||||||||||||||||||||||||||||||
| 452 | }, | ||||||||||||||||||||||||||||||||||
| 453 | 0 | ▶ | Char => sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 454 | 0 | push @{$tree[-1]}, $_[1]; | |||||||||||||||||||||||||||||||||
| 455 | }, | ||||||||||||||||||||||||||||||||||
| 456 | 0 | ▶ | End => sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=20 SCAR=60.4
| |||||||||||||||||||||||||||||||||||
| 457 | 0 | my $tag = $_[1]; | |||||||||||||||||||||||||||||||||
| 458 | 0 | ▶ | die <<eod unless @tree > 1; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 459 | Error - Unmatched end tag </$tag> | ||||||||||||||||||||||||||||||||||
| 460 | eod | ||||||||||||||||||||||||||||||||||
| 461 | 0 | ▶ | die <<eod unless $tag eq $tree[-1][0]; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 462 | Error - End tag </$tag> does not match start tag <$tree[-1][0]> | ||||||||||||||||||||||||||||||||||
| 463 | eod | ||||||||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||||||||
| 465 | # From here to the end of the subroutine is devoted to detecting | ||||||||||||||||||||||||||||||||||
| 466 | # the </TABLE> tag and extracting the data of the table into what | ||||||||||||||||||||||||||||||||||
| 467 | # is hopefully a more usable format. Any relationship of tables | ||||||||||||||||||||||||||||||||||
| 468 | # to resources is lost. | ||||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||||
| 470 | 0 | my $element = pop @tree; | |||||||||||||||||||||||||||||||||
| 471 | 0 | ▶ | if ($element->[0] eq 'TABLE') { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 472 | 0 | my (@meta, @data, @descr); | |||||||||||||||||||||||||||||||||
| 473 | 0 | foreach (@$element) { | |||||||||||||||||||||||||||||||||
| 474 | 0 | ▶ | next unless ARRAY_REF eq ref $_; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 475 | 0 | ▶ | if ($_->[0] eq 'FIELD') { | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 476 | 0 | push @meta, $_; | |||||||||||||||||||||||||||||||||
| 477 | 0 | push @descr, $_; | |||||||||||||||||||||||||||||||||
| 478 | } elsif ($_->[0] eq 'DATA') { | ||||||||||||||||||||||||||||||||||
| 479 | 0 | foreach (@$_) { | |||||||||||||||||||||||||||||||||
| 480 | 0 | ▶ | next unless ARRAY_REF eq ref $_; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 481 | 0 | ▶ | next unless $_->[0] eq 'TABLEDATA'; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 482 | 0 | foreach (@$_) { | |||||||||||||||||||||||||||||||||
| 483 | 0 | ▶ | next unless ARRAY_REF eq ref $_; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 484 | 0 | ▶ | next unless $_->[0] eq 'TR'; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 485 | 0 | my @row; | |||||||||||||||||||||||||||||||||
| 486 | 0 | foreach (@$_) { | |||||||||||||||||||||||||||||||||
| 487 | 0 | ▶ | next unless ARRAY_REF eq ref $_; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 488 | 0 | ▶ | next unless $_->[0] eq 'TD'; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 489 | 0 | my @inf = grep {!ref $_} @$_; | |||||||||||||||||||||||||||||||||
| 490 | 0 | shift @inf; | |||||||||||||||||||||||||||||||||
| 491 | 0 | push @row, join ' ', @inf; | |||||||||||||||||||||||||||||||||
| 492 | } | ||||||||||||||||||||||||||||||||||
| 493 | 0 | push @data, \@row; | |||||||||||||||||||||||||||||||||
| 494 | } | ||||||||||||||||||||||||||||||||||
| 495 | } | ||||||||||||||||||||||||||||||||||
| 496 | } else { | ||||||||||||||||||||||||||||||||||
| 497 | 0 | push @descr, $_; | |||||||||||||||||||||||||||||||||
| 498 | } | ||||||||||||||||||||||||||||||||||
| 499 | } | ||||||||||||||||||||||||||||||||||
| 500 | 0 | foreach (@data) { | |||||||||||||||||||||||||||||||||
| 501 | 0 | my $inx = 0; | |||||||||||||||||||||||||||||||||
| 502 | 0 | @$_ = map { { | |||||||||||||||||||||||||||||||||
| 503 | 0 | ▶ | value => (defined $_ && $_ eq '~') | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $_ and $_ eq "~"
MC/DC0%0/2
defined $_ and $_ eq "~"
defined $_
$_ eq "~"
Truth table0%0/3
A and B
A= defined $_B= $_ eq "~"
| |||||||||||||||||||||||||||||||||||
| 504 | ? undef : $_, | ||||||||||||||||||||||||||||||||||
| 505 | meta => $meta[$inx++], | ||||||||||||||||||||||||||||||||||
| 506 | } } @$_; | ||||||||||||||||||||||||||||||||||
| 507 | } | ||||||||||||||||||||||||||||||||||
| 508 | 0 | push @to_strip, @descr; | |||||||||||||||||||||||||||||||||
| 509 | 0 | push @table, { | |||||||||||||||||||||||||||||||||
| 510 | data => \@data, | ||||||||||||||||||||||||||||||||||
| 511 | meta => [$element->[0], | ||||||||||||||||||||||||||||||||||
| 512 | $element->[1], @descr], | ||||||||||||||||||||||||||||||||||
| 513 | }; | ||||||||||||||||||||||||||||||||||
| 514 | } | ||||||||||||||||||||||||||||||||||
| 515 | }, | ||||||||||||||||||||||||||||||||||
| 516 | 0 | ▶ | Final => sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||
| 517 | 0 | ▶ | die <<eod if @tree > 1; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 518 | Error - Missing end tags. | ||||||||||||||||||||||||||||||||||
| 519 | eod | ||||||||||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||||||||
| 521 | ## _strip_empty ($root); | ||||||||||||||||||||||||||||||||||
| 522 | ## @$root; | ||||||||||||||||||||||||||||||||||
| 523 | # If the previous two lines were uncommented and the following two | ||||||||||||||||||||||||||||||||||
| 524 | # commented, the parser would return the parse tree for the | ||||||||||||||||||||||||||||||||||
| 525 | # VOTable. | ||||||||||||||||||||||||||||||||||
| 526 | 0 | _strip_empty (\@to_strip); | |||||||||||||||||||||||||||||||||
| 527 | 0 | @table; | |||||||||||||||||||||||||||||||||
| 528 | }, | ||||||||||||||||||||||||||||||||||
| 529 | 0 | }); | |||||||||||||||||||||||||||||||||
| 530 | 0 | ▶ | return map {$_ ? $psr->parse ($_) : ()} split '(?=<\?xml)', $data | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 531 | } | ||||||||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||||||||
| 533 | } # End of local symbol block. | ||||||||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||||||||
| 535 | # _strip_empty (\@tree) | ||||||||||||||||||||||||||||||||||
| 536 | # | ||||||||||||||||||||||||||||||||||
| 537 | # splices out anything in the tree that is not a reference and | ||||||||||||||||||||||||||||||||||
| 538 | # does not match m/\S/. | ||||||||||||||||||||||||||||||||||
| 539 | |||||||||||||||||||||||||||||||||||
| 540 | 5 | ▶ | sub _strip_empty { | ||||||||||||||||||||||||||||||||
|
Subroutine
_strip_empty: not called CC=5 SCAR=32.6
| |||||||||||||||||||||||||||||||||||
| 541 | 0 | my $ref = shift; | |||||||||||||||||||||||||||||||||
| 542 | 0 | my $inx = @$ref; | |||||||||||||||||||||||||||||||||
| 543 | 0 | ▶ | while (--$inx >= 0) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 544 | 0 | my $val = $ref->[$inx]; | |||||||||||||||||||||||||||||||||
| 545 | 0 | my $typ = ref $val; | |||||||||||||||||||||||||||||||||
| 546 | 0 | ▶ | if ( ARRAY_REF eq $typ ) { | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 547 | 0 | _strip_empty ($val); | |||||||||||||||||||||||||||||||||
| 548 | } elsif (!$typ) { | ||||||||||||||||||||||||||||||||||
| 549 | 0 | ▶ | splice @$ref, $inx, 1 unless $val =~ m/\S/ms; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 550 | } | ||||||||||||||||||||||||||||||||||
| 551 | } | ||||||||||||||||||||||||||||||||||
| 552 | 0 | return; | |||||||||||||||||||||||||||||||||
| 553 | } | ||||||||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||||||||
| 555 | =item $result = $simbad->query ($query => @args); | ||||||||||||||||||||||||||||||||||
| 556 | |||||||||||||||||||||||||||||||||||
| 557 | This method is B<deprecated>, and will cease to work in April 2014. | ||||||||||||||||||||||||||||||||||
| 558 | Please choose a method that does not use SOAP. See the L<NOTICE|/NOTICE> | ||||||||||||||||||||||||||||||||||
| 559 | above for details. | ||||||||||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||||||||
| 561 | This method issues a web services (SOAP) query to the SIMBAD database. | ||||||||||||||||||||||||||||||||||
| 562 | The $query specifies a SIMBAD query method, and the @args are the | ||||||||||||||||||||||||||||||||||
| 563 | arguments for that method. Valid $query values and the corresponding | ||||||||||||||||||||||||||||||||||
| 564 | SIMBAD methods and arguments are: | ||||||||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||||||||
| 566 | bib => queryObjectByBib ($bibcode, $format, $type) | ||||||||||||||||||||||||||||||||||
| 567 | coo => queryObjectByCoord ($coord, $radius, $format, $type) | ||||||||||||||||||||||||||||||||||
| 568 | id => queryObjectById ($id, $format, $type) | ||||||||||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||||||||
| 570 | where: | ||||||||||||||||||||||||||||||||||
| 571 | |||||||||||||||||||||||||||||||||||
| 572 | $bibcode is a SIMBAD bibliographic code | ||||||||||||||||||||||||||||||||||
| 573 | $coord is a set of coordinates | ||||||||||||||||||||||||||||||||||
| 574 | $radius is an angular radius around the coordinates | ||||||||||||||||||||||||||||||||||
| 575 | $type is the type of data to be returned | ||||||||||||||||||||||||||||||||||
| 576 | $format is a format appropriate to the data type. | ||||||||||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||||||||
| 578 | The $type defaults to the value of the L<type|/type> attribute, and | ||||||||||||||||||||||||||||||||||
| 579 | the $format defaults to the value of the L<format|/format> attribute | ||||||||||||||||||||||||||||||||||
| 580 | for the given $type. | ||||||||||||||||||||||||||||||||||
| 581 | |||||||||||||||||||||||||||||||||||
| 582 | The return value depends on a number of factors: | ||||||||||||||||||||||||||||||||||
| 583 | |||||||||||||||||||||||||||||||||||
| 584 | If the query found nothing, you get undef in scalar context, and an | ||||||||||||||||||||||||||||||||||
| 585 | empty list in list context. | ||||||||||||||||||||||||||||||||||
| 586 | |||||||||||||||||||||||||||||||||||
| 587 | If a L<parser|/parser> is defined for the given type, the returned | ||||||||||||||||||||||||||||||||||
| 588 | data will be fed to the parser, and the output of the parser will be | ||||||||||||||||||||||||||||||||||
| 589 | returned. This is assumed to be a list, so a reference to the list | ||||||||||||||||||||||||||||||||||
| 590 | will be used in scalar context. Parser exceptions are not trapped, | ||||||||||||||||||||||||||||||||||
| 591 | so the caller will need to be prepared to deal with malformed data. | ||||||||||||||||||||||||||||||||||
| 592 | |||||||||||||||||||||||||||||||||||
| 593 | Otherwise, the result of the query is returned as-is. | ||||||||||||||||||||||||||||||||||
| 594 | |||||||||||||||||||||||||||||||||||
| 595 | B<NOTE> that this functionality makes use of the | ||||||||||||||||||||||||||||||||||
| 596 | L<SOAP::Lite|SOAP::Lite> module. As of version 0.026_01 of | ||||||||||||||||||||||||||||||||||
| 597 | C<Astro::SIMBAD::Client>, L<SOAP::Lite|SOAP::Lite> is not a prerequisite | ||||||||||||||||||||||||||||||||||
| 598 | of this module. If you wish to use the C<query()> method, you will have | ||||||||||||||||||||||||||||||||||
| 599 | to install L<SOAP::Lite|SOAP::Lite> separately. This can be done after | ||||||||||||||||||||||||||||||||||
| 600 | C<Astro::SIMBAD::Client> is installed. | ||||||||||||||||||||||||||||||||||
| 601 | |||||||||||||||||||||||||||||||||||
| 602 | =cut | ||||||||||||||||||||||||||||||||||
| 603 | |||||||||||||||||||||||||||||||||||
| 604 | { # Begin local symbol block | ||||||||||||||||||||||||||||||||||
| 605 | |||||||||||||||||||||||||||||||||||
| 606 | 5 | my %query_args = ( | |||||||||||||||||||||||||||||||||
| 607 | id => { | ||||||||||||||||||||||||||||||||||
| 608 | type => 2, | ||||||||||||||||||||||||||||||||||
| 609 | format => 1, | ||||||||||||||||||||||||||||||||||
| 610 | method => 'queryObjectById', | ||||||||||||||||||||||||||||||||||
| 611 | }, | ||||||||||||||||||||||||||||||||||
| 612 | bib => { | ||||||||||||||||||||||||||||||||||
| 613 | type => 2, | ||||||||||||||||||||||||||||||||||
| 614 | format => 1, | ||||||||||||||||||||||||||||||||||
| 615 | method => 'queryObjectByBib', | ||||||||||||||||||||||||||||||||||
| 616 | }, | ||||||||||||||||||||||||||||||||||
| 617 | coo => { | ||||||||||||||||||||||||||||||||||
| 618 | type => 3, | ||||||||||||||||||||||||||||||||||
| 619 | format => 2, | ||||||||||||||||||||||||||||||||||
| 620 | method => 'queryObjectByCoord', | ||||||||||||||||||||||||||||||||||
| 621 | }, | ||||||||||||||||||||||||||||||||||
| 622 | ); | ||||||||||||||||||||||||||||||||||
| 623 | |||||||||||||||||||||||||||||||||||
| 624 | my %transform = ( | ||||||||||||||||||||||||||||||||||
| 625 | 2 | ▶ | txt => sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 626 | 2 | local $_ = $_[0]; | |||||||||||||||||||||||||||||||||
| 627 | 2 | s/\n//gm; | |||||||||||||||||||||||||||||||||
| 628 | 2 | return $_ | |||||||||||||||||||||||||||||||||
| 629 | }, | ||||||||||||||||||||||||||||||||||
| 630 | 0 | ▶ | vo => sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||
| 631 | 0 | ▶ | local $_ = ref $_[0] ? join (',', @{$_[0]}) : $_[0]; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 632 | 0 | ▶ | if ( defined $_ ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 633 | 0 | s/\s+/,/gms; | |||||||||||||||||||||||||||||||||
| 634 | 0 | s/^,+//; | |||||||||||||||||||||||||||||||||
| 635 | 0 | s/,+$//; | |||||||||||||||||||||||||||||||||
| 636 | 0 | s/,+/,/g; | |||||||||||||||||||||||||||||||||
| 637 | } | ||||||||||||||||||||||||||||||||||
| 638 | 0 | return $_ | |||||||||||||||||||||||||||||||||
| 639 | }, | ||||||||||||||||||||||||||||||||||
| 640 | 5 | ); | |||||||||||||||||||||||||||||||||
| 641 | |||||||||||||||||||||||||||||||||||
| 642 | my %make_script = ( | ||||||||||||||||||||||||||||||||||
| 643 | 2 | ▶ | txt => sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 644 | 2 | my ( $self, $query, @args ) = @_; | |||||||||||||||||||||||||||||||||
| 645 | 2 | return <<"EOD"; | |||||||||||||||||||||||||||||||||
| 646 | 2 | format object "@{[ $transform{txt}->( $self->get( 'format' )->{txt} ) ]}" | |||||||||||||||||||||||||||||||||
| 647 | query $query @args | ||||||||||||||||||||||||||||||||||
| 648 | EOD | ||||||||||||||||||||||||||||||||||
| 649 | }, | ||||||||||||||||||||||||||||||||||
| 650 | 0 | ▶ | vo => sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 651 | 0 | my ( $self, $query, @args ) = @_; | |||||||||||||||||||||||||||||||||
| 652 | 0 | return <<"EOD"; | |||||||||||||||||||||||||||||||||
| 653 | votable myvo { | ||||||||||||||||||||||||||||||||||
| 654 | 0 | @{[ $transform{vo}->( $self->get( 'format' )->{vo} ) ]} | |||||||||||||||||||||||||||||||||
| 655 | } | ||||||||||||||||||||||||||||||||||
| 656 | votable open myvo | ||||||||||||||||||||||||||||||||||
| 657 | query $query @args | ||||||||||||||||||||||||||||||||||
| 658 | votable close myvo | ||||||||||||||||||||||||||||||||||
| 659 | EOD | ||||||||||||||||||||||||||||||||||
| 660 | }, | ||||||||||||||||||||||||||||||||||
| 661 | 5 | ); | |||||||||||||||||||||||||||||||||
| 662 | |||||||||||||||||||||||||||||||||||
| 663 | 2 | ▶ | sub query { | ||||||||||||||||||||||||||||||||
|
Subroutine
query: called CC=19 SCAR=56.6
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 664 | 2 | my ( $self, $query, @args ) = @_; | |||||||||||||||||||||||||||||||||
| 665 | 2 | ▶ | if ( $self->get( 'emulate_soap_queries' ) ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 666 | 2 | my $type = $self->get( 'type' ); | |||||||||||||||||||||||||||||||||
| 667 | 0 | ▶ | my $code = $make_script{$type} || sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 668 | 0 | my ( undef, $query, @args ) = @_; # Invocant unused | |||||||||||||||||||||||||||||||||
| 669 | 0 | return "query $query @args\n"; | |||||||||||||||||||||||||||||||||
| 670 | 2 | ▶ | }; | ||||||||||||||||||||||||||||||||
|
Condition33%1/3
$make_script{$type} || sub {
my(undef, $query, @args) = @_;
return "query $query @args\n";
}
MC/DC0%0/2
$make_script{$type} || sub {
my(undef, $query, @args) = @_;
return "query $query @args\n";
}
$make_script{$type}
sub {
my(undef, $query, @args) = @_;
return "query $query @args\n";
}
Truth table33%1/3
A || B
A= $make_script{$type}B= sub {
my(undef, $query, @args) = @_;
return "query $query @args\n";
}
| |||||||||||||||||||||||||||||||||||
| 671 | 2 | return $self->_script( | |||||||||||||||||||||||||||||||||
| 672 | parser => $type, | ||||||||||||||||||||||||||||||||||
| 673 | script => $code->( $self, $query, @args ), | ||||||||||||||||||||||||||||||||||
| 674 | verbatim => 0, | ||||||||||||||||||||||||||||||||||
| 675 | ); | ||||||||||||||||||||||||||||||||||
| 676 | } | ||||||||||||||||||||||||||||||||||
| 677 | 0 | $self->_deprecation_notice( method => 'query', 'a non-SOAP method' ); | |||||||||||||||||||||||||||||||||
| 678 | 0 | ▶ | eval { _load_module( 'SOAP::Lite' ); 1 } | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 679 | or croak 'Error - query() requires SOAP::Lite'; | ||||||||||||||||||||||||||||||||||
| 680 | 0 | ▶ | eval { _load_module( | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 681 | 0 | 'Astro::SIMBAD::Client::WSQueryInterfaceService' ); 1 } | |||||||||||||||||||||||||||||||||
| 682 | or croak "Programming Error - Can not load Astro::SIMBAD::Client::WSQueryInterfaceService: $@"; | ||||||||||||||||||||||||||||||||||
| 683 | croak "Error - Illegal query type '$query'" | ||||||||||||||||||||||||||||||||||
| 684 | 0 | ▶ | unless $query_args{$query}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 685 | 0 | my $method = $query_args{$query}{method}; | |||||||||||||||||||||||||||||||||
| 686 | 0 | ▶ | croak "Programming error - Illegal query $query method $method" | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 687 | unless Astro::SIMBAD::Client::WSQueryInterfaceService->can ($method); | ||||||||||||||||||||||||||||||||||
| 688 | 0 | my $debug = $self->get ('debug'); | |||||||||||||||||||||||||||||||||
| 689 | 0 | my $parser; | |||||||||||||||||||||||||||||||||
| 690 | 0 | ▶ | if (defined (my $type = $query_args{$query}{type})) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 691 | 0 | ▶ | $args[$type] ||= $self->get ('type'); | ||||||||||||||||||||||||||||||||
|
Condition0%0/3
$args[$type] ||= $self->get("type")
MC/DC0%0/2
$args[$type] ||= $self->get("type")
$args[$type]
$self->get("type")
Truth table0%0/3
A ||= B
A= $args[$type]B= $self->get("type")
| |||||||||||||||||||||||||||||||||||
| 692 | 0 | ▶ | if (defined (my $format = $query_args{$query}{format})) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 693 | 0 | ▶ | $args[$format] ||= $self->get ('format')->{$args[$type]}; | ||||||||||||||||||||||||||||||||
|
Condition0%0/3
$args[$format] ||= $self->get("format")->{$args[$type]}
MC/DC0%0/2
$args[$format] ||= $self->get("format")->{$args[$type]}
$args[$format]
$self->get("format")->{$args[$type]}
Truth table0%0/3
A ||= B
A= $args[$format]B= $self->get("format")->{$args[$type]}
| |||||||||||||||||||||||||||||||||||
| 694 | $args[$format] = $transform{$args[$type]}->($args[$format]) | ||||||||||||||||||||||||||||||||||
| 695 | 0 | ▶ | if $transform{$args[$type]}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 696 | 0 | ▶ | warn "$args[$type] format: $args[$format]\n" if $debug; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 697 | 0 | ▶ | $args[$format] = undef unless $args[$format]; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 698 | } | ||||||||||||||||||||||||||||||||||
| 699 | 0 | $parser = $self->_get_parser ($args[$type]); | |||||||||||||||||||||||||||||||||
| 700 | } | ||||||||||||||||||||||||||||||||||
| 701 | 0 | ▶ | SOAP::Lite->import (+trace => $debug ? 'all' : '-all'); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 702 | 0 | $self->_delay (); | |||||||||||||||||||||||||||||||||
| 703 | ## $debug and SOAP::Trace->import ('all'); | ||||||||||||||||||||||||||||||||||
| 704 | 0 | my $rslt = Astro::SIMBAD::Client::WSQueryInterfaceService->$method( | |||||||||||||||||||||||||||||||||
| 705 | $self, @args); | ||||||||||||||||||||||||||||||||||
| 706 | 0 | ▶ | return unless defined $rslt; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 707 | 0 | ▶ | HAVE_DOUBLE_ENCODED | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 708 | and $rslt = XML::DoubleEncodedEntities::decode ($rslt); | ||||||||||||||||||||||||||||||||||
| 709 | 0 | ▶ | return wantarray ? ($parser->($rslt)) : [$parser->($rslt)] | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 710 | if $parser; | ||||||||||||||||||||||||||||||||||
| 711 | 0 | return $rslt; | |||||||||||||||||||||||||||||||||
| 712 | } | ||||||||||||||||||||||||||||||||||
| 713 | |||||||||||||||||||||||||||||||||||
| 714 | } # End local symbol block. | ||||||||||||||||||||||||||||||||||
| 715 | |||||||||||||||||||||||||||||||||||
| 716 | =item $value = $simbad->queryObjectByBib ($bibcode, $format, $type); | ||||||||||||||||||||||||||||||||||
| 717 | |||||||||||||||||||||||||||||||||||
| 718 | This method is B<deprecated>, and will cease to work on December 31 | ||||||||||||||||||||||||||||||||||
| 719 | 2018. Please choose a method that does not use SOAP. See the | ||||||||||||||||||||||||||||||||||
| 720 | L<NOTICE|/NOTICE> above for details. | ||||||||||||||||||||||||||||||||||
| 721 | |||||||||||||||||||||||||||||||||||
| 722 | This method is just a convenience wrapper for | ||||||||||||||||||||||||||||||||||
| 723 | |||||||||||||||||||||||||||||||||||
| 724 | $value = $simbad->query (bib => $bibcode, $format, $type); | ||||||||||||||||||||||||||||||||||
| 725 | |||||||||||||||||||||||||||||||||||
| 726 | See the query() documentation for more information. | ||||||||||||||||||||||||||||||||||
| 727 | |||||||||||||||||||||||||||||||||||
| 728 | =cut | ||||||||||||||||||||||||||||||||||
| 729 | |||||||||||||||||||||||||||||||||||
| 730 | 5 | ▶ | sub queryObjectByBib { | ||||||||||||||||||||||||||||||||
|
Subroutine
queryObjectByBib: not called CC=1 SCAR=2.6
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 731 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 732 | 0 | return $self->query (bib => @_); | |||||||||||||||||||||||||||||||||
| 733 | } | ||||||||||||||||||||||||||||||||||
| 734 | |||||||||||||||||||||||||||||||||||
| 735 | =item $value = $simbad->queryObjectByCoord ($coord, $radius, $format, $type); | ||||||||||||||||||||||||||||||||||
| 736 | |||||||||||||||||||||||||||||||||||
| 737 | This method is B<deprecated>, and will cease to work on December 31 | ||||||||||||||||||||||||||||||||||
| 738 | 2018. Please choose a method that does not use SOAP. See the | ||||||||||||||||||||||||||||||||||
| 739 | L<NOTICE|/NOTICE> above for details. | ||||||||||||||||||||||||||||||||||
| 740 | |||||||||||||||||||||||||||||||||||
| 741 | This method is just a convenience wrapper for | ||||||||||||||||||||||||||||||||||
| 742 | |||||||||||||||||||||||||||||||||||
| 743 | $value = $simbad->query (coo => $coord, $radius, $format, $type); | ||||||||||||||||||||||||||||||||||
| 744 | |||||||||||||||||||||||||||||||||||
| 745 | See the query() documentation for more information. | ||||||||||||||||||||||||||||||||||
| 746 | |||||||||||||||||||||||||||||||||||
| 747 | =cut | ||||||||||||||||||||||||||||||||||
| 748 | |||||||||||||||||||||||||||||||||||
| 749 | 0 | ▶ | sub queryObjectByCoord { | ||||||||||||||||||||||||||||||||
|
Subroutine
queryObjectByCoord: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 750 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 751 | 0 | return $self->query (coo => @_); | |||||||||||||||||||||||||||||||||
| 752 | } | ||||||||||||||||||||||||||||||||||
| 753 | |||||||||||||||||||||||||||||||||||
| 754 | =item $value = $simbad->queryObjectById ($id, $format, $type); | ||||||||||||||||||||||||||||||||||
| 755 | |||||||||||||||||||||||||||||||||||
| 756 | This method is B<deprecated>, and will cease to work on December 31 | ||||||||||||||||||||||||||||||||||
| 757 | 2018. Please choose a method that does not use SOAP. See the | ||||||||||||||||||||||||||||||||||
| 758 | L<NOTICE|/NOTICE> above for details. | ||||||||||||||||||||||||||||||||||
| 759 | |||||||||||||||||||||||||||||||||||
| 760 | This method is just a convenience wrapper for | ||||||||||||||||||||||||||||||||||
| 761 | |||||||||||||||||||||||||||||||||||
| 762 | $value = $simbad->query (id => $id, $format, $type); | ||||||||||||||||||||||||||||||||||
| 763 | |||||||||||||||||||||||||||||||||||
| 764 | See the query() documentation for more information. | ||||||||||||||||||||||||||||||||||
| 765 | |||||||||||||||||||||||||||||||||||
| 766 | =cut | ||||||||||||||||||||||||||||||||||
| 767 | |||||||||||||||||||||||||||||||||||
| 768 | 0 | ▶ | sub queryObjectById { | ||||||||||||||||||||||||||||||||
|
Subroutine
queryObjectById: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 769 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 770 | 0 | return $self->query (id => @_); | |||||||||||||||||||||||||||||||||
| 771 | } | ||||||||||||||||||||||||||||||||||
| 772 | |||||||||||||||||||||||||||||||||||
| 773 | =item $release = $simbad->release (); | ||||||||||||||||||||||||||||||||||
| 774 | |||||||||||||||||||||||||||||||||||
| 775 | This method returns the current SIMBAD4 release, as scraped from the | ||||||||||||||||||||||||||||||||||
| 776 | top-level web page. This will look something like 'SIMBAD4 1.045 - | ||||||||||||||||||||||||||||||||||
| 777 | 27-Jul-2007' | ||||||||||||||||||||||||||||||||||
| 778 | |||||||||||||||||||||||||||||||||||
| 779 | If called in list context, it returns ($major, $minor, $point, $patch, | ||||||||||||||||||||||||||||||||||
| 780 | $date). The returned information corresponding to the scalar example | ||||||||||||||||||||||||||||||||||
| 781 | above is: | ||||||||||||||||||||||||||||||||||
| 782 | |||||||||||||||||||||||||||||||||||
| 783 | $major => 4 | ||||||||||||||||||||||||||||||||||
| 784 | $minor => 1 | ||||||||||||||||||||||||||||||||||
| 785 | $point => 45 | ||||||||||||||||||||||||||||||||||
| 786 | $patch => '' | ||||||||||||||||||||||||||||||||||
| 787 | $date => '27-Jul-2007' | ||||||||||||||||||||||||||||||||||
| 788 | |||||||||||||||||||||||||||||||||||
| 789 | The $patch will usually be empty, but occasionally you get something | ||||||||||||||||||||||||||||||||||
| 790 | like release '1.019a', in which case $patch would be 'a'. | ||||||||||||||||||||||||||||||||||
| 791 | |||||||||||||||||||||||||||||||||||
| 792 | Please note that this method is B<not> based on a published interface, | ||||||||||||||||||||||||||||||||||
| 793 | but is simply a web page scraper, and subject to all the problems such | ||||||||||||||||||||||||||||||||||
| 794 | software is heir to. What the algorithm attempts to do is to find (and | ||||||||||||||||||||||||||||||||||
| 795 | parse, if called in list context) the contents of the next E<lt>tdE<gt> | ||||||||||||||||||||||||||||||||||
| 796 | after 'Release:' (case-insensitive). | ||||||||||||||||||||||||||||||||||
| 797 | |||||||||||||||||||||||||||||||||||
| 798 | =cut | ||||||||||||||||||||||||||||||||||
| 799 | |||||||||||||||||||||||||||||||||||
| 800 | 3 | ▶ | sub release { | ||||||||||||||||||||||||||||||||
|
Subroutine
release: called CC=6 SCAR=18.1
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 801 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 802 | 3 | my $rslt = $self->_retrieve( 'simbad/' ); | |||||||||||||||||||||||||||||||||
| 803 | 3 | ▶ | my ($rls) = $rslt->content =~ | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 804 | m{Release:.*?</td>.*?<td.*?>(.*?)</td>}sxi | ||||||||||||||||||||||||||||||||||
| 805 | or croak "Error - Release information not found"; | ||||||||||||||||||||||||||||||||||
| 806 | 3 | $rls =~ s{<.*?>}{}g; | |||||||||||||||||||||||||||||||||
| 807 | 3 | $rls =~ s/^\s+//; | |||||||||||||||||||||||||||||||||
| 808 | 3 | $rls =~ s/\s+$//; | |||||||||||||||||||||||||||||||||
| 809 | 3 | ▶ | wantarray or return $rls; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 810 | 1 | $rls =~ s/\s+-\s+/ /; | |||||||||||||||||||||||||||||||||
| 811 | 1 | ▶ | my ($major, $minor, $date) = split '\s+', $rls | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 812 | or croak "Error - Release '$rls' is ill-formed"; | ||||||||||||||||||||||||||||||||||
| 813 | 1 | $major =~s/^\D+//; | |||||||||||||||||||||||||||||||||
| 814 | 1 | $major += 0; | |||||||||||||||||||||||||||||||||
| 815 | 1 | ($minor, my $point) = split '\.', $minor, 2; | |||||||||||||||||||||||||||||||||
| 816 | 1 | $minor += 0; | |||||||||||||||||||||||||||||||||
| 817 | 1 | ▶ | ($point, my $patch) = $point =~ m/^(\d+)(.*)/ | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 818 | or croak "Error - Release '$rls' is ill-formed: bad point"; | ||||||||||||||||||||||||||||||||||
| 819 | 1 | ▶ | defined $patch or $patch = ''; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 820 | 1 | $point += 0; | |||||||||||||||||||||||||||||||||
| 821 | 1 | return ($major, $minor, $point, $patch, $date); | |||||||||||||||||||||||||||||||||
| 822 | } | ||||||||||||||||||||||||||||||||||
| 823 | |||||||||||||||||||||||||||||||||||
| 824 | =item $value = $simbad->script ($script); | ||||||||||||||||||||||||||||||||||
| 825 | |||||||||||||||||||||||||||||||||||
| 826 | This method submits the given script to SIMBAD4. The $script variable | ||||||||||||||||||||||||||||||||||
| 827 | contains the text if the script; if you want to submit a script file | ||||||||||||||||||||||||||||||||||
| 828 | by name, use the script_file() method. | ||||||||||||||||||||||||||||||||||
| 829 | |||||||||||||||||||||||||||||||||||
| 830 | If the L<verbatim|/verbatim> attribute is false, the front matter of the | ||||||||||||||||||||||||||||||||||
| 831 | result (up to and including the '::data:::::' line) is stripped. If | ||||||||||||||||||||||||||||||||||
| 832 | there is no '::data:::::' line, the entire script output is raised as an | ||||||||||||||||||||||||||||||||||
| 833 | exception. | ||||||||||||||||||||||||||||||||||
| 834 | |||||||||||||||||||||||||||||||||||
| 835 | If a 'script' L<parser|/parser> was specified, the output of the script | ||||||||||||||||||||||||||||||||||
| 836 | (after stripping front matter if that was specified) is passed to it. | ||||||||||||||||||||||||||||||||||
| 837 | The parser is presumed to return a list, so if script() was called in | ||||||||||||||||||||||||||||||||||
| 838 | scalar context you get a reference to that list back. | ||||||||||||||||||||||||||||||||||
| 839 | |||||||||||||||||||||||||||||||||||
| 840 | If no 'script' L<parser|/parser> is specified, the output of the script | ||||||||||||||||||||||||||||||||||
| 841 | (after stripping front matter if that was specified) is simply returned | ||||||||||||||||||||||||||||||||||
| 842 | to the caller. | ||||||||||||||||||||||||||||||||||
| 843 | |||||||||||||||||||||||||||||||||||
| 844 | =cut | ||||||||||||||||||||||||||||||||||
| 845 | |||||||||||||||||||||||||||||||||||
| 846 | 2 | ▶ | sub script { | ||||||||||||||||||||||||||||||||
|
Subroutine
script: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 847 | 2 | my ( $self, $script ) = @_; | |||||||||||||||||||||||||||||||||
| 848 | 2 | return $self->_script( | |||||||||||||||||||||||||||||||||
| 849 | parser => 'script', | ||||||||||||||||||||||||||||||||||
| 850 | script => $script, | ||||||||||||||||||||||||||||||||||
| 851 | verbatim => $self->get( 'verbatim' ), | ||||||||||||||||||||||||||||||||||
| 852 | ); | ||||||||||||||||||||||||||||||||||
| 853 | } | ||||||||||||||||||||||||||||||||||
| 854 | |||||||||||||||||||||||||||||||||||
| 855 | { | ||||||||||||||||||||||||||||||||||
| 856 | my %dflt = ( | ||||||||||||||||||||||||||||||||||
| 857 | 0 | ▶ | parser => sub { return 'script' }, | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 858 | 0 | ▶ | script => sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 859 | 0 | confess 'Programming error - script argument required'; | |||||||||||||||||||||||||||||||||
| 860 | }, | ||||||||||||||||||||||||||||||||||
| 861 | 0 | ▶ | verbatim => sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 862 | 0 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||
| 863 | 0 | return $self->get( 'verbatim' ); | |||||||||||||||||||||||||||||||||
| 864 | }, | ||||||||||||||||||||||||||||||||||
| 865 | 5 | ); | |||||||||||||||||||||||||||||||||
| 866 | |||||||||||||||||||||||||||||||||||
| 867 | 4 | ▶ | sub _script { | ||||||||||||||||||||||||||||||||
|
Subroutine
_script: called CC=14 SCAR=32.3
| |||||||||||||||||||||||||||||||||||
| 868 | 4 | my ( $self, %arg ) = @_; | |||||||||||||||||||||||||||||||||
| 869 | |||||||||||||||||||||||||||||||||||
| 870 | 4 | foreach my $key ( keys %dflt ) { | |||||||||||||||||||||||||||||||||
| 871 | defined $arg{$key} | ||||||||||||||||||||||||||||||||||
| 872 | 12 | ▶ | or $arg{$key} = $dflt{$key}->( $self ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 873 | } | ||||||||||||||||||||||||||||||||||
| 874 | |||||||||||||||||||||||||||||||||||
| 875 | 4 | my $debug = $self->get( 'debug' ); | |||||||||||||||||||||||||||||||||
| 876 | |||||||||||||||||||||||||||||||||||
| 877 | 4 | ▶ | $debug | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 878 | and warn "Debug - script\n$arg{script} "; | ||||||||||||||||||||||||||||||||||
| 879 | |||||||||||||||||||||||||||||||||||
| 880 | my $resp = $self->_retrieve( 'simbad/sim-script', { | ||||||||||||||||||||||||||||||||||
| 881 | submit => 'submit+script', | ||||||||||||||||||||||||||||||||||
| 882 | script => $arg{script}, | ||||||||||||||||||||||||||||||||||
| 883 | }, | ||||||||||||||||||||||||||||||||||
| 884 | 4 | ); | |||||||||||||||||||||||||||||||||
| 885 | |||||||||||||||||||||||||||||||||||
| 886 | 4 | ▶ | my $rslt = $resp->content | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 887 | or return; | ||||||||||||||||||||||||||||||||||
| 888 | |||||||||||||||||||||||||||||||||||
| 889 | 4 | ▶ | unless ( $arg{verbatim} ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 890 | 4 | ▶ | $rslt =~ s/.*?::data:+\s*//sm or croak $rslt; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 891 | } | ||||||||||||||||||||||||||||||||||
| 892 | |||||||||||||||||||||||||||||||||||
| 893 | $debug | ||||||||||||||||||||||||||||||||||
| 894 | 4 | ▶ | and warn "Debug - result:\n$rslt "; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 895 | |||||||||||||||||||||||||||||||||||
| 896 | 4 | ▶ | HAVE_DOUBLE_ENCODED | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 897 | and $rslt = XML::DoubleEncodedEntities::decode ($rslt); | ||||||||||||||||||||||||||||||||||
| 898 | 4 | ▶ | if ( my $parser = $self->_get_parser( $arg{parser} ) ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 899 | 4 | ▶ | $debug | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 900 | and warn "Debug - Parser $arg{parser}"; | ||||||||||||||||||||||||||||||||||
| 901 | ## $rslt =~ s/.*?::data:+.?$//sm or croak $rslt; | ||||||||||||||||||||||||||||||||||
| 902 | 4 | my @rslt = $parser->($rslt); | |||||||||||||||||||||||||||||||||
| 903 | $debug | ||||||||||||||||||||||||||||||||||
| 904 | 4 | ▶ | and eval { ## no critic (RequireCheckingReturnValueOfEval) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 905 | 0 | require YAML; | |||||||||||||||||||||||||||||||||
| 906 | 0 | warn "Debug - Parsed to:\n", YAML::Dump( \@rslt ), ' '; | |||||||||||||||||||||||||||||||||
| 907 | }; | ||||||||||||||||||||||||||||||||||
| 908 | 4 | ▶ | return wantarray ? @rslt : \@rslt; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 909 | } else { | ||||||||||||||||||||||||||||||||||
| 910 | 0 | ▶ | $debug | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 911 | and warn "Debug - No parser for $arg{parser}"; | ||||||||||||||||||||||||||||||||||
| 912 | 0 | return $rslt; | |||||||||||||||||||||||||||||||||
| 913 | } | ||||||||||||||||||||||||||||||||||
| 914 | } | ||||||||||||||||||||||||||||||||||
| 915 | } | ||||||||||||||||||||||||||||||||||
| 916 | |||||||||||||||||||||||||||||||||||
| 917 | =item $value = $simbad->script_file ($filename); | ||||||||||||||||||||||||||||||||||
| 918 | |||||||||||||||||||||||||||||||||||
| 919 | This method submits the given script file to SIMBAD, returning the | ||||||||||||||||||||||||||||||||||
| 920 | result of the script. Unlike script(), the argument is the name of the | ||||||||||||||||||||||||||||||||||
| 921 | file containing the script, not the text of the script. However, if a | ||||||||||||||||||||||||||||||||||
| 922 | parser for 'script' has been specified, it will be applied to the | ||||||||||||||||||||||||||||||||||
| 923 | output. | ||||||||||||||||||||||||||||||||||
| 924 | |||||||||||||||||||||||||||||||||||
| 925 | =cut | ||||||||||||||||||||||||||||||||||
| 926 | |||||||||||||||||||||||||||||||||||
| 927 | 5 | ▶ | sub script_file { | ||||||||||||||||||||||||||||||||
|
Subroutine
script_file: called CC=6 SCAR=19.1
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 928 | 2 | my ( $self, $file ) = @_; | |||||||||||||||||||||||||||||||||
| 929 | |||||||||||||||||||||||||||||||||||
| 930 | 2 | my $url = $self->__build_url( 'simbad/sim-script' ); | |||||||||||||||||||||||||||||||||
| 931 | 2 | my $rqst = POST $url, | |||||||||||||||||||||||||||||||||
| 932 | Content_Type => 'form-data', | ||||||||||||||||||||||||||||||||||
| 933 | Content => [ | ||||||||||||||||||||||||||||||||||
| 934 | submit => 'submit file', | ||||||||||||||||||||||||||||||||||
| 935 | scriptFile => [$file, undef], | ||||||||||||||||||||||||||||||||||
| 936 | # May need to specify Content_Type => application/octet-stream. | ||||||||||||||||||||||||||||||||||
| 937 | ]; | ||||||||||||||||||||||||||||||||||
| 938 | 2 | my $resp = $self->_retrieve( $rqst ); | |||||||||||||||||||||||||||||||||
| 939 | |||||||||||||||||||||||||||||||||||
| 940 | 2 | ▶ | my $rslt = $resp->content or return; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 941 | 2 | ▶ | unless ($self->get ('verbatim')) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 942 | 2 | ▶ | $rslt =~ s/.*?::data:+\s*//sm or croak $rslt; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 943 | } | ||||||||||||||||||||||||||||||||||
| 944 | 2 | ▶ | if (my $parser = $self->_get_parser ('script')) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 945 | ## $rslt =~ s/.*?::data:+.?$//sm or croak $rslt; | ||||||||||||||||||||||||||||||||||
| 946 | ## $rslt =~ s/\s+//sm; | ||||||||||||||||||||||||||||||||||
| 947 | 2 | my @rslt = $parser->($rslt); | |||||||||||||||||||||||||||||||||
| 948 | 2 | ▶ | return wantarray ? @rslt : \@rslt; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 949 | } else { | ||||||||||||||||||||||||||||||||||
| 950 | 0 | return $rslt; | |||||||||||||||||||||||||||||||||
| 951 | } | ||||||||||||||||||||||||||||||||||
| 952 | |||||||||||||||||||||||||||||||||||
| 953 | } | ||||||||||||||||||||||||||||||||||
| 954 | |||||||||||||||||||||||||||||||||||
| 955 | =item $simbad->set ($name => $value ...); | ||||||||||||||||||||||||||||||||||
| 956 | |||||||||||||||||||||||||||||||||||
| 957 | This method sets the value of the given L<attributes|/Attributes>. More | ||||||||||||||||||||||||||||||||||
| 958 | than one name/value pair may be specified. If called as a static method, | ||||||||||||||||||||||||||||||||||
| 959 | it sets the default value of the attribute. | ||||||||||||||||||||||||||||||||||
| 960 | |||||||||||||||||||||||||||||||||||
| 961 | =cut | ||||||||||||||||||||||||||||||||||
| 962 | |||||||||||||||||||||||||||||||||||
| 963 | { # Begin local symbol block. | ||||||||||||||||||||||||||||||||||
| 964 | |||||||||||||||||||||||||||||||||||
| 965 | 8 | ▶ | my $ckpn = sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=13.1
| |||||||||||||||||||||||||||||||||||
| 966 | 8 | ▶ | (looks_like_number ($_[2]) && $_[2] >= 0) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
&looks_like_number($_[2]) and $_[2] >= 0
MC/DC0%0/2
&looks_like_number($_[2]) and $_[2] >= 0
&looks_like_number($_[2])
$_[2] >= 0
Truth table33%1/3
A and B
A= &looks_like_number($_[2])B= $_[2] >= 0
| |||||||||||||||||||||||||||||||||||
| 967 | or croak "Attribute '$_[1]' must be a non-negative number"; | ||||||||||||||||||||||||||||||||||
| 968 | 8 | +$_[2]; | |||||||||||||||||||||||||||||||||
| 969 | 5 | }; | |||||||||||||||||||||||||||||||||
| 970 | |||||||||||||||||||||||||||||||||||
| 971 | 5 | my %mutator = ( | |||||||||||||||||||||||||||||||||
| 972 | format => \&_set_hash, | ||||||||||||||||||||||||||||||||||
| 973 | parser => \&_set_hash, | ||||||||||||||||||||||||||||||||||
| 974 | scheme => \&_set_scheme, | ||||||||||||||||||||||||||||||||||
| 975 | url_args => \&_set_hash, | ||||||||||||||||||||||||||||||||||
| 976 | ); | ||||||||||||||||||||||||||||||||||
| 977 | |||||||||||||||||||||||||||||||||||
| 978 | 5 | my %server_map = ( | |||||||||||||||||||||||||||||||||
| 979 | harvard => 'simbad.cfa.harvard.edu', | ||||||||||||||||||||||||||||||||||
| 980 | strasbourg => 'simbad.unistra.fr', | ||||||||||||||||||||||||||||||||||
| 981 | unistra => 'simbad.unistra.fr', | ||||||||||||||||||||||||||||||||||
| 982 | idia => 'simbad.idia.ac.za', | ||||||||||||||||||||||||||||||||||
| 983 | sa => 'simbad.idia.ac.za', | ||||||||||||||||||||||||||||||||||
| 984 | ); | ||||||||||||||||||||||||||||||||||
| 985 | |||||||||||||||||||||||||||||||||||
| 986 | my %transform = ( | ||||||||||||||||||||||||||||||||||
| 987 | delay => ($have_time_hires ? | ||||||||||||||||||||||||||||||||||
| 988 | $ckpn : | ||||||||||||||||||||||||||||||||||
| 989 | 0 | ▶ | sub {+sprintf '%d', $ckpn->(@_) + .5}), | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 990 | 18 | ▶ | format => sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||
| 991 | ## my ( $self, $name, $val, $key ) = @_; | ||||||||||||||||||||||||||||||||||
| 992 | 18 | my ( $self, undef, $val ) = @_; # Name and key unused | |||||||||||||||||||||||||||||||||
| 993 | 18 | ▶ | if ($val !~ m/\W/ && (my $code = eval { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $val =~ /\W/ and my $code = eval {
do {
$self->_get_coderef($val)
}
}
MC/DC50%1/2
not $val =~ /\W/ and my $code = eval {
do {
$self->_get_coderef($val)
}
}
not $val =~ /\W/
my $code = eval {
do {
$self->_get_coderef($val)
}
}
Truth table66%2/3
not(A) and B
A= not $val =~ /\W/B= my $code = eval {
do {
$self->_get_coderef($val)
}
}
| |||||||||||||||||||||||||||||||||||
| 994 | 2 | $self->_get_coderef ($val)})) { | |||||||||||||||||||||||||||||||||
| 995 | 2 | $val = $code->(); | |||||||||||||||||||||||||||||||||
| 996 | } | ||||||||||||||||||||||||||||||||||
| 997 | 18 | $val; | |||||||||||||||||||||||||||||||||
| 998 | }, | ||||||||||||||||||||||||||||||||||
| 999 | 6 | ▶ | parser => sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=14.8
| |||||||||||||||||||||||||||||||||||
| 1000 | ## my ( $self, $name, $val, $key ) = @_; | ||||||||||||||||||||||||||||||||||
| 1001 | 6 | my ( $self, undef, $val ) = @_; # Name and key unused | |||||||||||||||||||||||||||||||||
| 1002 | 6 | ▶ | if (!ref $val) { | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 1003 | 6 | ▶ | unless ($val =~ m/::/) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1004 | 2 | my $pkg = $self->_parse_subroutine_name ($val); | |||||||||||||||||||||||||||||||||
| 1005 | 2 | $val = $pkg . '::' . $val; | |||||||||||||||||||||||||||||||||
| 1006 | } | ||||||||||||||||||||||||||||||||||
| 1007 | 6 | $self->_get_coderef ($val); # Just to see if we can. | |||||||||||||||||||||||||||||||||
| 1008 | } elsif ( CODE_REF ne ref $val ) { | ||||||||||||||||||||||||||||||||||
| 1009 | 0 | croak "Error - $_[1] value must be scalar or code reference"; | |||||||||||||||||||||||||||||||||
| 1010 | } | ||||||||||||||||||||||||||||||||||
| 1011 | 6 | $val; | |||||||||||||||||||||||||||||||||
| 1012 | }, | ||||||||||||||||||||||||||||||||||
| 1013 | 17 | ▶ | server => sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=21.7
| |||||||||||||||||||||||||||||||||||
| 1014 | ## my ( $self, $name, $val, $key ) = @_; | ||||||||||||||||||||||||||||||||||
| 1015 | 17 | my ( undef, undef, $val ) = @_; # Invocant name and key unused | |||||||||||||||||||||||||||||||||
| 1016 | 17 | ▶ | defined $val | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1017 | or return $val; | ||||||||||||||||||||||||||||||||||
| 1018 | defined $server_map{$val} | ||||||||||||||||||||||||||||||||||
| 1019 | 17 | ▶ | and $val = $server_map{$val}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1020 | 17 | ▶ | $val eq 'random' | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1021 | or return $val; | ||||||||||||||||||||||||||||||||||
| 1022 | 0 | my $resp = __random_server( $val ); | |||||||||||||||||||||||||||||||||
| 1023 | 0 | ▶ | $resp->is_success() | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1024 | or croak 'Error - No responsive server found'; | ||||||||||||||||||||||||||||||||||
| 1025 | 0 | return $val; | |||||||||||||||||||||||||||||||||
| 1026 | } | ||||||||||||||||||||||||||||||||||
| 1027 | 5 | ▶ | ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1028 | |||||||||||||||||||||||||||||||||||
| 1029 | 5 | foreach my $key (keys %static) { | |||||||||||||||||||||||||||||||||
| 1030 | 62 | ▶ | $transform{$key} ||= sub {$_[2]}; | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.1
Condition66%2/3
$transform{$key} ||= sub {
$_[2];
}
MC/DC0%0/2
$transform{$key} ||= sub {
$_[2];
}
$transform{$key}
sub {
$_[2];
}
Truth table66%2/3
A ||= B
A= $transform{$key}B= sub {
$_[2];
}
| |||||||||||||||||||||||||||||||||||
| 1031 | 87 | ▶ | $mutator{$key} ||= sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||||||||
| 1032 | 87 | ▶ | my $hash = ref $_[0] ? $_[0] : \%static; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1033 | 87 | $hash->{$_[1]} = $transform{$_[1]}->(@_) | |||||||||||||||||||||||||||||||||
| 1034 | 65 | ▶ | }; | ||||||||||||||||||||||||||||||||
|
Condition66%2/3
$mutator{$key} ||= sub {
my $hash = ref $_[0] ? $_[0] : \%static;
$$hash{$_[1]} = $transform{$_[1]}(@_);
}
MC/DC0%0/2
$mutator{$key} ||= sub {
my $hash = ref $_[0] ? $_[0] : \%static;
$$hash{$_[1]} = $transform{$_[1]}(@_);
}
$mutator{$key}
sub {
my $hash = ref $_[0] ? $_[0] : \%static;
$$hash{$_[1]} = $transform{$_[1]}(@_);
}
Truth table66%2/3
A ||= B
A= $mutator{$key}B= sub {
my $hash = ref $_[0] ? $_[0] : \%static;
$$hash{$_[1]} = $transform{$_[1]}(@_);
}
| |||||||||||||||||||||||||||||||||||
| 1035 | } | ||||||||||||||||||||||||||||||||||
| 1036 | |||||||||||||||||||||||||||||||||||
| 1037 | 34 | ▶ | sub set { | ||||||||||||||||||||||||||||||||
|
Subroutine
set: called CC=4 SCAR=14.2
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 1038 | 34 | my ($self, @args) = @_; | |||||||||||||||||||||||||||||||||
| 1039 | 0 | croak "Error - First argument must be an @{[__PACKAGE__]} object" | |||||||||||||||||||||||||||||||||
| 1040 | 34 | ▶ | unless eval {$self->isa(__PACKAGE__)}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1041 | 34 | ▶ | while (@args) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1042 | 130 | my $name = shift @args; | |||||||||||||||||||||||||||||||||
| 1043 | croak "Error - Attribute '$name' is unknown" | ||||||||||||||||||||||||||||||||||
| 1044 | 130 | ▶ | unless exists $mutator{$name}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1045 | 130 | $mutator{$name}->($self, $name, shift @args); | |||||||||||||||||||||||||||||||||
| 1046 | } | ||||||||||||||||||||||||||||||||||
| 1047 | 34 | return $self; | |||||||||||||||||||||||||||||||||
| 1048 | } | ||||||||||||||||||||||||||||||||||
| 1049 | |||||||||||||||||||||||||||||||||||
| 1050 | 32 | ▶ | sub _set_hash { | ||||||||||||||||||||||||||||||||
|
Subroutine
_set_hash: called CC=8 SCAR=21.4
| |||||||||||||||||||||||||||||||||||
| 1051 | 32 | my ($self, $name, $value) = @_; | |||||||||||||||||||||||||||||||||
| 1052 | 32 | ▶ | my $hash = ref $self ? $self : \%static; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1053 | 32 | ▶ | unless (ref $value) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1054 | 8 | ▶ | $value = {$value =~ m/=/ ? | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1055 | split ('=', $value, 2) : ($value => undef)}; | ||||||||||||||||||||||||||||||||||
| 1056 | } | ||||||||||||||||||||||||||||||||||
| 1057 | 32 | ▶ | $hash->{$name} = {} if $value->{clear}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1058 | 32 | delete $value->{clear}; | |||||||||||||||||||||||||||||||||
| 1059 | 32 | foreach my $key (keys %$value) { | |||||||||||||||||||||||||||||||||
| 1060 | 56 | my $val = $value->{$key}; | |||||||||||||||||||||||||||||||||
| 1061 | 56 | ▶ | if (!defined $val) { | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 1062 | 0 | delete $hash->{$name}{$key}; | |||||||||||||||||||||||||||||||||
| 1063 | } elsif ($val) { | ||||||||||||||||||||||||||||||||||
| 1064 | $hash->{$name}{$key} = | ||||||||||||||||||||||||||||||||||
| 1065 | 24 | $transform{$name}->($self, $name, $value->{$key}, $key); | |||||||||||||||||||||||||||||||||
| 1066 | } else { | ||||||||||||||||||||||||||||||||||
| 1067 | 32 | $hash->{$name}{$key} = ''; | |||||||||||||||||||||||||||||||||
| 1068 | } | ||||||||||||||||||||||||||||||||||
| 1069 | } | ||||||||||||||||||||||||||||||||||
| 1070 | 32 | return; | |||||||||||||||||||||||||||||||||
| 1071 | } | ||||||||||||||||||||||||||||||||||
| 1072 | |||||||||||||||||||||||||||||||||||
| 1073 | 11 | ▶ | sub _set_scheme { | ||||||||||||||||||||||||||||||||
|
Subroutine
_set_scheme: called CC=3 SCAR=11.8
| |||||||||||||||||||||||||||||||||||
| 1074 | 11 | my ( $self, $name, $value ) = @_; | |||||||||||||||||||||||||||||||||
| 1075 | 11 | ▶ | if ( my $msg = _is_scheme_valid( $value ) ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1076 | 0 | croak $msg; | |||||||||||||||||||||||||||||||||
| 1077 | } | ||||||||||||||||||||||||||||||||||
| 1078 | 11 | ▶ | my $hash = ref $self ? $self : \%static; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1079 | 11 | $hash->{$name} = lc $value; | |||||||||||||||||||||||||||||||||
| 1080 | 11 | return; | |||||||||||||||||||||||||||||||||
| 1081 | } | ||||||||||||||||||||||||||||||||||
| 1082 | |||||||||||||||||||||||||||||||||||
| 1083 | } # End local symbol block. | ||||||||||||||||||||||||||||||||||
| 1084 | |||||||||||||||||||||||||||||||||||
| 1085 | =item $value = $simbad->url_query ($type => ...) | ||||||||||||||||||||||||||||||||||
| 1086 | |||||||||||||||||||||||||||||||||||
| 1087 | This method performs a query by URL, returning the results. The type | ||||||||||||||||||||||||||||||||||
| 1088 | is one of: | ||||||||||||||||||||||||||||||||||
| 1089 | |||||||||||||||||||||||||||||||||||
| 1090 | id = query by identifier, | ||||||||||||||||||||||||||||||||||
| 1091 | coo = query by coordinates, | ||||||||||||||||||||||||||||||||||
| 1092 | ref = query by references, | ||||||||||||||||||||||||||||||||||
| 1093 | sam = query by criteria. | ||||||||||||||||||||||||||||||||||
| 1094 | |||||||||||||||||||||||||||||||||||
| 1095 | The arguments depend on on the type, and are documented at | ||||||||||||||||||||||||||||||||||
| 1096 | L<https://simbad.unistra.fr/guide/sim-url.htx>. They are | ||||||||||||||||||||||||||||||||||
| 1097 | specified as name => value. For example: | ||||||||||||||||||||||||||||||||||
| 1098 | |||||||||||||||||||||||||||||||||||
| 1099 | $simbad->url_query (id => | ||||||||||||||||||||||||||||||||||
| 1100 | Ident => 'Arcturus', | ||||||||||||||||||||||||||||||||||
| 1101 | NbIdent => 1 | ||||||||||||||||||||||||||||||||||
| 1102 | ); | ||||||||||||||||||||||||||||||||||
| 1103 | |||||||||||||||||||||||||||||||||||
| 1104 | Note that in an id query you must specify 'Ident' explicitly. This is | ||||||||||||||||||||||||||||||||||
| 1105 | true in general, because it is not always possible to derive the first | ||||||||||||||||||||||||||||||||||
| 1106 | argument name from the query type, and consistency was chosen over | ||||||||||||||||||||||||||||||||||
| 1107 | brevity. | ||||||||||||||||||||||||||||||||||
| 1108 | |||||||||||||||||||||||||||||||||||
| 1109 | The output.format argument can be defaulted based on the object's type | ||||||||||||||||||||||||||||||||||
| 1110 | setting as follows: | ||||||||||||||||||||||||||||||||||
| 1111 | |||||||||||||||||||||||||||||||||||
| 1112 | txt becomes 'ASCII', | ||||||||||||||||||||||||||||||||||
| 1113 | vo becomes 'VOTable'. | ||||||||||||||||||||||||||||||||||
| 1114 | |||||||||||||||||||||||||||||||||||
| 1115 | Any other value is passed verbatim. | ||||||||||||||||||||||||||||||||||
| 1116 | |||||||||||||||||||||||||||||||||||
| 1117 | If the query succeeds, the results will be passed to the appropriate | ||||||||||||||||||||||||||||||||||
| 1118 | parser if any. The reverse of the above translation is done to determine | ||||||||||||||||||||||||||||||||||
| 1119 | the appropriate parser, so the 'vo' parser (if any) is called if | ||||||||||||||||||||||||||||||||||
| 1120 | output.format is 'VOTable', and the 'txt' parser (if any) is called if | ||||||||||||||||||||||||||||||||||
| 1121 | output.format is 'ASCII'. If output.format is 'HTML', you will need to | ||||||||||||||||||||||||||||||||||
| 1122 | explicitly set up a parser for that. | ||||||||||||||||||||||||||||||||||
| 1123 | |||||||||||||||||||||||||||||||||||
| 1124 | The type of HTTP interaction depends on the setting of the L<post|/post> | ||||||||||||||||||||||||||||||||||
| 1125 | attribute: if true a POST is done; otherwise all arguments are tacked | ||||||||||||||||||||||||||||||||||
| 1126 | onto the end of the URL and a GET is done. | ||||||||||||||||||||||||||||||||||
| 1127 | |||||||||||||||||||||||||||||||||||
| 1128 | =cut | ||||||||||||||||||||||||||||||||||
| 1129 | |||||||||||||||||||||||||||||||||||
| 1130 | { # Begin local symbol block. | ||||||||||||||||||||||||||||||||||
| 1131 | |||||||||||||||||||||||||||||||||||
| 1132 | 5 | my %type_map = ( # Map SOAP type parameter to URL output.format. | |||||||||||||||||||||||||||||||||
| 1133 | txt => 'ASCII', | ||||||||||||||||||||||||||||||||||
| 1134 | vo => 'VOTable', | ||||||||||||||||||||||||||||||||||
| 1135 | ); | ||||||||||||||||||||||||||||||||||
| 1136 | 5 | my %type_unmap = reverse %type_map; | |||||||||||||||||||||||||||||||||
| 1137 | |||||||||||||||||||||||||||||||||||
| 1138 | # Perl::Critic objects to the use of @_ (rather than values | ||||||||||||||||||||||||||||||||||
| 1139 | # unpacked from it) but the parity check lets me give a less | ||||||||||||||||||||||||||||||||||
| 1140 | # unfriendly error message. CAVEAT: do NOT modify the contents | ||||||||||||||||||||||||||||||||||
| 1141 | # of @_, since this will be seen by the caller. Modifying @_ | ||||||||||||||||||||||||||||||||||
| 1142 | # itself is fine. | ||||||||||||||||||||||||||||||||||
| 1143 | 0 | ▶ | sub url_query { ## no critic (RequireArgUnpacking) | ||||||||||||||||||||||||||||||||
|
Subroutine
url_query: not called CC=10 SCAR=47.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 1144 | 0 | ▶ | @_ % 2 and croak <<eod; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1145 | Error - url_query needs an even number of arguments after the query | ||||||||||||||||||||||||||||||||||
| 1146 | type. | ||||||||||||||||||||||||||||||||||
| 1147 | eod | ||||||||||||||||||||||||||||||||||
| 1148 | 0 | my ($self, $query, %args) = @_; | |||||||||||||||||||||||||||||||||
| 1149 | ### my $debug = $self->get ('debug'); | ||||||||||||||||||||||||||||||||||
| 1150 | 0 | my $dflt = $self->get ('url_args'); | |||||||||||||||||||||||||||||||||
| 1151 | 0 | foreach my $key (keys %$dflt) { | |||||||||||||||||||||||||||||||||
| 1152 | 0 | ▶ | exists ($args{$key}) or $args{$key} = $dflt->{$key}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1153 | } | ||||||||||||||||||||||||||||||||||
| 1154 | 0 | ▶ | unless ($args{'output.format'}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1155 | 0 | my $type = $self->get ('type'); | |||||||||||||||||||||||||||||||||
| 1156 | 0 | ▶ | $args{'output.format'} = $type_map{$type} || $type; | ||||||||||||||||||||||||||||||||
|
Condition0%0/3
$type_map{$type} || $type
MC/DC0%0/2
$type_map{$type} || $type
$type_map{$type}
$type
Truth table0%0/3
A || B
A= $type_map{$type}B= $type
| |||||||||||||||||||||||||||||||||||
| 1157 | } | ||||||||||||||||||||||||||||||||||
| 1158 | 0 | my $resp = $self->_retrieve( "simbad/sim-$query", \%args ); | |||||||||||||||||||||||||||||||||
| 1159 | |||||||||||||||||||||||||||||||||||
| 1160 | 0 | my $rslt = $resp->content(); | |||||||||||||||||||||||||||||||||
| 1161 | |||||||||||||||||||||||||||||||||||
| 1162 | 0 | ▶ | HAVE_DOUBLE_ENCODED | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1163 | and $rslt = XML::DoubleEncodedEntities::decode( $rslt ); | ||||||||||||||||||||||||||||||||||
| 1164 | |||||||||||||||||||||||||||||||||||
| 1165 | 0 | my $parser; | |||||||||||||||||||||||||||||||||
| 1166 | 0 | ▶ | if (my $type = $type_unmap{$args{'output.format'}}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1167 | 0 | $parser = $self->_get_parser ($type); | |||||||||||||||||||||||||||||||||
| 1168 | 0 | ▶ | return wantarray ? ($parser->($rslt)) : [$parser->($rslt)] | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 1169 | if $parser; | ||||||||||||||||||||||||||||||||||
| 1170 | } | ||||||||||||||||||||||||||||||||||
| 1171 | |||||||||||||||||||||||||||||||||||
| 1172 | 0 | return $rslt; | |||||||||||||||||||||||||||||||||
| 1173 | } | ||||||||||||||||||||||||||||||||||
| 1174 | |||||||||||||||||||||||||||||||||||
| 1175 | } # End local symbol block. | ||||||||||||||||||||||||||||||||||
| 1176 | |||||||||||||||||||||||||||||||||||
| 1177 | ######################################################################## | ||||||||||||||||||||||||||||||||||
| 1178 | # | ||||||||||||||||||||||||||||||||||
| 1179 | # Utility routines | ||||||||||||||||||||||||||||||||||
| 1180 | # | ||||||||||||||||||||||||||||||||||
| 1181 | |||||||||||||||||||||||||||||||||||
| 1182 | # __build_url | ||||||||||||||||||||||||||||||||||
| 1183 | # | ||||||||||||||||||||||||||||||||||
| 1184 | # Builds a URL based on the currently-set scheme and server, and | ||||||||||||||||||||||||||||||||||
| 1185 | # the fragment provided as an argument. If the fragment is an | ||||||||||||||||||||||||||||||||||
| 1186 | # HTTP::Request object it is simply returned. | ||||||||||||||||||||||||||||||||||
| 1187 | |||||||||||||||||||||||||||||||||||
| 1188 | 5 | ▶ | sub __build_url { | ||||||||||||||||||||||||||||||||
|
Subroutine
__build_url: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||
| 1189 | 18 | my ( $self, $fragment ) = @_; | |||||||||||||||||||||||||||||||||
| 1190 | 18 | ▶ | defined $fragment | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1191 | or $fragment = ''; | ||||||||||||||||||||||||||||||||||
| 1192 | 18 | ▶ | eval { $fragment->isa( 'HTTP::Request' ) } | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1193 | and return $fragment; | ||||||||||||||||||||||||||||||||||
| 1194 | 16 | $fragment =~ s< \A / ><>smx; # Defensive programming | |||||||||||||||||||||||||||||||||
| 1195 | 16 | return sprintf '%s://%s/%s', $self->get( 'scheme' ), | |||||||||||||||||||||||||||||||||
| 1196 | $self->get( 'server' ), $fragment; | ||||||||||||||||||||||||||||||||||
| 1197 | } | ||||||||||||||||||||||||||||||||||
| 1198 | |||||||||||||||||||||||||||||||||||
| 1199 | # _callers_caller(); | ||||||||||||||||||||||||||||||||||
| 1200 | # | ||||||||||||||||||||||||||||||||||
| 1201 | # Returns the name of the subroutine that called the caller. | ||||||||||||||||||||||||||||||||||
| 1202 | # Results undefined if not called from a subroutine nested at | ||||||||||||||||||||||||||||||||||
| 1203 | # least two deep. | ||||||||||||||||||||||||||||||||||
| 1204 | |||||||||||||||||||||||||||||||||||
| 1205 | 0 | ▶ | sub _callers_caller { | ||||||||||||||||||||||||||||||||
|
Subroutine
_callers_caller: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||
| 1206 | 0 | my $inx = 1; | |||||||||||||||||||||||||||||||||
| 1207 | 0 | my $caller; | |||||||||||||||||||||||||||||||||
| 1208 | 0 | foreach ( 1 .. 2 ) { | |||||||||||||||||||||||||||||||||
| 1209 | 0 | ▶ | do { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1210 | 0 | $caller = ( caller $inx++ )[3] | |||||||||||||||||||||||||||||||||
| 1211 | } while '(eval)' eq $caller; | ||||||||||||||||||||||||||||||||||
| 1212 | } | ||||||||||||||||||||||||||||||||||
| 1213 | 0 | return $caller; | |||||||||||||||||||||||||||||||||
| 1214 | } | ||||||||||||||||||||||||||||||||||
| 1215 | |||||||||||||||||||||||||||||||||||
| 1216 | # $self->_delay | ||||||||||||||||||||||||||||||||||
| 1217 | # | ||||||||||||||||||||||||||||||||||
| 1218 | # Delays the desired amount of time before issuing the next | ||||||||||||||||||||||||||||||||||
| 1219 | # query. | ||||||||||||||||||||||||||||||||||
| 1220 | |||||||||||||||||||||||||||||||||||
| 1221 | { | ||||||||||||||||||||||||||||||||||
| 1222 | 5 | my %last; | |||||||||||||||||||||||||||||||||
| 1223 | 9 | ▶ | sub _delay { | ||||||||||||||||||||||||||||||||
|
Subroutine
_delay: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||
| 1224 | 9 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 1225 | 9 | ▶ | my $last = $last{$self->{server}} ||= 0; | ||||||||||||||||||||||||||||||||
|
Condition100%2/2
$last{$self->{"server"}} ||= 0
MC/DC100%1/1
$last{$self->{"server"}} ||= 0
$last{$self->{"server"}}
Truth table100%2/2
A
A= $last{$self->{"server"}}
| |||||||||||||||||||||||||||||||||||
| 1226 | 9 | ▶ | if ((my $delay = $last + $self->{delay} - time) > 0) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1227 | 6 | sleep ($delay); | |||||||||||||||||||||||||||||||||
| 1228 | } | ||||||||||||||||||||||||||||||||||
| 1229 | 9 | return ($last{$self->{server}} = time); | |||||||||||||||||||||||||||||||||
| 1230 | } | ||||||||||||||||||||||||||||||||||
| 1231 | } | ||||||||||||||||||||||||||||||||||
| 1232 | |||||||||||||||||||||||||||||||||||
| 1233 | # $self->_deprecation_notice( $type, $name ); | ||||||||||||||||||||||||||||||||||
| 1234 | # | ||||||||||||||||||||||||||||||||||
| 1235 | # This method centralizes deprecation. Type is 'attribute' or | ||||||||||||||||||||||||||||||||||
| 1236 | # 'method'. Deprecation is driven of the %deprecate hash. Values | ||||||||||||||||||||||||||||||||||
| 1237 | # are: | ||||||||||||||||||||||||||||||||||
| 1238 | # false - no warning | ||||||||||||||||||||||||||||||||||
| 1239 | # 1 - warn on first use | ||||||||||||||||||||||||||||||||||
| 1240 | # 2 - warn on each use | ||||||||||||||||||||||||||||||||||
| 1241 | # 3 - die on each use. | ||||||||||||||||||||||||||||||||||
| 1242 | # | ||||||||||||||||||||||||||||||||||
| 1243 | # $self->_deprecation_in_progress( $type, $name ) | ||||||||||||||||||||||||||||||||||
| 1244 | # | ||||||||||||||||||||||||||||||||||
| 1245 | # This method returns true if the deprecation is in progress. In | ||||||||||||||||||||||||||||||||||
| 1246 | # practice this means the %deprecate value is defined. | ||||||||||||||||||||||||||||||||||
| 1247 | # This is currently unused and commented out | ||||||||||||||||||||||||||||||||||
| 1248 | |||||||||||||||||||||||||||||||||||
| 1249 | { | ||||||||||||||||||||||||||||||||||
| 1250 | |||||||||||||||||||||||||||||||||||
| 1251 | 5 | my %deprecate = ( | |||||||||||||||||||||||||||||||||
| 1252 | attribute => { | ||||||||||||||||||||||||||||||||||
| 1253 | scheme => { | ||||||||||||||||||||||||||||||||||
| 1254 | http => 1, | ||||||||||||||||||||||||||||||||||
| 1255 | }, | ||||||||||||||||||||||||||||||||||
| 1256 | }, | ||||||||||||||||||||||||||||||||||
| 1257 | method => { | ||||||||||||||||||||||||||||||||||
| 1258 | query => 2, | ||||||||||||||||||||||||||||||||||
| 1259 | }, | ||||||||||||||||||||||||||||||||||
| 1260 | ); | ||||||||||||||||||||||||||||||||||
| 1261 | |||||||||||||||||||||||||||||||||||
| 1262 | 17 | ▶ | sub _deprecation_notice { | ||||||||||||||||||||||||||||||||
|
Subroutine
_deprecation_notice: called CC=12 SCAR=45.6
| |||||||||||||||||||||||||||||||||||
| 1263 | 17 | my ( undef, $type, $name, $repl ) = @_; # Invocant unused | |||||||||||||||||||||||||||||||||
| 1264 | 17 | ▶ | $deprecate{$type} or return; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1265 | 12 | ▶ | $deprecate{$type}{$name} or return; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1266 | 0 | my $msg; | |||||||||||||||||||||||||||||||||
| 1267 | 0 | ▶ | if ( ref( $deprecate{$type}{$name} ) eq HASH_REF ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1268 | 0 | ▶ | $deprecate{$type}{$name}{$repl} | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1269 | or return; | ||||||||||||||||||||||||||||||||||
| 1270 | $msg = sprintf 'The %s %s value %s is %s', $name, $type, $repl, | ||||||||||||||||||||||||||||||||||
| 1271 | 0 | ▶ | $deprecate{$type}{$name} > 2 ? 'removed' : 'deprecated'; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1272 | $deprecate{$type}{$name}{$repl} == 1 | ||||||||||||||||||||||||||||||||||
| 1273 | 0 | ▶ | and $deprecate{$type}{$name}{$repl} = 0; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1274 | } else { | ||||||||||||||||||||||||||||||||||
| 1275 | $msg = sprintf 'The %s %s is %s', $name, $type, | ||||||||||||||||||||||||||||||||||
| 1276 | 0 | ▶ | $deprecate{$type}{$name} > 2 ? 'removed' : 'deprecated'; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1277 | 0 | ▶ | defined $repl | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1278 | and $msg .= "; use $repl instead"; | ||||||||||||||||||||||||||||||||||
| 1279 | $deprecate{$type}{$name} == 1 | ||||||||||||||||||||||||||||||||||
| 1280 | 0 | ▶ | and $deprecate{$type}{$name} = 0; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1281 | } | ||||||||||||||||||||||||||||||||||
| 1282 | 0 | ▶ | $deprecate{$type}{$name} >= 3 | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1283 | and croak( $msg ); | ||||||||||||||||||||||||||||||||||
| 1284 | 0 | ▶ | warnings::enabled( 'deprecated' ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1285 | and carp( $msg ); | ||||||||||||||||||||||||||||||||||
| 1286 | 0 | return; | |||||||||||||||||||||||||||||||||
| 1287 | } | ||||||||||||||||||||||||||||||||||
| 1288 | |||||||||||||||||||||||||||||||||||
| 1289 | =begin comment | ||||||||||||||||||||||||||||||||||
| 1290 | |||||||||||||||||||||||||||||||||||
| 1291 | sub _deprecation_in_progress { | ||||||||||||||||||||||||||||||||||
| 1292 | my ( undef, $type, $name ) = @_; # Invocant unused | ||||||||||||||||||||||||||||||||||
| 1293 | $deprecate{$type} or return; | ||||||||||||||||||||||||||||||||||
| 1294 | return defined $deprecate{$type}{$name}; | ||||||||||||||||||||||||||||||||||
| 1295 | } | ||||||||||||||||||||||||||||||||||
| 1296 | |||||||||||||||||||||||||||||||||||
| 1297 | =end comment | ||||||||||||||||||||||||||||||||||
| 1298 | |||||||||||||||||||||||||||||||||||
| 1299 | =cut | ||||||||||||||||||||||||||||||||||
| 1300 | |||||||||||||||||||||||||||||||||||
| 1301 | } | ||||||||||||||||||||||||||||||||||
| 1302 | |||||||||||||||||||||||||||||||||||
| 1303 | # $ref = $self->_get_coderef ($string) | ||||||||||||||||||||||||||||||||||
| 1304 | # | ||||||||||||||||||||||||||||||||||
| 1305 | # Translates the given string into a code reference, loading | ||||||||||||||||||||||||||||||||||
| 1306 | # modules if needed. If the string is not a fully-qualified | ||||||||||||||||||||||||||||||||||
| 1307 | # subroutine name, it is assumed to be in the namespace of | ||||||||||||||||||||||||||||||||||
| 1308 | # the first caller not in this namespace. Failed loads are | ||||||||||||||||||||||||||||||||||
| 1309 | # cached so that they will not be tried again. | ||||||||||||||||||||||||||||||||||
| 1310 | |||||||||||||||||||||||||||||||||||
| 1311 | { | ||||||||||||||||||||||||||||||||||
| 1312 | |||||||||||||||||||||||||||||||||||
| 1313 | 5 | ▶ | sub _get_coderef { | ||||||||||||||||||||||||||||||||
|
Subroutine
_get_coderef: called CC=6 SCAR=21.4
| |||||||||||||||||||||||||||||||||||
| 1314 | 14 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 1315 | 14 | my $parser = shift; | |||||||||||||||||||||||||||||||||
| 1316 | 14 | ▶ | if ($parser && !ref $parser) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$parser and not ref $parser
MC/DC0%0/2
$parser and not ref $parser
$parser
not ref $parser
Truth table33%1/3
A and not(B)
A= $parserB= not ref $parser
| |||||||||||||||||||||||||||||||||||
| 1317 | 14 | my ($pkg, $code) = | |||||||||||||||||||||||||||||||||
| 1318 | $self->_parse_subroutine_name ($parser); | ||||||||||||||||||||||||||||||||||
| 1319 | 14 | ▶ | unless (($parser = $pkg->can ($code)) || !$self->get ('autoload')) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$parser = $pkg->can($code) or not $self->get("autoload")
MC/DC0%0/2
$parser = $pkg->can($code) or not $self->get("autoload")
$parser = $pkg->can($code)
not $self->get("autoload")
Truth table33%1/3
A or not(B)
A= $parser = $pkg->can($code)B= not $self->get("autoload")
| |||||||||||||||||||||||||||||||||||
| 1320 | 0 | _load_module ($pkg); | |||||||||||||||||||||||||||||||||
| 1321 | 0 | $parser = $pkg->can ($code); | |||||||||||||||||||||||||||||||||
| 1322 | } | ||||||||||||||||||||||||||||||||||
| 1323 | 14 | ▶ | $parser or croak "Error - ${pkg}::$code undefined"; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1324 | } | ||||||||||||||||||||||||||||||||||
| 1325 | 14 | return $parser; | |||||||||||||||||||||||||||||||||
| 1326 | } | ||||||||||||||||||||||||||||||||||
| 1327 | |||||||||||||||||||||||||||||||||||
| 1328 | } | ||||||||||||||||||||||||||||||||||
| 1329 | |||||||||||||||||||||||||||||||||||
| 1330 | # $parser = $self->_get_parser ($type) | ||||||||||||||||||||||||||||||||||
| 1331 | |||||||||||||||||||||||||||||||||||
| 1332 | # returns the code reference to the parser for the given type of | ||||||||||||||||||||||||||||||||||
| 1333 | # data, or false if none. An exception is thrown if the value | ||||||||||||||||||||||||||||||||||
| 1334 | # is a string which does not specify a defined subroutine. | ||||||||||||||||||||||||||||||||||
| 1335 | |||||||||||||||||||||||||||||||||||
| 1336 | 5 | ▶ | sub _get_parser { | ||||||||||||||||||||||||||||||||
|
Subroutine
_get_parser: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 1337 | 6 | my ($self, $type) = @_; | |||||||||||||||||||||||||||||||||
| 1338 | 6 | return $self->_get_coderef ($self->get ('parser')->{$type}); | |||||||||||||||||||||||||||||||||
| 1339 | } | ||||||||||||||||||||||||||||||||||
| 1340 | |||||||||||||||||||||||||||||||||||
| 1341 | # Return false if the argument is a URI scheme we know how to deal with; | ||||||||||||||||||||||||||||||||||
| 1342 | # otherwise return an error message. The optional second argument is a | ||||||||||||||||||||||||||||||||||
| 1343 | # template for the message, with a single '%s' that gets the actual | ||||||||||||||||||||||||||||||||||
| 1344 | # value of the scheme. | ||||||||||||||||||||||||||||||||||
| 1345 | |||||||||||||||||||||||||||||||||||
| 1346 | { | ||||||||||||||||||||||||||||||||||
| 1347 | 5 | my %supported; | |||||||||||||||||||||||||||||||||
| 1348 | |||||||||||||||||||||||||||||||||||
| 1349 | 5 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 1350 | 5 | %supported = map { $_ => 1 } qw{ http https }; | |||||||||||||||||||||||||||||||||
| 1351 | } | ||||||||||||||||||||||||||||||||||
| 1352 | |||||||||||||||||||||||||||||||||||
| 1353 | 17 | ▶ | sub _is_scheme_valid { | ||||||||||||||||||||||||||||||||
|
Subroutine
_is_scheme_valid: called CC=5 SCAR=17.5
| |||||||||||||||||||||||||||||||||||
| 1354 | 17 | my ( $scheme, $msg ) = @_; | |||||||||||||||||||||||||||||||||
| 1355 | 17 | ▶ | $scheme = lc( $scheme || '' ); | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
$scheme || ''
MC/DC0%0/1
$scheme || ''
$scheme
Truth table50%1/2
A
A= $scheme
| |||||||||||||||||||||||||||||||||||
| 1356 | 17 | __PACKAGE__->_deprecation_notice( attribute => 'query', 'http' ); | |||||||||||||||||||||||||||||||||
| 1357 | 17 | ▶ | $msg ||= q<Unsupported scheme '%s'>; | ||||||||||||||||||||||||||||||||
|
Condition100%2/2
$msg ||= "Unsupported scheme '%s'"
MC/DC100%1/1
$msg ||= "Unsupported scheme '%s'"
$msg
Truth table100%2/2
A
A= $msg
| |||||||||||||||||||||||||||||||||||
| 1358 | 17 | ▶ | $supported{$scheme} | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1359 | or return sprintf $msg, $scheme; | ||||||||||||||||||||||||||||||||||
| 1360 | 17 | ▶ | LWP::Protocol::implementor( $scheme ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1361 | and return; | ||||||||||||||||||||||||||||||||||
| 1362 | 0 | $msg .= "; have you installed LWP::Protocol::$scheme?"; | |||||||||||||||||||||||||||||||||
| 1363 | 0 | return sprintf $msg, $scheme; | |||||||||||||||||||||||||||||||||
| 1364 | } | ||||||||||||||||||||||||||||||||||
| 1365 | } | ||||||||||||||||||||||||||||||||||
| 1366 | |||||||||||||||||||||||||||||||||||
| 1367 | # $rslt = _load_module($name) | ||||||||||||||||||||||||||||||||||
| 1368 | # | ||||||||||||||||||||||||||||||||||
| 1369 | # This subroutine loads the named module using 'require'. It | ||||||||||||||||||||||||||||||||||
| 1370 | # croaks if the load fails, or returns the result of the | ||||||||||||||||||||||||||||||||||
| 1371 | # 'require' if it succeeds. Results are cached, so subsequent | ||||||||||||||||||||||||||||||||||
| 1372 | # calls simply do what the first one did. | ||||||||||||||||||||||||||||||||||
| 1373 | |||||||||||||||||||||||||||||||||||
| 1374 | { # Local symbol block. Oh, for 5.10 and state variables. | ||||||||||||||||||||||||||||||||||
| 1375 | 5 | my %error; | |||||||||||||||||||||||||||||||||
| 1376 | 5 | my %rslt; | |||||||||||||||||||||||||||||||||
| 1377 | 10 | ▶ | sub _load_module { | ||||||||||||||||||||||||||||||||
|
Subroutine
_load_module: called CC=4 SCAR=15.2
| |||||||||||||||||||||||||||||||||||
| 1378 | 10 | my ($module) = @_; | |||||||||||||||||||||||||||||||||
| 1379 | 10 | ▶ | exists $error{$module} and croak $error{$module}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1380 | 10 | ▶ | exists $rslt{$module} and return $rslt{$module}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1381 | 10 | $rslt{$module} = eval "require $module"; | |||||||||||||||||||||||||||||||||
| 1382 | 10 | ▶ | $@ and croak ($error{$module} = $@); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1383 | 0 | return $rslt{$module}; | |||||||||||||||||||||||||||||||||
| 1384 | } | ||||||||||||||||||||||||||||||||||
| 1385 | } # End local symbol block. | ||||||||||||||||||||||||||||||||||
| 1386 | |||||||||||||||||||||||||||||||||||
| 1387 | # $ua = $self->_get_user_agent(); | ||||||||||||||||||||||||||||||||||
| 1388 | # | ||||||||||||||||||||||||||||||||||
| 1389 | # This subroutine returns an LWP::UserAgent object with its agent | ||||||||||||||||||||||||||||||||||
| 1390 | # string set to the default, with our class name and version | ||||||||||||||||||||||||||||||||||
| 1391 | # appended in parentheses. | ||||||||||||||||||||||||||||||||||
| 1392 | |||||||||||||||||||||||||||||||||||
| 1393 | 5 | ▶ | sub _get_user_agent { | ||||||||||||||||||||||||||||||||
|
Subroutine
_get_user_agent: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 1394 | 9 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||
| 1395 | 9 | my $ua = LWP::UserAgent->new( | |||||||||||||||||||||||||||||||||
| 1396 | agent => $self->agent(), | ||||||||||||||||||||||||||||||||||
| 1397 | timeout => $self->get( 'timeout' ), | ||||||||||||||||||||||||||||||||||
| 1398 | ); | ||||||||||||||||||||||||||||||||||
| 1399 | 9 | return $ua; | |||||||||||||||||||||||||||||||||
| 1400 | } | ||||||||||||||||||||||||||||||||||
| 1401 | |||||||||||||||||||||||||||||||||||
| 1402 | # ($package, $subroutine) = $self->_parse_subroutine_name ($name); | ||||||||||||||||||||||||||||||||||
| 1403 | # | ||||||||||||||||||||||||||||||||||
| 1404 | # This method parses the given name, and returns the package name | ||||||||||||||||||||||||||||||||||
| 1405 | # in which the subroutine is defined and the subroutine name. If | ||||||||||||||||||||||||||||||||||
| 1406 | # the $name is a bare subroutine name, the package is the calling | ||||||||||||||||||||||||||||||||||
| 1407 | # package unless that package contains no such subroutine but | ||||||||||||||||||||||||||||||||||
| 1408 | # $self->can($name) is true, in which case the package is | ||||||||||||||||||||||||||||||||||
| 1409 | # ref($self). | ||||||||||||||||||||||||||||||||||
| 1410 | # | ||||||||||||||||||||||||||||||||||
| 1411 | # If called in scalar context, the package is returned. | ||||||||||||||||||||||||||||||||||
| 1412 | |||||||||||||||||||||||||||||||||||
| 1413 | 16 | ▶ | sub _parse_subroutine_name { | ||||||||||||||||||||||||||||||||
|
Subroutine
_parse_subroutine_name: called CC=9 SCAR=22.3
| |||||||||||||||||||||||||||||||||||
| 1414 | 16 | my ($self, $parser) = @_; | |||||||||||||||||||||||||||||||||
| 1415 | 16 | my @parts = split '::', $parser; | |||||||||||||||||||||||||||||||||
| 1416 | 16 | my $code = pop @parts; | |||||||||||||||||||||||||||||||||
| 1417 | 16 | my $pkg = join '::', @parts; | |||||||||||||||||||||||||||||||||
| 1418 | 16 | ▶ | unless ($pkg) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1419 | 4 | my %tried = (__PACKAGE__, 1); | |||||||||||||||||||||||||||||||||
| 1420 | 4 | my $inx = 1; | |||||||||||||||||||||||||||||||||
| 1421 | 4 | ▶ | while ($pkg = (caller ($inx++))[0]) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1422 | 28 | ▶ | next if $tried{$pkg}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1423 | 10 | $tried{$pkg} = 1; | |||||||||||||||||||||||||||||||||
| 1424 | 10 | ▶ | last if $pkg->can ($code); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1425 | } | ||||||||||||||||||||||||||||||||||
| 1426 | 4 | ▶ | $pkg = ref $self if !$pkg && $self->can ($code); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $pkg and $self->can($code)
MC/DC0%0/2
not $pkg and $self->can($code)
not $pkg
$self->can($code)
Truth table33%1/3
not(A) and B
A= not $pkgB= $self->can($code)
| |||||||||||||||||||||||||||||||||||
| 1427 | 4 | ▶ | defined $pkg or croak <<eod; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1428 | Error - '$parser' yields undefined package name. | ||||||||||||||||||||||||||||||||||
| 1429 | eod | ||||||||||||||||||||||||||||||||||
| 1430 | 4 | @parts = split '::', $pkg; | |||||||||||||||||||||||||||||||||
| 1431 | } | ||||||||||||||||||||||||||||||||||
| 1432 | 16 | ▶ | return wantarray ? ($pkg, $code) : $pkg; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1433 | } | ||||||||||||||||||||||||||||||||||
| 1434 | |||||||||||||||||||||||||||||||||||
| 1435 | # my $resp = __random_server( $server, $default ); | ||||||||||||||||||||||||||||||||||
| 1436 | # | ||||||||||||||||||||||||||||||||||
| 1437 | # Select a random server, which must be responsive. The return is | ||||||||||||||||||||||||||||||||||
| 1438 | # an HTTP::Response object. If it represents a successful | ||||||||||||||||||||||||||||||||||
| 1439 | # response, header 'x-simbad-server' will be set to the selected | ||||||||||||||||||||||||||||||||||
| 1440 | # server. | ||||||||||||||||||||||||||||||||||
| 1441 | # | ||||||||||||||||||||||||||||||||||
| 1442 | # The arguments are optional. | ||||||||||||||||||||||||||||||||||
| 1443 | # | ||||||||||||||||||||||||||||||||||
| 1444 | # $server must be an lvalue, which will be assigned the selected | ||||||||||||||||||||||||||||||||||
| 1445 | # server if one is found. | ||||||||||||||||||||||||||||||||||
| 1446 | # | ||||||||||||||||||||||||||||||||||
| 1447 | # If $default is specified, $server will be assigned $default if | ||||||||||||||||||||||||||||||||||
| 1448 | # no responsive server is found. | ||||||||||||||||||||||||||||||||||
| 1449 | # | ||||||||||||||||||||||||||||||||||
| 1450 | # We **MUST** use $_[0] rather than an unpacked version, because | ||||||||||||||||||||||||||||||||||
| 1451 | # @_ is aliased to the actual arguments, and we want to modify the | ||||||||||||||||||||||||||||||||||
| 1452 | # first one. | ||||||||||||||||||||||||||||||||||
| 1453 | |||||||||||||||||||||||||||||||||||
| 1454 | 4 | ▶ | sub __random_server { ## no critic (RequireArgUnpacking) | ||||||||||||||||||||||||||||||||
|
Subroutine
__random_server: called CC=5 SCAR=16.9
| |||||||||||||||||||||||||||||||||||
| 1455 | 4 | my $ua = LWP::UserAgent->new( | |||||||||||||||||||||||||||||||||
| 1456 | timeout => 10, | ||||||||||||||||||||||||||||||||||
| 1457 | ); | ||||||||||||||||||||||||||||||||||
| 1458 | 4 | my $smb = __PACKAGE__->new(); | |||||||||||||||||||||||||||||||||
| 1459 | 4 | my @known_servers = qw{ | |||||||||||||||||||||||||||||||||
| 1460 | simbad.unistra.fr | ||||||||||||||||||||||||||||||||||
| 1461 | simbad.cfa.harvard.edu | ||||||||||||||||||||||||||||||||||
| 1462 | simbad.idia.ac.za | ||||||||||||||||||||||||||||||||||
| 1463 | }; | ||||||||||||||||||||||||||||||||||
| 1464 | 4 | my $resp; | |||||||||||||||||||||||||||||||||
| 1465 | 4 | ▶ | while ( @known_servers ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1466 | 6 | my $inx = int rand scalar @known_servers; | |||||||||||||||||||||||||||||||||
| 1467 | 6 | my $server = splice @known_servers, $inx, 1; | |||||||||||||||||||||||||||||||||
| 1468 | 6 | $smb->set( server => $server ); | |||||||||||||||||||||||||||||||||
| 1469 | 6 | $resp = $ua->head( $smb->__build_url( 'simbad/' ) ); | |||||||||||||||||||||||||||||||||
| 1470 | 6 | ▶ | $resp->is_success() | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1471 | or next; | ||||||||||||||||||||||||||||||||||
| 1472 | 4 | $resp->header( 'x-simbad-server', $server ); | |||||||||||||||||||||||||||||||||
| 1473 | 4 | ▶ | $_[0] = $server if @_; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1474 | 4 | return $resp; | |||||||||||||||||||||||||||||||||
| 1475 | } | ||||||||||||||||||||||||||||||||||
| 1476 | 0 | ▶ | $_[0] = $_[1] if @_ > 1; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1477 | 0 | return $resp; | |||||||||||||||||||||||||||||||||
| 1478 | } | ||||||||||||||||||||||||||||||||||
| 1479 | |||||||||||||||||||||||||||||||||||
| 1480 | # my $resp = $self->_retrieve( $fragment, \%args ); | ||||||||||||||||||||||||||||||||||
| 1481 | # | ||||||||||||||||||||||||||||||||||
| 1482 | # Build a URL from the contents of the 'scheme' and 'server' | ||||||||||||||||||||||||||||||||||
| 1483 | # attributes, and the given fragment, and retrieve the data from | ||||||||||||||||||||||||||||||||||
| 1484 | # that URL. The \%args argument is optional. | ||||||||||||||||||||||||||||||||||
| 1485 | # | ||||||||||||||||||||||||||||||||||
| 1486 | # The return is an HTTP::Response object. If the response is | ||||||||||||||||||||||||||||||||||
| 1487 | # indicates that the request is unsuccessful we croak with the URL | ||||||||||||||||||||||||||||||||||
| 1488 | # (if that can be retrieved) and the status line. | ||||||||||||||||||||||||||||||||||
| 1489 | # | ||||||||||||||||||||||||||||||||||
| 1490 | # The details depend on the arguments and the state of the | ||||||||||||||||||||||||||||||||||
| 1491 | # invocant as follows: | ||||||||||||||||||||||||||||||||||
| 1492 | # | ||||||||||||||||||||||||||||||||||
| 1493 | # If $url is an HTTP::Request object, it is executed and the | ||||||||||||||||||||||||||||||||||
| 1494 | # response returned. Otherwise | ||||||||||||||||||||||||||||||||||
| 1495 | # | ||||||||||||||||||||||||||||||||||
| 1496 | # If \%args is present and not empty, and the 'post' attribute is | ||||||||||||||||||||||||||||||||||
| 1497 | # true, an HTTP post() request is done to the URL, sending the | ||||||||||||||||||||||||||||||||||
| 1498 | # data. Otherwise | ||||||||||||||||||||||||||||||||||
| 1499 | # | ||||||||||||||||||||||||||||||||||
| 1500 | # If there are arguments they are appended to the URL, and an HTTP | ||||||||||||||||||||||||||||||||||
| 1501 | # get() is done to the URL. | ||||||||||||||||||||||||||||||||||
| 1502 | |||||||||||||||||||||||||||||||||||
| 1503 | 9 | ▶ | sub _retrieve { | ||||||||||||||||||||||||||||||||
|
Subroutine
_retrieve: called CC=13 SCAR=29.6
| |||||||||||||||||||||||||||||||||||
| 1504 | 9 | my ($self, $fragment, $args) = @_; | |||||||||||||||||||||||||||||||||
| 1505 | 9 | my $url = $self->__build_url( $fragment ); | |||||||||||||||||||||||||||||||||
| 1506 | 9 | ▶ | $args ||= {}; | ||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args ||= {}
MC/DC100%1/1
$args ||= {}
$args
Truth table100%2/2
A
A= $args
| |||||||||||||||||||||||||||||||||||
| 1507 | 9 | my $debug = $self->get( 'debug' ); | |||||||||||||||||||||||||||||||||
| 1508 | 9 | my $ua = $self->_get_user_agent(); | |||||||||||||||||||||||||||||||||
| 1509 | 9 | $self->_delay(); | |||||||||||||||||||||||||||||||||
| 1510 | 9 | my $resp; | |||||||||||||||||||||||||||||||||
| 1511 | 9 | ▶ | if (eval {$url->isa('HTTP::Request')}) { | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 1512 | 2 | ▶ | $debug | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1513 | and print 'Debug ', _callers_caller(), 'executing ', | ||||||||||||||||||||||||||||||||||
| 1514 | $url->as_string, "\n"; | ||||||||||||||||||||||||||||||||||
| 1515 | 2 | $resp = $ua->request ($url); | |||||||||||||||||||||||||||||||||
| 1516 | ▶ | } elsif ($self->get ('post') && %$args) { | |||||||||||||||||||||||||||||||||
|
Condition66%2/3
$self->get("post") and %$args
MC/DC50%1/2
$self->get("post") and %$args
$self->get("post")
%$args
Truth table66%2/3
A and B
A= $self->get("post")B= %$args
| |||||||||||||||||||||||||||||||||||
| 1517 | 4 | ▶ | if ($debug) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1518 | 0 | print 'Debug ', _callers_caller(), " posting to $url\n"; | |||||||||||||||||||||||||||||||||
| 1519 | 0 | foreach my $key (sort keys %$args) { | |||||||||||||||||||||||||||||||||
| 1520 | 0 | print " $key => $args->{$key}\n"; | |||||||||||||||||||||||||||||||||
| 1521 | } | ||||||||||||||||||||||||||||||||||
| 1522 | } | ||||||||||||||||||||||||||||||||||
| 1523 | 4 | $resp = $ua->post ($url, $args); | |||||||||||||||||||||||||||||||||
| 1524 | } else { | ||||||||||||||||||||||||||||||||||
| 1525 | 3 | my $join = '?'; | |||||||||||||||||||||||||||||||||
| 1526 | 3 | foreach my $key (sort keys %$args) { | |||||||||||||||||||||||||||||||||
| 1527 | $url .= $join . _escape_uri( $key ) . '=' . _escape_uri ( | ||||||||||||||||||||||||||||||||||
| 1528 | 0 | $args->{$key} ); | |||||||||||||||||||||||||||||||||
| 1529 | 0 | $join = '&'; | |||||||||||||||||||||||||||||||||
| 1530 | } | ||||||||||||||||||||||||||||||||||
| 1531 | $debug | ||||||||||||||||||||||||||||||||||
| 1532 | 3 | ▶ | and print 'Debug ', _callers_caller(), " getting from $url\n"; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1533 | 3 | $resp = $ua->get( $url ); | |||||||||||||||||||||||||||||||||
| 1534 | } | ||||||||||||||||||||||||||||||||||
| 1535 | 9 | ▶ | $debug | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1536 | and print 'Debug - request: ', $resp->request()->as_string(), "\n"; | ||||||||||||||||||||||||||||||||||
| 1537 | |||||||||||||||||||||||||||||||||||
| 1538 | 9 | ▶ | $resp->is_success() | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1539 | and return $resp; | ||||||||||||||||||||||||||||||||||
| 1540 | |||||||||||||||||||||||||||||||||||
| 1541 | 0 | ▶ | my $rq = $resp->request() | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1542 | or croak $resp->status_line(); | ||||||||||||||||||||||||||||||||||
| 1543 | 0 | my $u = $rq->uri(); | |||||||||||||||||||||||||||||||||
| 1544 | 0 | croak "$u: ", $resp->status_line(); | |||||||||||||||||||||||||||||||||
| 1545 | } | ||||||||||||||||||||||||||||||||||
| 1546 | |||||||||||||||||||||||||||||||||||
| 1547 | 5 | 1; | |||||||||||||||||||||||||||||||||
| 1548 | |||||||||||||||||||||||||||||||||||
| 1549 | __END__ | ||||||||||||||||||||||||||||||||||