line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Template::Plugin::Gravatar; |
2
|
4
|
|
|
4
|
|
150592
|
use warnings; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
130
|
|
3
|
4
|
|
|
4
|
|
19
|
use strict; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
125
|
|
4
|
4
|
|
|
4
|
|
15
|
use base "Template::Plugin"; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
1986
|
|
5
|
4
|
|
|
4
|
|
6645
|
use Carp qw( carp croak ); |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
271
|
|
6
|
4
|
|
|
4
|
|
2167
|
use URI (); |
|
4
|
|
|
|
|
16046
|
|
|
4
|
|
|
|
|
80
|
|
7
|
4
|
|
|
4
|
|
27
|
use Digest::MD5 (); |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
1431
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = "0.08"; |
10
|
|
|
|
|
|
|
our $AUTHORITY = "cpan:ASHLEY"; |
11
|
|
|
|
|
|
|
our $Gravatar_Base = "http://www.gravatar.com/avatar/"; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
14
|
17
|
|
|
17
|
1
|
38058
|
my ( $class, $context, $instance_args ) = @_; |
15
|
17
|
|
100
|
|
|
70
|
$instance_args ||= {}; # the USE'd object. |
16
|
17
|
|
100
|
|
|
78
|
my $config = $context->{CONFIG}{GRAVATAR} || {}; # from TT config. |
17
|
17
|
|
|
|
|
20
|
my %args; |
18
|
|
|
|
|
|
|
|
19
|
17
|
|
100
|
|
|
110
|
$args{default} = $instance_args->{default} || $config->{default}; |
20
|
17
|
|
100
|
|
|
61
|
$args{rating} = $instance_args->{rating} || $config->{rating}; |
21
|
17
|
|
66
|
|
|
61
|
$args{border} = $instance_args->{border} || $config->{border}; |
22
|
17
|
|
100
|
|
|
58
|
$args{size} = $instance_args->{size} || $config->{size}; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# Overriding the base might be nice for some developers. |
25
|
17
|
|
66
|
|
|
75
|
$args{base} = $instance_args->{base} || $config->{base} || |
26
|
|
|
|
|
|
|
$Gravatar_Base; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
return sub { |
29
|
14
|
|
100
|
14
|
|
479
|
my $args = shift || {}; |
30
|
14
|
|
|
|
|
41
|
$args = { |
31
|
|
|
|
|
|
|
%args, |
32
|
14
|
|
|
|
|
33
|
%{$args} |
33
|
|
|
|
|
|
|
}; |
34
|
14
|
100
|
|
|
|
206
|
$args->{email} || croak "Cannot generate a Gravatar URI without an email address"; |
35
|
13
|
100
|
|
|
|
28
|
if ( $args->{size} ) { |
36
|
9
|
100
|
66
|
|
|
163
|
$args->{size} >= 1 and $args->{size} <= 2048 |
37
|
|
|
|
|
|
|
or croak "Gravatar size must be 1 .. 2048"; |
38
|
|
|
|
|
|
|
} |
39
|
12
|
100
|
|
|
|
22
|
if ( $args->{rating} ) { |
40
|
10
|
100
|
|
|
|
186
|
$args->{rating} =~ /\A(?:G|PG|R|X)\z/ |
41
|
|
|
|
|
|
|
or croak "Gravatar rating can only be G, PG, R, or X"; |
42
|
|
|
|
|
|
|
} |
43
|
11
|
100
|
|
|
|
22
|
if ( $args->{border} ) { |
44
|
2
|
|
|
|
|
404
|
carp "Border is deprecated! Dropping it."; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
11
|
|
|
|
|
235
|
$args->{gravatar_id} = Digest::MD5::md5_hex($args->{email}); |
48
|
|
|
|
|
|
|
|
49
|
11
|
|
33
|
|
|
57
|
my $uri = URI->new( $args->{base} || $Gravatar_Base ); |
50
|
11
|
|
|
|
|
15327
|
my @ordered = map { $_, $args->{$_} } |
|
38
|
|
|
|
|
75
|
|
51
|
|
|
|
|
|
|
grep $args->{$_}, |
52
|
|
|
|
|
|
|
qw( gravatar_id rating size default ); |
53
|
11
|
|
|
|
|
52
|
$uri->query_form(@ordered); |
54
|
11
|
|
|
|
|
1294
|
return $uri; |
55
|
|
|
|
|
|
|
} |
56
|
17
|
|
|
|
|
96
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
1; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
__END__ |