NAME
UserAgent::Any::Response – Response object for UserAgent::Any
SYNOPSIS
my $response = $any_ua->get($url);
if ($response->success) {
print $response->content."\n";
} else {
print $response->status_code." ".$response->status_text."\n";
}
DESCRIPTION
UserAgent::Any::Response
is a read-only object containing the response from a call made by UserAgent::Any.
Constructor
my $res = UserAgent::Any::Response->new($underlying_response);
Builds a new UserAgent::Any::Response
object wrapping the given underlying response. Currently supported wrapped objects are HTTP::Response, Mojo::Message::Response and HTTP::Promise::Response. Feel free to ask for or contribute new implementations.
Methods
status_code
my $code = $res->status_code;
Returns the 3 digit numerical status code of the HTTP Response.
status_text
my $text = $res->status_text;
Returns the response status message attribute explaining the response code.
success
my $bool = $res->success;
Returns whether the request was successful (which typically means that the status code is in the 200 .. 299
range).
content
my $bytes = $res->content;
Returns the decoded response content according to the Content-Encoding
header and, for text content (as per the Content-Type
header) attempt to decode the text into a Perl unicode string.
Note that this is often called decoded_content
in other response objects. But, as this is what you should always use, we settled here on the simpler name.
decoded_content
my $text = $res->decoded_content;
Returns the raw response content. This should be treated as a string of bytes.
Note that this is often called content
in other response objects. But in general you don’t want to use that field unless you are doing low-level manipulations.
headers
my %headers = $res->headers;
my @headers_key_value_list = $res->headers;
Returns all headers of the response. Note that this actually returns a list of alternating keys and values and that a given key can appear more than once if a given header appears more than once in the response.
header
my $header = $res->header($string);
my @headers = $res->header($string);
Returns the value of the given header. if the header appears multiple times in the response then returns the concatenated values (separated by ,
) in scalar context or all the values in list content.
res
my $obj = $res->res;
Returns the underlying response object being wrapped.
AUTHOR
Mathias Kende <mathias@cpan.org>
COPYRIGHT AND LICENSE
Copyright 2024 Mathias Kende
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.