HiD/Generator/RSSFeed.pm

filter: Statementstmt 38.6% 22 / 57 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 66.6% 6 / 9 Podpod 100% 1 / 1 totaltotal 34.1% 29 / 85 CC 9 SCAR 26.8
CC
9
Cov
31%
generate
30.0
_new_feed
20.0
_new_entry
6.0
CRAP 14.6
« HiD/App/Command/server.pm ↑ Summary HiD/Server/Loader.pm »
1 # ABSTRACT: RSS feed generator
2  
3  
4 package HiD::Generator::RSSFeed;
5 1 our $AUTHORITY = 'cpan:GENEHACK';
6 1 $HiD::Generator::RSSFeed::VERSION = '1.96';
7 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 with 'HiD::Generator';
9  
10 1 ▶use 5.014; # strict, unicode_strings
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 ▶use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use XML::Feed;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use XML::Feed::Entry;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 1 ▶use HiD::VirtualPage;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18  
19 sub generate {
20 0 ▶ my( $self , $site ) = @_;
Subroutine generate: not called CC=5 SCAR=34.0
Pod documented
21  
22 0 ▶ return unless $site->config->{rss_feed}{generate};
Branch: 1 branch
BranchTrueFalseTotal
unless $site->config->{"rss_feed"}{"generate"} 0 0 0
23  
24 0 my $destination = $site->config->{rss_feed}{destination};
25 0 ▶ my $post_limit = $site->config->{rss_feed}{posts} // 20;
Condition0%0/2
$site->config->{"rss_feed"}{"posts"} // 20
l!l
00
MC/DC0%0/1
$site->config->{"rss_feed"}{"posts"} // 20
$site->config->{"rss_feed"}{"posts"}
Truth table0%0/2
A
A= $site->config->{"rss_feed"}{"posts"}
Aresult
11
00
26 0 my $post_count = 1;
27  
28 0 my $feed = $self->_new_feed($site);
29  
30 0 POST: for my $post( @{ $site->posts }) {
31 0 $feed->add_entry($self->_new_entry($post));
32  
33 0 $post_count++;
34 0 ▶ last POST if $post_count > $post_limit;
Branch: 1 branch
BranchTrueFalseTotal
if $post_count > $post_limit 0 0 0
35 }
36  
37 0 my $feed_page = HiD::VirtualPage->new({
38 output_filename => $site->destination . $destination ,
39 content => $feed->as_xml ,
40 });
41  
42 0 $site->add_input( "RSS FEED" => 'page' );
43 0 $site->add_object( $feed_page );
44  
45 0 $site->INFO( "* Injected RSS feed");
46 }
47  
48 sub _new_entry {
49 0 ▶ my( $self , $post ) = @_;
Subroutine _new_entry: not called CC=2 SCAR=17.9
50  
51 0 my $entry = XML::Feed::Entry->new('RSS');
52 0 $entry->title($post->title);
53 0 $entry->author($post->author);
54 0 $entry->link($post->baseurl . $post->url);
55 0 $entry->id($post->get_config('baseurl') . $post->url);
56 0 $entry->issued($post->date);
57 0 ▶ $entry->summary($post->description) if $post->description;
Branch: 1 branch
BranchTrueFalseTotal
if $post->description 0 0 0
58 0 $entry->content($post->converted_content);
59  
60 0 return $entry;
61 }
62  
63 sub _new_feed {
64 0 ▶ my( $self , $site ) = @_;
Subroutine _new_feed: not called CC=4 SCAR=30.0
65  
66 0 my $feed = XML::Feed->new('RSS');
67 0 ▶ my $title = $site->config->{rss_feed}{title} // $site->config->{title};
Condition0%0/3
$site->config->{"rss_feed"}{"title"} // $site->config->{"title"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$site->config->{"rss_feed"}{"title"} // $site->config->{"title"}
$site->config->{"rss_feed"}{"title"} $site->config->{"title"}
Truth table0%0/3
A // B
A= $site->config->{"rss_feed"}{"title"}B= $site->config->{"title"}
ABresult
1X1
011
000
68 0 $feed->title( $title );
69  
70 $feed->base( $site->config->{rss_feed}{base} )
71 0 ▶ if $site->config->{rss_feed}{base};
Branch: 1 branch
BranchTrueFalseTotal
if $site->config->{"rss_feed"}{"base"} 0 0 0
72  
73 0 ▶ if( $site->config->{rss_feed}{link}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($site->config->{"rss_feed"}{"link"}) 0 0 0
74 0 $feed->link( $site->config->{rss_feed}{link} );
75 0 $feed->id( $site->config->{rss_feed}{link} );
76 }
77  
78 0 $feed->modified(DateTime->now());
79  
80 0 return $feed;
81 }
82  
83 1 __PACKAGE__->meta->make_immutable;
84 1 1;
85  
86 __END__
87  
88 =pod
89  
90 =encoding UTF-8
91  
92 =head1 NAME
93  
94 HiD::Generator::RSSFeed - RSS feed generator
95  
96 =head1 DESCRIPTION
97  
98 This Generator produces an RSS feed of your posts.
99  
100 Enable it by setting the 'rss_feed.generate' key in your config to 1. Also
101 set an 'rss_feed.destination' key indicating where the feed should be
102 generated.
103  
104 You may also set optional 'rss_feed.base' and 'rss_feed.link' keys to set
105 the 'rel=alternate' base link and the 'rel=self' link to the RSS feed,
106 respectively.
107  
108 The 'rss_feed.title' config key can be used to give the feed a
109 title. Otherwise the site title will be used.
110  
111 The 'rss_feed.posts' config key can be used to control the number of posts in
112 the feed. It defaults to 20.
113  
114 =head1 METHODS
115  
116 =head2 generate
117  
118 =head1 VERSION
119  
120 version 1.96
121  
122 =head1 AUTHOR
123  
124 John SJ Anderson <genehack@genehack.org>
125  
126 =head1 COPYRIGHT AND LICENSE
127  
128 This software is copyright (c) 2015 by John SJ Anderson.
129  
130 This is free software; you can redistribute it and/or modify it under
131 the same terms as the Perl 5 programming language system itself.
132  
133 =cut
« HiD/App/Command/server.pm ↑ Summary HiD/Server/Loader.pm »