Templa...avatar(3pm)
π NAME π
Template::Plugin::Gravatar β bestie, this is your configurable TT2-based generator of Gravatar URLs straight from email addresses. β¨
πΈ SYNOPSIS πΈ
[% USE Gravatar %]
[% FOR user IN user_list %]
<img src="[% Gravatar( email => user.email ) | html %]"
alt="[% user.name | html %]" />
[% END %]
# OR a mini CGI example
use strict;
use CGI qw( header start_html end_html );
use Template;
my %config = ( # ... your other config stuff
GRAVATAR => { default => "http://myhost.moo/local/image.png",
size => 80,
rating => "R" },
);
# note the "default" must be an absolute URI to work correctly
my $tt2 = Template->new(\%config);
my $user = { email => 'whatever@wherever.whichever',
rating => "PG",
name => "Manamana",
size => 75 };
print header(), start_html();
$tt2->process(\*DATA, { user => $user })
or warn $Template::ERROR;
print end_html();
__DATA__
[% USE Gravatar %]
[% FILTER html %]
<img src="[% Gravatar( user ) | html %]"
alt="[% user.name | html %]" />
[% END %]
π¦ DESCRIPTION π¦
okay so if you wanna know more about the service interface itself, go peek at <http://gravatar.com/site/implement/url>, and if you just want the tea on what Gravatars even are (spoiler: globally recognized avatars π«Ά), that's <http://gravatar.com/>.
Every single option Gravatars support β default, rating, and size β is usable right here. The gravatar_id gets generated from whatever email you hand over. it's giving automatic. it's giving effortless. π
β¨ INTERFACE/SETTINGS β¨
π new π
Not something you call directly, bestie β this fires off when you USE the plugin. It scoops up defaults from the template config hash and mixes them together with any per-template defaults. Like so:
[% USE Gravatar %]
Use config arguments if any.
[% USE Gravatar(default => 'http://mysite.moo/local/default-image.gif') %]
Mix config arguments, if any, with new instance arguments.
π Arguments π
email(required) β the whole key to using Gravatars is a hex hash of the user's email. This one gets generated automatically and shipped off to gravatar.com as thegravatar_id.default(optional) β the local image (any valid absolute image URI, no cap) to fall back on when there's no Gravatar matching the given email.size(optional) β Gravatars are square, periodt. Size goes from 1 through 80 (pixels) and sets both the width and the height.rating(optional) βG|PG|R|X. This is the maximum rating of Gravatar you want returned. Running a family friendly forum? You might set it to"G."border(DEPRECATED) β a hex color, e.g.FF00FForF0F. Gravatar doesn't do anything with these anymore so we don't even pass them along. If you include it anyway, you will get a warning. πbase(developer override) β this one exists purely as a courtesy for the one or two developers who might actually need it. More below. πgravatar_id(not allowed) β this isn't an option, it's a generated variable. It's an MD5 hex hash of the email address. The reason it's not supported as an optional variable is that it would allow avatar hijacking. so no. π«
The only argument that must be given when you call the Gravatar plugin is the email. Everything else β rating, default image, border, and size β can be set in three different places: the config, the USE call, or the Gravatar call. All three of the following produce the same Gravatar URL. iconic. π
π Settings via config π
Used if the entire site should rely on one set of defaults.
use Template;
my %config = (
GRAVATAR => {
default => "http://mysite.moo/img/avatar.png",
rating => "PG",
size => 80,
}
);
my $template = <<;
[% USE Gravatar %]
[% Gravatar(email => 'me@myself.ego') | html %]
my $tt2 = Template->new(\%config);
$tt2->process(\$template);
π Settings via instance π
Used if a particular template needs its own defaults.
use Template;
my $template = <<;
[% USE Gravatar( rating => "PG",
size => 80 ) %]
[% Gravatar(email => 'me@myself.ego') | html %]
my $tt2 = Template->new();
$tt2->process(\$template);
Any other calls with different emails will share the defaults in this template. β¨
π§ Settings in the Gravatar call π§
Used for per URL control.
use Template;
my $template = <<;
[% USE Gravatar %]
[% Gravatar(email => 'me@myself.ego',
default => "http://mysite.moo/img/avatar.png",
rating => "PG",
size => 80 ) | html %]
my $tt2 = Template->new();
$tt2->process(\$template);
π Base URL (for developers only) π
You may also override the base URL for retrieving the Gravatars. It's set to use the service from <https://gravatar.com/>. It can be overridden in the config or the USE. that's it, that's the whole flex. π
π DIAGNOSTICS π
Email is the only required argument. Croaks without it. no email, no avatar, no mercy.
Rating and size are also validated on each call. Croaks if an invalid size (like 0 or 100) or rating (like MA or NC-17). π
π Configuration AND ENVIRONMENT π
No configuration is necessary, bestie. You may use the configuration hash of your new template to pass default information β like the default image location for those without Gravatars. You can also set it in the USE call per template if needed. your call, your rules. π«Ά
π« Dependencies (see also) π«
Template, Template::Plugin, Carp, Digest::MD5, and URI::Escape.
π¦ Bugs and Limitations π¦
None known. I certainly appreciate bug reports and feedback via <https://github.com/pangyre/p5-template-plugin-gravatar/issues>. slide into the issues, fr fr. ππ
π Author π
Ashley Pond V, <ashley@cpan.org>.
π License π
Copyright 2007-2016, Ashley Pond V.
This program is free software; you can redistribute it and modify it under the same terms as Perl itself.
See <http://dev.perl.org/licenses/artistic.html>.
π See Also π
Gravatar::URLβ standalone Gravatar URL generation.- <http://gravatar.com> β The Gravatar web site.
- <http://gravatar.com/site/implement/> β The Gravatar URL implementation guide.
and that's the whole page, bestie!! this was written for perl v5.34.0, dated 2022-06-17, and it's part of the User Contributed Perl Documentation for Template::Plugin::Gravatar. go forth and generate avatars. slay. π
β¨π¦
π¦ where this page comes from
- debian bookworm: libtemplate-plugin-gravatar-perl 0.10-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libtemplate-plugin-gravatar-perl 0.10-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libtemplate-plugin-gravatar-perl 0.10-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libtemplate-plugin-gravatar-perl 0.10-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libtemplate-plugin-gravatar-perl 0.10-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms