Plagger/Plugin/Subscription/Config.pm untested

filter: Statementstmt 0.0% 0 / 35 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 65 CC 8 SCAR 38.1
CC
8
Cov
0%
load
72.0
register
2.0
BEGIN
2.0
CRAP 45.1
1 package Plagger::Plugin::Subscription::Config;
2 use strict;
3 use base qw( Plagger::Plugin );
4  
5 use Encode;
6 use Plagger::Tag;
7  
8 sub register {
9 my($self, $context) = @_;
10  
11 $context->register_hook(
12 $self,
13 'subscription.load' => $self->can('load'),
14 );
15 }
16  
17 sub load {
18 my($self, $context) = @_;
19  
20 my $feeds = $self->conf->{feed} or return;
21 $feeds = [ $feeds ] unless ref $feeds;
22  
23 for my $config (@$feeds) {
24 if (!ref($config)) {
25 $config = { url => $config };
26 }
27  
28 # file:// URL doesn't work with UTF-8 flag on Win32
29 Encode::_utf8_off($config->{url});
30  
31 my $feed = Plagger::Feed->new;
32 $feed->url($config->{url}) or $context->error("Feed URL is missing");
33 $feed->link($config->{link}) if $config->{link};
34 $feed->title($config->{title}) if $config->{title};
35 $feed->meta($config->{meta}) if $config->{meta};
36  
37 if (my $tags = $config->{tag}) {
38 unless (ref $tags) {
39 $tags = [ Plagger::Tag->parse($config->{tag}) ];
40 }
41 $feed->tags($tags);
42 }
43  
44 $context->subscription->add($feed);
45 }
46 }
47  
48 1;
49  
50 __END__