Plagger/Plugin/Subscription/Planet.pm untested

filter: Statementstmt 0.0% 0 / 33 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 44 CC 2 SCAR 12.0
CC
2
Cov
0%
load
6.0
BEGIN
2.0
BEGIN
2.0
CRAP 3.3
1 package Plagger::Plugin::Subscription::Planet;
2 use strict;
3 use base qw( Plagger::Plugin::Subscription::Config );
4  
5 use Encode;
6 use URI::Escape;
7  
8 sub load {
9 my($self, $context) = @_;
10  
11 my $lang = $self->conf->{lang} || 'default';
12 $lang = [ $lang ] unless ref $lang;
13  
14 $self->load_assets(
15 File::Find::Rule->file->name([ map "$_.yaml", @$lang ]),
16 sub {
17 my($file) = @_;
18 my $data = YAML::LoadFile($file);
19 push @{ $self->{engines} }, @{ $data->{engines} };
20 },
21 );
22  
23 for my $site (@{ $self->{engines} }) {
24 my $site_url = $site; # copy
25  
26 # use eval ... die to skip if there's no url/keyword
27 eval {
28 $site_url =~ s{{([\w\-\:]+)}}{
29 my($key, $encoding) = split /:/, $1;
30  
31 my $data = $self->conf->{$key} or die "$key is not there";
32 if ($encoding && $encoding ne 'utf-8') {
33 $data = Encode::encode($encoding, $data);
34 } else {
35 $data = Encode::encode_utf8($data);
36 }
37  
38 my $chunk = URI::Escape::uri_escape($data);
39 $chunk =~ s/%20/+/g; # hack
40 $chunk;
41 }eg;
42 push @{$self->conf->{feed}}, { url => $site_url }
43 };
44 }
45  
46 $self->SUPER::load($context);
47 }
48  
49 1;
50  
51 __END__