MooX-Role-HTTP-Tiny
view release on metacpan or search on metacpan
lib/MooX/Role/REST.pm view on Meta::CPAN
Mandatory method that implements the actual HTTP stuff.
=cut
sub call {
my $self = shift;
$self->validate_positional_parameters(
[
$self->parameter(http_method => $self->Required, { store => \my $hmethod }),
$self->parameter(call_path => $self->Required, { store => \my $cpath }),
$self->parameter(call_data => $self->Optional, { store => \my $cdata }),
],
\@_
);
my $endpoint = $self->base_uri->clone;
(my $path = $endpoint->path) =~ s{/+$}{};
$path = $cpath =~ m{^ / }x ? $cpath : "$path/$cpath";
$endpoint->path($path);
my @body;
# GET and DELETE have no body
if ($hmethod =~ m{^ (?: GET | DELETE ) $}x) {
my $params = $cdata ? $self->www_form_urlencode($cdata) : '';
$endpoint->query($params) if $params;
}
else {
@body = $cdata ? { content => encode_json($cdata) } : ();
}
print STDERR ">>>$hmethod($endpoint)>>>@body<<<\n"
if $DEBUG;
my $response = $self->request($hmethod, $endpoint->as_string, @body);
use Data::Dumper; local($Data::Dumper::Indent, $Data::Dumper::Sortkeys) = (1, 1);
print STDERR ">>>" . Dumper($response) . "<<<\n" if $DEBUG;
my ($ct) = split(m{\s*;\s*}, $response->{headers}{'content-type'}, 2);
( run in 0.254 second using v1.01-cache-2.11-cpan-454fe037f31 )