Plagger/Plugin/CustomFeed/Debug.pm untested

filter: Statementstmt 0.0% 0 / 42 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 13 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 79 CC 5 SCAR 27.7
CC
5
Cov
0%
aggregate
30.0
register
2.0
load
2.0
CRAP 16.0
1 package Plagger::Plugin::CustomFeed::Debug;
2 use strict;
3 use warnings;
4 use base qw (Plagger::Plugin);
5  
6 our $VERSION = 0.01;
7  
8 sub register {
9 my ($self, $context) = @_;
10 $context->register_hook(
11 $self,
12 'subscription.load' => \&load,
13 );
14 }
15  
16 sub load {
17 my ($self, $context) = @_;
18 my $feed = Plagger::Feed->new;
19 $feed->aggregator(sub { $self->aggregate(@_) });
20 $context->subscription->add($feed);
21 }
22  
23 sub aggregate {
24 my ($self, $context, $args) = @_;
25  
26 my $feed = $args->{feed};
27 $feed->type('debug');
28 for (keys %{$self->conf}) {
29 next if $_ eq 'entry' || $_ eq 'entries';
30 $feed->$_($self->conf->{$_});
31 }
32  
33 for my $entry_conf (@{ $self->conf->{entry} || $self->conf->{entries} || [] }) {
34 my $entry = Plagger::Entry->new;
35 for my $method (keys %$entry_conf) {
36 next if $method eq 'enclosure';
37 $entry->$method($entry_conf->{$method});
38 }
39 $feed->add_entry($entry);
40  
41 # enclosure
42 my $encls = $entry_conf->{enclosure} || [];
43 $encls = [ $encls ] if ref $encls && ref $encls ne 'ARRAY';
44  
45 for my $enclosure_conf ( @$encls ) {
46 my $enclosure = Plagger::Enclosure->new;
47 $enclosure->$_($enclosure_conf->{$_}) for keys %$enclosure_conf;
48 $enclosure->auto_set_type unless defined $enclosure->type;
49 $entry->add_enclosure($enclosure);
50 }
51 }
52  
53 $context->update->add($feed);
54 }
55  
56 1;
57  
58 __END__