Acme-Insult-Pirate
view release on metacpan or search on metacpan
lib/Acme/Insult/Pirate.pm view on Meta::CPAN
#~ use JSON::Tiny qw[decode_json]; # Not needed here (yet)
use URI;
use parent 'Exporter';
our %EXPORT_TAGS = ( all => [ our @EXPORT_OK = qw[insult] ] );
#
use overload '""' => sub ( $s, $u, $b ) { $s->{insult} // () };
#
sub _http (%params) {
state $http
//= HTTP::Tiny->new( default_headers => { Accept => 'application/json' }, agent => sprintf '%s/%.2f ', __PACKAGE__, our $VERSION );
state $api //= URI->new('https://pirate.monkeyness.com/api/insult');
#~ $api->query_form( %params );
my $res = $http->get($api); # {success} is true even when advice is not found but we'll at least know when we have valid JSON
# This API only returns strings for now
#~ $res->{success} ? decode_json( $res->{content} ) : ();
$res->{success} ? { insult => $res->{content} } : ();
}
#
( run in 0.270 second using v1.01-cache-2.11-cpan-8780591d54d )