60. Using a cache
use HTTP::Tiny::Mech;
use MetaCPAN::API;
use WWW::Mechanize::Cached;
my $mcpan = MetaCPAN::API->new(
ua => HTTP::Tiny::Mech->new(
mechua => WWW::Mechanize::Cached->new()
)
);
61.
62. Enable Compression
• use WWW::Mechanize::Gzip
• use WWW::Mechanize::Cached::Gzip
• Or set the appropriate request header
63. Use the scrolling API
• The scrolling API allows you to iterate
over an arbitrary number of results
• Be aware that when you scroll, your
docs will come back unsorted
Editor's Notes
show of hands: \n1) have used the metacpan search site \n2) use it as their default search site \n3) have worked with the API\n
\n
\n
\n
\n
\n
\n
\n
\n
CPAN visualization tool\n
\n
\n
\n
Exports Pod into a format you can import right into your Kindle app.\n
\n
Drop-in replacement for Perldoc. Read documentation for modules which you haven’t even installed. Genius.\n
\n
\n
\n
\n
\n
You can see that for the email and website fields, we allow you to provide a list rather than a single value. Now, for our example we need an author’s Github profile. Matt Trout does not provide this, so he’s a bad test case for our script.\n
Things like StackOverflow, Twitter and Github usernames are all provided by authors voluntarily after logging in to MetaCPAN. In order to see what the profiles look like in a data structure, we need to find an author who has filled these fields.\n
You can see from Mo’s example here that he has filled out some of his profile information. He’s a good test case. Note the MetaCPAN explorer link on the bottom left corner. These links can also be found on the module and release pages.\n
This is a great way to explore the various endpoints of the API and practice crafting queries by hand. However, today we’re just concerned with the /author endpoint.\n
\n
\n
You can see here that since we’re no longer using a convenience endpoint, the output is a little busier. What we generally care about here is the list provided inside of hits->{hits}. In each list item, we care about _source and _source->{profile} in particular.\n