Address-PostCode-UserAgent
view release on metacpan or search on metacpan
lib/Address/PostCode/UserAgent.pm view on Meta::CPAN
=head1 DESCRIPTION
The L<Address::PostCode::UserAgent> module is the core library Address::PostCode::* family.
=head1 METHODS
=head2 get($url, \%headers)
It requires URL and optionally headers. It returns the standard response.On error
throws exception of type L<Address::PostCode::UserAgent::Exception>.
=cut
sub get {
my ($self, $url, $headers) = @_;
die "ERROR: Headers have to be hash ref." if (defined $headers && ref($headers) ne 'HASH');
my $ua = $self->ua;
my $response = (defined $headers)
?
($ua->request('GET', $url, { headers => $headers }))
:
($ua->request('GET', $url));
my @caller = caller(1);
@caller = caller(2) if $caller[3] eq '(eval)';
unless ($response->{success}) {
Address::PostCode::UserAgent::Exception->throw({
method => $caller[3],
message => "request to API failed",
code => $response->{status},
reason => $response->{reason},
filename => $caller[1],
line_number => $caller[2] });
}
return $response;
}
( run in 0.570 second using v1.01-cache-2.11-cpan-496ff517765 )