Developing my first Perl module turned out to be quite amusing, so I was happy to do it again, and here’s my second contribution to the wonderful world of CPAN: WebService::Gravatar, a Perl interface to Gravatar XML-RPC API.
Here’s a quick usage example (taken from the documentation):
use WebService::Gravatar;
use MIME::Base64;
# Create a new instance of WebService::Gravatar
my $grav = WebService::Gravatar->new(email => 'your@email.address',
apikey => 'your_API_key');
# Get a list of addresses
my $addresses = $grav->addresses;
if (defined $addresses) {
# Print the userimage URL for each e-mail address
foreach my $email (keys %$addresses) {
print $addresses->{$email}->{'userimage_url'} . "\n";
}
}
else {
# We have a problem
print STDERR "Error: " . $grav->errstr . "\n";
}
# Read image file data
my $data;
{
local $/ = undef;
open(F, "< my_pretty_face.png");
$data = <F>;
close(F);
}
# Save the image as a new userimage
$grav->save_data(data => encode_base64($data), rating => 0);
...