This runs two requests: one to get the metadata using the API and the second to get the image itself. If you don't need the image, it would be better (and faster) for you to use the fetch_metadata method below.

NAMING

How do I write "xkcd"? There's nothing in Strunk and White about this.
For those of us pedantic enough to want a rule, here it is: The preferred
form is "xkcd", all lower-case. In formal contexts where a lowercase word
shouldn't start a sentence, "XKCD" is an okay alternative. "Xkcd" is
frowned upon.

DEPENDENCIES

Try::Tiny

HTTP::Tiny

JSON

Carp

OPTIONAL DEPENDENCIES

AnyEvent

AnyEvent::HTTP

AUTHOR

Sawyer X <xsawyerx@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2018 by Sawyer X.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.