/usr/share/perl5/Template/Plugin/Gravatar.pm is in libtemplate-plugin-gravatar-perl 0.10-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 | package Template::Plugin::Gravatar;
use warnings;
use strict;
use base "Template::Plugin";
use Carp qw( carp croak );
use URI ();
use Digest::MD5 ();
our $VERSION = "0.10";
our $AUTHORITY = "cpan:ASHLEY";
our $Gravatar_Base = "https://gravatar.com/avatar/";
sub new {
my ( $class, $context, $instance_args ) = @_;
$instance_args ||= {}; # the USE'd object.
my $config = $context->{CONFIG}{GRAVATAR} || {}; # from TT config.
my %args;
$args{default} = $instance_args->{default} || $config->{default};
$args{rating} = $instance_args->{rating} || $config->{rating};
$args{border} = $instance_args->{border} || $config->{border};
$args{size} = $instance_args->{size} || $config->{size};
# Overriding the base might be nice for some developers.
$args{base} = $instance_args->{base} || $config->{base} ||
$Gravatar_Base;
return sub {
my $args = shift || {};
$args = {
%args,
%{$args}
};
$args->{email} || croak "Cannot generate a Gravatar URI without an email address";
if ( $args->{size} ) {
$args->{size} >= 1 and $args->{size} <= 2048
or croak "Gravatar size must be 1 .. 2048";
}
if ( $args->{rating} ) {
$args->{rating} =~ /\A(?:G|PG|R|X)\z/
or croak "Gravatar rating can only be G, PG, R, or X";
}
if ( $args->{border} ) {
carp "Border is deprecated! Dropping it.";
}
my $email = $args->{email};
s/\A\s+//, s/\s+\z// for $email;
$email = lc $email; # Might need to consider charset here or document consideration...
$args->{gravatar_id} = Digest::MD5::md5_hex($email);
my $uri = URI->new( $args->{base} || $Gravatar_Base );
my @ordered = map { $_, $args->{$_} }
grep $args->{$_},
qw( gravatar_id rating size default );
$uri->query_form(@ordered);
$uri;
}
}
1;
__END__
=head1 Name
Template::Plugin::Gravatar - Configurable TT2-based generation of Gravatar URLs from email addresses.
=head1 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 %]
=head1 Description
Please see L<http://gravatar.com/site/implement/url> for more on the
service interface and L<http://gravatar.com/> for information
about Gravatars (globally recognized avatars) in general.
All of the options supported in GravatarsE<mdash>default, rating, and
sizeE<mdash>can be used here. The C<gravatar_id> is generated from a given
email.
=head1 Interface/Settings
=head2 new
Not called directly. Called when you C<USE> the plugin. Takes defaults
from the template config hash and mixes them with any per template
defaults. E.g.E<ndash>
[% 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.
=head2 Arguments
=over 4
=item email (required)
The key to using Gravatars is a hex hash of the user's email. This is
generated automatically and sent to gravatar.com as the C<gravatar_id>.
=item default (optional)
The local (any valid absolute image URI) image to use if there is no
Gravatar corresponding to the given email.
=item size (optional)
Gravatars are square. Size is 1 through 80 (pixels) and sets the width
and the height.
=item rating (optional)
G|PG|R|X. The B<maximum> rating of Gravatar you wish returned. If you
have a family friendly forum, for example, you might set it to "G."
=item border (DEPRECATED)
A hex color, e.g. FF00FF or F0F. Gravatar no longer does anything with
these so we don't even pass them along. If included they will give a
warning.
=item base (developer override)
This is provided as a courtesy for the one or two developers who might
need it. More below.
=item gravatar_id (not allowed)
This is B<not> an option but a generated variable. It is an MD5 hex
hash of the email address. The reason is it not supported as an
optional variable is it would allow avatar hijacking.
=back
The only argument that must be given when you call the C<Gravatar>
plugin is the email. Everything elseE<mdash>rating, default image,
border, and sizeE<mdash>can be set in three different places: the
config, the C<USE> call, or the C<Gravatar> call. All three of the
following produce the same Gravatar URL.
=head2 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);
=head2 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.
=head2 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);
=head2 Base URL (for developers only)
You may also override the base URL for retrieving the Gravatars. It's
set to use the service from L<https://gravatar.com/>. It can be
overridden in the config or the C<USE>.
=head1 Diagnostics
Email is the only required argument. Croaks without it.
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).
=head1 Configuration AND ENVIRONMENT
No configuration is necessary. 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 C<USE>
call per template if needed.
=head1 Dependencies (see also)
L<Template>, L<Template::Plugin>, L<Carp>, L<Digest::MD5>, and
L<URI::Escape>.
L<http://gravatar.com/>
=head1 Bugs and Limitations
None known. I certainly appreciate bug reports and feedback via
L<https://github.com/pangyre/p5-template-plugin-gravatar/issues>.
=head1 Author
Ashley Pond V, C<< <ashley@cpan.org> >>.
=head1 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 L<http://dev.perl.org/licenses/artistic.html>.
=head1 See Also
L<Gravatar::URL> - standalone Gravatar URL generation.
L<http://gravatar.com> - The Gravatar web site.
L<http://gravatar.com/site/implement/> - The Gravatar URL implementation guide.
=cut
|