This file is indexed.

/usr/share/perl5/Template/Plugin/Gravatar.pm is in libtemplate-plugin-gravatar-perl 0.05-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
288
289
290
291
292
293
294
295
296
297
298
299
300
package Template::Plugin::Gravatar;
use base "Template::Plugin";

our $VERSION = "0.05";

use strict;
use Carp;
use Digest::MD5 ();
use URI::Escape ();

my $Gravatar_Base = "http://www.gravatar.com/avatar.php";

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} <= 80
                or croak "Gravatar size must be 1 .. 80";
        }
        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} ) {
            $args->{border} =~ /\A[0-9A-F]{3}(?:[0-9A-F]{3})?\Z/
                or croak "Border must be a 3 or 6 digit hex number in caps";
        }
        
        $args->{gravatar_id} = Digest::MD5::md5_hex( $args->{email} );

        $args->{default} = URI::Escape::uri_escape($args->{default})
            if $args->{default};

        my @pairs;
        for my $key ( qw( gravatar_id rating size default border ) ) {
            next unless $args->{$key};
            push @pairs, join("=", $key, $args->{$key});
        }

        my $uri = join("?",
                       $args->{base},
                       join("&",
                            @pairs
                            )
                       );

        return $uri;
    }
}

1;

__END__

=head1 NAME

Template::Plugin::Gravatar - configurable TT2-based generation of Gravatar URLs from email addresses.

=head1 VERSION

0.05

=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://site.gravatar.com/site/implement> for more on the
service interface and L<http://site.gravatar.com/> for information
about Gravatars (globally recognized avatars) in general.

All of the options supported in Gravatars--default, rating, size, and
border--can be used here. The 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.,

  [% 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 (optional)

A hex color, e.g. FF00FF or F0F.

=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 else -- rating, default image, border,
and size -- 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 www.gravatar.com. It can be overridden in
the config or the C<USE>.

=head1 DIAGNOSTICS

Email is the only required argument. Croaks without it.

Size, border, and rating are also validated on each call. Croaks if an
invalid size (like 0 or 100) or rating (like MA or NC-17) or border
(like ff0 or FF) is given.

=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>.

http://www.gravatar.com/

=head1 BUGS AND LIMITATIONS

None known. I certainly appreciate bug reports and feedback via
C<bug-template-plugin-gravatar@rt.cpan.org>, or through the web
interface at L<http://rt.cpan.org/>.

=head1 AUTHOR

Ashley Pond V  C<< <ashley@cpan.org> >>.

=head1 LICENSE

Copyright 2007, Ashley Pond V.

This program is free software; you can redistribute it and modify it
under the same terms as Perl itself.

See F<http://www.perl.com/perl/misc/Artistic.html>.

=head1 SEE ALSO

L<Gravatar::URL> - standalone Gravatar URL generation.

L<http://www.gravatar.com> - The Gravatar web site.

L<http://site.gravatar.com/site/implement> - The Gravatar URL implementation guide.

=cut