line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::Libravatar; |
2
|
1
|
|
|
1
|
|
61014
|
use Mojo::Base 'Mojolicious::Plugin'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
9
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
our $VERSION = '1.09'; |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
1203
|
use Libravatar::URL; |
|
1
|
|
|
|
|
5787
|
|
|
1
|
|
|
|
|
71
|
|
7
|
1
|
|
|
1
|
|
25
|
use Mojo::Cache; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
18
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
#use Smart::Comments; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub register { |
12
|
2
|
|
|
2
|
1
|
14939
|
my ( $self, $app, $conf ) = @_; |
13
|
|
|
|
|
|
|
|
14
|
2
|
|
50
|
|
|
11
|
$conf //= {}; |
15
|
2
|
|
50
|
|
|
9
|
$conf->{size} //= 80; |
16
|
2
|
|
50
|
|
|
15
|
$conf->{rating} //= 'PG'; |
17
|
2
|
|
50
|
|
|
12
|
$conf->{cached_email} //= 'user@info.com'; |
18
|
2
|
|
|
|
|
5
|
my $mojo_cache = $conf->{mojo_cache}; |
19
|
2
|
100
|
|
|
|
8
|
delete $conf->{mojo_cache} if defined $mojo_cache; |
20
|
2
|
|
|
|
|
3
|
my $cache; |
21
|
|
|
|
|
|
|
### mojo cache : $mojo_cache |
22
|
2
|
100
|
|
|
|
116
|
$cache = Mojo::Cache->new if $mojo_cache; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
$app->helper( |
25
|
|
|
|
|
|
|
cached_avatar => sub { |
26
|
2
|
|
|
2
|
|
3727
|
my ( $c, $email, %options ) = @_; |
27
|
2
|
|
|
|
|
11
|
my $url = $cache->get($email); |
28
|
2
|
50
|
|
|
|
14
|
return $url if $url; |
29
|
2
|
|
|
|
|
21
|
return $app->libravatar_url( $conf->{cached_email}, %options ); |
30
|
|
|
|
|
|
|
}, |
31
|
2
|
|
|
|
|
40
|
); |
32
|
|
|
|
|
|
|
$app->helper( |
33
|
|
|
|
|
|
|
libravatar_url => sub { |
34
|
6
|
|
|
6
|
|
440880
|
my ( $c, $email, %options ) = @_; |
35
|
|
|
|
|
|
|
### cache : $cache |
36
|
6
|
100
|
|
|
|
29
|
return libravatar_url( email => $email, %{$conf}, %options ) |
|
2
|
|
|
|
|
17
|
|
37
|
|
|
|
|
|
|
if not defined $cache; |
38
|
|
|
|
|
|
|
|
39
|
4
|
|
|
|
|
21
|
my $url = $cache->get($email); |
40
|
4
|
100
|
|
|
|
38
|
if ( not $url ) { |
41
|
2
|
|
|
|
|
18
|
$url = libravatar_url( |
42
|
|
|
|
|
|
|
email => $email, |
43
|
|
|
|
|
|
|
base => 'https://seccdn.libravatar.org/avatar', |
44
|
2
|
|
|
|
|
4
|
%{$conf}, %options |
45
|
|
|
|
|
|
|
); |
46
|
2
|
|
|
|
|
320
|
$cache->set( $email => $url ); |
47
|
|
|
|
|
|
|
} |
48
|
4
|
|
|
|
|
113
|
return $url; |
49
|
|
|
|
|
|
|
}, |
50
|
2
|
|
|
|
|
316
|
); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
"Donuts. Is there anything they can't do?" |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
__END__ |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head1 NAME |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Mojolicious::Plugin::Libravatar - Access the Libravatar API in Mojolicious. |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head1 SYNOPSIS |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# Mojolicious |
65
|
|
|
|
|
|
|
$self->plugin( |
66
|
|
|
|
|
|
|
'Libravatar', |
67
|
|
|
|
|
|
|
{ |
68
|
|
|
|
|
|
|
size => 30, |
69
|
|
|
|
|
|
|
https => 1, |
70
|
|
|
|
|
|
|
mojo_cache => 1, # optional to enable cacheing |
71
|
|
|
|
|
|
|
cached_email => 'abc@xyz.com', # optional "pre-cached" avatar |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
); |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# Mojolicious::Lite |
76
|
|
|
|
|
|
|
plugin 'Libravatar'; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
% my $url = libravatar_url 'user@info.com', size => 80; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 DESCRIPTION |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
L<Mojolicious::Plugin::Libravatar> provides access to the open source |
83
|
|
|
|
|
|
|
Libravatar API L<http://www.libravatar.org>. It utilizes the L<Libravatar::URL> |
84
|
|
|
|
|
|
|
library internally and configuration and options to the helper method |
85
|
|
|
|
|
|
|
L<libravatar_url|Mojolicious::Plugin::Libravatar/libravatar_url> are passed |
86
|
|
|
|
|
|
|
to it directly. |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head1 METHODS |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
L<Mojolicious::Plugin::Libravatar> inherits all methods from |
91
|
|
|
|
|
|
|
L<Mojolicious::Plugin> and implements the following new ones. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head2 C<register> |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
$plugin->register(Mojolicious->new); |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Register plugin in L<Mojolicious> application. |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 CONFIG |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
L<Mojolicious::Plugin::Libravatar> accepts the same options as |
102
|
|
|
|
|
|
|
L<Libravatar::URL>, including C<size>, C<https>, C<base>, and C<short_keys>. |
103
|
|
|
|
|
|
|
In addition, L<Mojolicious::Plugin::Libravatar> accepts the following: |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head2 mojo_cache |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
This is a boolean parameter (0|1) which, when I<true>, tells the plugin to |
108
|
|
|
|
|
|
|
store urls in a cache. For now, this is done with L<Mojo::Cache>. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head2 cached_email |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Default email to use for L<cached_avatar|Mojolicious::Plugin::Libravatar/cached_avatar> helper. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head1 HELPERS |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head2 libravatar_url |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
Given an email, returns a url for the corresponding avatar. Options |
120
|
|
|
|
|
|
|
override configuration. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
# In code |
123
|
|
|
|
|
|
|
my $url = $app->libravatar('email',%options); |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
# Template |
126
|
|
|
|
|
|
|
% my $url = libravatar_url 'user@info.com', size => 80,...; |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head2 cached_avatar |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
If the libravatar url for a specific email has not already been cached, return a |
131
|
|
|
|
|
|
|
I<pre-cached> default. This might be handy if you want to avoid making a lot |
132
|
|
|
|
|
|
|
of queries to libravatar/gravatar servers on a single page load. The default |
133
|
|
|
|
|
|
|
is to use C<user@info.com>, but you can set whatever you like using the |
134
|
|
|
|
|
|
|
L<cached_email|Mojolicious::Plugin::Libravatar/cached_email> parameter above. |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
% my $url = cached_avatar 'xyz@abc.com', https => 1, size => 80 ..; |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head1 SEE ALSO |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
L<Mojolicious>, L<Mojolicious::Guides>, L<http://mojolicio.us>, |
141
|
|
|
|
|
|
|
L<Libravatar::URL>, L<http://www.libravatar.org>. |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head1 SOURCE |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
L<git://github.com/heytrav/mpl.git> |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=cut |