line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
=head1 NAME |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
Templer::Plugin::Redis - A plugin to retrieve values from Redis |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=cut |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 SYNOPSIS |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
The following is a good example use of this plugin |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
title: About my site |
13
|
|
|
|
|
|
|
count: redis_get( "total_count" ) |
14
|
|
|
|
|
|
|
---- |
15
|
|
|
|
|
|
|
<p>There are <!-- tmpl_var name='count' --> ponies.</p> |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=cut |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 DESCRIPTION |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
This plugin allows template variables to be values retrieved from |
22
|
|
|
|
|
|
|
a redis store. |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
It is assumed that redis will be running on the localhost, if it is |
25
|
|
|
|
|
|
|
not you may set the environmental variable C<REDIS_SERVER> to point |
26
|
|
|
|
|
|
|
to your IP:port pair. |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=cut |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head1 LICENSE |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
This module is free software; you can redistribute it and/or modify it |
33
|
|
|
|
|
|
|
under the terms of either: |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
a) the GNU General Public License as published by the Free Software |
36
|
|
|
|
|
|
|
Foundation; either version 2, or (at your option) any later version, |
37
|
|
|
|
|
|
|
or |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
b) the Perl "Artistic License". |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=cut |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 AUTHOR |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
Steve Kemp <steve@steve.org.uk> |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=cut |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
Copyright (C) 2015 Steve Kemp <steve@steve.org.uk>. |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
This library is free software. You can modify and or distribute it under |
54
|
|
|
|
|
|
|
the same terms as Perl itself. |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=cut |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head1 METHODS |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=cut |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
|
63
|
11
|
|
|
11
|
|
3920
|
use strict; |
|
11
|
|
|
|
|
11
|
|
|
11
|
|
|
|
|
233
|
|
64
|
11
|
|
|
11
|
|
30
|
use warnings; |
|
11
|
|
|
|
|
9
|
|
|
11
|
|
|
|
|
2622
|
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
package Templer::Plugin::Redis; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head2 |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
Constructor. No arguments are required/supported. |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=cut |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub new |
77
|
|
|
|
|
|
|
{ |
78
|
11
|
|
|
11
|
0
|
17
|
my ( $proto, %supplied ) = (@_); |
79
|
11
|
|
33
|
|
|
55
|
my $class = ref($proto) || $proto; |
80
|
|
|
|
|
|
|
|
81
|
11
|
|
|
|
|
12
|
my $self = {}; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
|
84
|
11
|
|
|
|
|
13
|
bless( $self, $class ); |
85
|
|
|
|
|
|
|
|
86
|
11
|
|
|
|
|
15
|
my $module = "use Redis;"; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
|
89
|
11
|
|
|
11
|
|
6678
|
eval($module); |
|
11
|
|
|
|
|
294012
|
|
|
11
|
|
|
|
|
159
|
|
|
11
|
|
|
|
|
1047
|
|
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
|
92
|
11
|
50
|
|
|
|
43
|
if ( !$@ ) |
93
|
|
|
|
|
|
|
{ |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
|
103
|
11
|
|
|
|
|
17
|
eval {$self->{ 'redis' } = new Redis()}; |
|
11
|
|
|
|
|
35
|
|
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
11
|
|
|
|
|
6902
|
return $self; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head2 expand_variables |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
This is the method which is called by the L<Templer::Plugin::Factory> |
113
|
|
|
|
|
|
|
to expand the variables contained in a L<Templer::Site::Page> object. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
Variables are written in the file in the form "key: value", and are |
116
|
|
|
|
|
|
|
internally stored within the Page object as a hash. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
This method iterates over each key & value and updates any that |
119
|
|
|
|
|
|
|
seem to refer to redis-fetches. |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=cut |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub expand_variables |
124
|
|
|
|
|
|
|
{ |
125
|
9
|
|
|
9
|
1
|
17
|
my ( $self, $site, $page, $data ) = (@_); |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
|
130
|
9
|
|
|
|
|
38
|
my %hash = %$data; |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
|
135
|
9
|
|
|
|
|
28
|
foreach my $key ( keys %hash ) |
136
|
|
|
|
|
|
|
{ |
137
|
66
|
50
|
|
|
|
124
|
if ( $hash{ $key } =~ /^redis_get\((.*)\)/ ) |
138
|
|
|
|
|
|
|
{ |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
|
143
|
0
|
|
|
|
|
0
|
my $rkey = $1; |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
|
148
|
0
|
|
|
|
|
0
|
$rkey =~ s/^\s+|\s+$//g; |
149
|
0
|
|
|
|
|
0
|
$rkey =~ s/^["']|['"]$//g; |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
|
154
|
0
|
0
|
0
|
|
|
0
|
if ( $self->{ 'redis' } && |
155
|
|
|
|
|
|
|
$self->{ 'redis' }->ping() ) |
156
|
|
|
|
|
|
|
{ |
157
|
0
|
|
|
|
|
0
|
$hash{ $key } = $self->{ 'redis' }->get($rkey); |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
|
166
|
9
|
|
|
|
|
21
|
return ( \%hash ); |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
Templer::Plugin::Factory->new()->register_plugin("Templer::Plugin::Redis"); |
174
|
|
|
|
|
|
|
|