« lib/Strehler/Element/RSS/RSSChannel.pm
↑ Summary
blib/lib/Strehler/Schema/RSS/Result/Rsschannel.pm »
| 1 | package Strehler::RSS; | ||||||||||||||||||||||||||||
| 2 | 1 | $Strehler::RSS::VERSION = '1.1.2'; | |||||||||||||||||||||||||||
| 3 | # ABSTRACT: RSS management using Strehler | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Dancer2 0.160000; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Strehler::Element::RSS::RSSChannel; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Strehler::Helpers; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use XML::Feed; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use XML::Feed::Entry; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 1 | prefix '/rss'; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | get '/:lang/:slug' => sub | ||||||||||||||||||||||||||||
| 15 | 2 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=19.7
| |||||||||||||||||||||||||||||
| 16 | 2 | my $language = params->{lang}; | |||||||||||||||||||||||||||
| 17 | 2 | my $slug = params->{slug}; | |||||||||||||||||||||||||||
| 18 | 2 | $slug =~ s/\.xml$//; | |||||||||||||||||||||||||||
| 19 | 2 | my $rss = Strehler::Element::RSS::RSSChannel->get_by_slug($slug, $language); | |||||||||||||||||||||||||||
| 20 | 2 | my %rss_data = $rss->get_ext_data(); | |||||||||||||||||||||||||||
| 21 | 2 | my $entity = Strehler::Helpers::class_from_entity($rss_data{'entity_type'}); | |||||||||||||||||||||||||||
| 22 | 2 | my $query; | |||||||||||||||||||||||||||
| 23 | 2 | $query->{'order'} = 'desc'; | |||||||||||||||||||||||||||
| 24 | 2 | $query->{'order_by'} = $rss->get_attr("order_by"); | |||||||||||||||||||||||||||
| 25 | 2 | ▶ | $query->{'entries_per_page'} = config->{Strehler}->{RSS}->{entries} || 6; | ||||||||||||||||||||||||||
|
Condition50%1/2
config()->{'Strehler'}{'RSS'}{'entries'} || 6
MC/DC0%0/1
config()->{'Strehler'}{'RSS'}{'entries'} || 6
config()->{'Strehler'}{'RSS'}{'entries'}
Truth table50%1/2
A
A= config()->{'Strehler'}{'RSS'}{'entries'}
| |||||||||||||||||||||||||||||
| 26 | 2 | $query->{'language'} = $language; | |||||||||||||||||||||||||||
| 27 | 2 | $query->{'published'} = 1; | |||||||||||||||||||||||||||
| 28 | 2 | $query->{'ext'} = 1; | |||||||||||||||||||||||||||
| 29 | 2 | ▶ | if($rss->get_attr("deep") && $rss->get_attr("deep") == 1) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$rss->get_attr("deep") and $rss->get_attr("deep") == 1
MC/DC50%1/2
$rss->get_attr("deep") and $rss->get_attr("deep") == 1
$rss->get_attr("deep")
$rss->get_attr("deep") == 1
Truth table66%2/3
A and B
A= $rss->get_attr("deep")B= $rss->get_attr("deep") == 1
| |||||||||||||||||||||||||||||
| 30 | { | ||||||||||||||||||||||||||||
| 31 | 1 | $query->{'ancestor'} = $rss->get_attr("category", 1); | |||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | else | ||||||||||||||||||||||||||||
| 34 | { | ||||||||||||||||||||||||||||
| 35 | 1 | $query->{'category'} = $rss->get_attr("category"); | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | 2 | my $elements = $entity->get_list($query); | |||||||||||||||||||||||||||
| 38 | 2 | my $rss_items = []; | |||||||||||||||||||||||||||
| 39 | 2 | my $link_template = $rss->get_attr('link_template'); | |||||||||||||||||||||||||||
| 40 | 2 | my $feed = XML::Feed->new('RSS', version => '2.0'); | |||||||||||||||||||||||||||
| 41 | 0 | $feed->title($rss->get_attr_multilang('title', $language)); | |||||||||||||||||||||||||||
| 42 | 0 | $feed->description($rss->get_attr_multilang('description', $language)); | |||||||||||||||||||||||||||
| 43 | 0 | $feed->link($rss->get_attr('link')); | |||||||||||||||||||||||||||
| 44 | 0 | $feed->language($language); | |||||||||||||||||||||||||||
| 45 | 0 | $feed->generator("Strehler::RSS " . $Strehler::RSS::VERSION); | |||||||||||||||||||||||||||
| 46 | 0 | foreach my $e (@{$elements->{'to_view'}}) | |||||||||||||||||||||||||||
| 47 | { | ||||||||||||||||||||||||||||
| 48 | 0 | my $item = XML::Feed::Entry->new('RSS', version => '2.0'); | |||||||||||||||||||||||||||
| 49 | 0 | $item->title($e->{$rss->get_attr('title_field')}); | |||||||||||||||||||||||||||
| 50 | 0 | $item->content($e->{$rss->get_attr('description_field')}); | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 0 | my $link_value = $e->{$rss->get_attr('link_field')}; | |||||||||||||||||||||||||||
| 53 | 0 | my $link = $link_template; | |||||||||||||||||||||||||||
| 54 | 0 | $link =~ s/%%/$link_value/; | |||||||||||||||||||||||||||
| 55 | 0 | $link = $link; | |||||||||||||||||||||||||||
| 56 | 0 | $item->link($link); | |||||||||||||||||||||||||||
| 57 | 0 | $feed->add_entry($item); | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 0 | content_type('application/rss+xml'); | |||||||||||||||||||||||||||
| 62 | 0 | return $feed->as_xml; | |||||||||||||||||||||||||||
| 63 | 1 | }; | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | get '/:slug' => sub | ||||||||||||||||||||||||||||
| 66 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 67 | 0 | forward "/" . dancer_app->prefix . "/" . config->{Strehler}->{default_language} . "/" . params->{slug}; | |||||||||||||||||||||||||||
| 68 | 1 | }; | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | =encoding utf8 | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | =head1 NAME | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | Strehler::RSS - RSS Feed created using Strehler contents | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | Strehler::RSS gives a Strehler site possibility to have automatic RSS feed, based on contents published using Strehler. | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | =head1 INSTALLATION | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | In your Strehler-based site directory, do | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | strehler initentity Strehler::Element::RSS::RSSChannel | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | As said by installation procedure, then do | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | strehler schemadump | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | Add Strehler::RSS module to your app.psgi. | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | Remember to verify also that the module L<Strehler::API> (from Strehler main package) is in your app.psgi because it's used by backend form. | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | =head1 CONFIGURATION | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | There's only a configuration key available that you can manage from your config.yml. | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | Strehler: | ||||||||||||||||||||||||||||
| 99 | RSS: | ||||||||||||||||||||||||||||
| 100 | entries: 10 | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | Default value is 6, it means that, when the RSS feed is generated, latest six contents are retrieved and used as items. You can change it as you like. Using -1 will make Strehler::RSS to use all the configured contents in the feed. | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | =head1 USE | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | Look at the documentation of L<Strehler::Element::RSS::RSSChannel> to see how to configure an RSS Channel and how to retrieve link to it. Put the link on your site to make RSS available to your users. | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | =cut | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 1 | 1; | |||||||||||||||||||||||||||