| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
=head1 NAME |
|
3
|
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
Templer::Plugin::RSS - A plugin to include RSS feeds in pages. |
|
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
|
|
|
|
|
|
|
feed: rss(4, http://blog.steve.org.uk/index.rss ) |
|
14
|
|
|
|
|
|
|
---- |
|
15
|
|
|
|
|
|
|
<p>This is my page content.</p> |
|
16
|
|
|
|
|
|
|
<ul> |
|
17
|
|
|
|
|
|
|
<!-- tmpl_loop name='feed' --> |
|
18
|
|
|
|
|
|
|
<li><a href="<!-- tmpl_var name='link' -->"><!-- tmpl_var name='title' --></a></li> |
|
19
|
|
|
|
|
|
|
<!-- /tmpl_loop --> |
|
20
|
|
|
|
|
|
|
</ul> |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
Here the variable 'feed' will contain the first four elements of the |
|
24
|
|
|
|
|
|
|
RSS feed my blog produces. |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
The feed entries will contain the following three attributes |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=over 8 |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=item author |
|
31
|
|
|
|
|
|
|
The author of the post. |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=item link |
|
34
|
|
|
|
|
|
|
The link to the post. |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=item title |
|
37
|
|
|
|
|
|
|
The title of the popst |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=back |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=cut |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
This plugin uses L<XML::Feed> to extract remote RSS feeds and allow |
|
46
|
|
|
|
|
|
|
them to be included in your site bodies - if that module is not |
|
47
|
|
|
|
|
|
|
available then the plugin will disable itself. |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=cut |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 LICENSE |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
This module is free software; you can redistribute it and/or modify it |
|
54
|
|
|
|
|
|
|
under the terms of either: |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
a) the GNU General Public License as published by the Free Software |
|
57
|
|
|
|
|
|
|
Foundation; either version 2, or (at your option) any later version, |
|
58
|
|
|
|
|
|
|
or |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
b) the Perl "Artistic License". |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=cut |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head1 AUTHOR |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
Steve Kemp <steve@steve.org.uk> |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=cut |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
Copyright (C) 2015 Steve Kemp <steve@steve.org.uk>. |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
This library is free software. You can modify and or distribute it under |
|
75
|
|
|
|
|
|
|
the same terms as Perl itself. |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=cut |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 METHODS |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=cut |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
|
|
84
|
12
|
|
|
12
|
|
7135
|
use strict; |
|
|
11
|
|
|
|
|
12
|
|
|
|
11
|
|
|
|
|
239
|
|
|
85
|
11
|
|
|
11
|
|
29
|
use warnings; |
|
|
11
|
|
|
|
|
10
|
|
|
|
11
|
|
|
|
|
3036
|
|
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
package Templer::Plugin::RSS; |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head2 new |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Constructor. No arguments are required/supported. |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=cut |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub new |
|
98
|
|
|
|
|
|
|
{ |
|
99
|
11
|
|
|
11
|
1
|
18
|
my ( $proto, %supplied ) = (@_); |
|
100
|
11
|
|
33
|
|
|
68
|
my $class = ref($proto) || $proto; |
|
101
|
|
|
|
|
|
|
|
|
102
|
11
|
|
|
|
|
17
|
my $self = {}; |
|
103
|
11
|
|
|
|
|
15
|
bless( $self, $class ); |
|
104
|
11
|
|
|
|
|
78
|
return $self; |
|
105
|
|
|
|
|
|
|
} |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head2 expand_variables |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
This is the method which is called by the L<Templer::Plugin::Factory> |
|
112
|
|
|
|
|
|
|
to expand the variables contained in a L<Templer::Site::Page> object. |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
This method will expand any variable that has a defintion of the |
|
115
|
|
|
|
|
|
|
form "rss( NN, http... )" and replace the variable definition |
|
116
|
|
|
|
|
|
|
with the result of fetching that RSS feed. |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=cut |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub expand_variables |
|
121
|
|
|
|
|
|
|
{ |
|
122
|
9
|
|
|
9
|
1
|
15
|
my ( $self, $site, $page, $data ) = (@_); |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
|
|
128
|
9
|
|
|
|
|
37
|
my %hash = %$data; |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
|
|
134
|
9
|
|
|
|
|
15
|
my $module = "use XML::Feed"; |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
|
|
137
|
8
|
|
|
8
|
|
1324
|
eval($module); |
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
|
9
|
|
|
|
|
417
|
|
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
|
|
143
|
9
|
50
|
|
|
|
52
|
return ( \%hash ) if ($@); |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
|
|
148
|
0
|
|
|
|
|
|
foreach my $key ( keys %hash ) |
|
149
|
|
|
|
|
|
|
{ |
|
150
|
0
|
0
|
|
|
|
|
if ( $hash{ $key } =~ /^rss\(\s?([0-9]+)\s?,\s?(https?:\/\/.*)\s?\)/ ) |
|
151
|
|
|
|
|
|
|
{ |
|
152
|
0
|
|
|
|
|
|
my $count = $1; |
|
153
|
0
|
|
|
|
|
|
my $link = $2; |
|
154
|
|
|
|
|
|
|
|
|
155
|
0
|
|
|
|
|
|
$link =~ s/^\s+|\s+$//g; |
|
156
|
0
|
|
|
|
|
|
$count =~ s/^\s+|\s+$//g; |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
|
|
159
|
0
|
|
|
|
|
|
delete( $hash{ $key } ); |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
|
|
162
|
0
|
|
|
|
|
|
my $feed = XML::Feed->parse( URI->new($link) ); |
|
163
|
|
|
|
|
|
|
|
|
164
|
0
|
0
|
|
|
|
|
if ($feed) |
|
165
|
|
|
|
|
|
|
{ |
|
166
|
0
|
|
|
|
|
|
my $tmp; |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
|
|
169
|
0
|
|
|
|
|
|
for my $entry ( $feed->entries ) |
|
170
|
|
|
|
|
|
|
{ |
|
171
|
0
|
0
|
|
|
|
|
if ( $count > 0 ) |
|
172
|
|
|
|
|
|
|
{ |
|
173
|
0
|
|
|
|
|
|
push( @$tmp, |
|
174
|
|
|
|
|
|
|
{ link => $entry->link, |
|
175
|
|
|
|
|
|
|
author => $entry->author, |
|
176
|
|
|
|
|
|
|
title => $entry->title |
|
177
|
|
|
|
|
|
|
} ); |
|
178
|
|
|
|
|
|
|
} |
|
179
|
0
|
|
|
|
|
|
$count = $count - 1; |
|
180
|
|
|
|
|
|
|
} |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
|
|
183
|
0
|
|
|
|
|
|
$hash{ $key } = $tmp; |
|
184
|
|
|
|
|
|
|
} |
|
185
|
|
|
|
|
|
|
else |
|
186
|
|
|
|
|
|
|
{ |
|
187
|
0
|
|
|
|
|
|
print "WARNING: Failed to fetch $link\n"; |
|
188
|
|
|
|
|
|
|
} |
|
189
|
|
|
|
|
|
|
} |
|
190
|
|
|
|
|
|
|
} |
|
191
|
|
|
|
|
|
|
|
|
192
|
0
|
|
|
|
|
|
return ( \%hash ); |
|
193
|
|
|
|
|
|
|
} |
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
Templer::Plugin::Factory->new()->register_plugin("Templer::Plugin::RSS"); |
|
200
|
|
|
|
|
|
|
|