Acme-Free-Advice-Unsolicited

 view release on metacpan or  search on metacpan

lib/Acme/Free/Advice/Unsolicited.pm  view on Meta::CPAN

package Acme::Free::Advice::Unsolicited 1.1 {    # https://kk-advice.koyeb.app/api
    use v5.38;
    use HTTP::Tiny;
    use JSON::Tiny qw[decode_json];
    use parent 'Exporter';
    our %EXPORT_TAGS = ( all => [ our @EXPORT_OK = qw[advice all] ] );
    #
    use overload '""' => sub ( $s, $u, $b ) { $s->{advice} // () };
    #
    sub _http ($uri) {
        state $http
            //= HTTP::Tiny->new( default_headers => { Accept => 'application/json' }, agent => sprintf '%s/%.2f ', __PACKAGE__, our $VERSION );
        my $res = $http->get($uri);    # {success} is true even when advice is not found but we'll at least know when we have valid JSON
        $res->{success} ? decode_json( $res->{content} ) : ();
    }



( run in 0.513 second using v1.01-cache-2.11-cpan-4d50c553e7e )