Perlanet/Trait/OPML.pm

filter: Statementstmt 93.6% 44 / 47 Branchbran 66.6% 4 / 6 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 10 / 10 Podpod 100% 2 / 2 totaltotal 90.0% 63 / 70 CC 6 SCAR 7.3
CC
6
Cov
89%
update_opml
4.0
_build_opml_generator
2.1
__ANON__
2.0
CRAP 2.1
« Perlanet/Feed.pm ↑ Summary Perlanet/Trait/FeedFile.pm »
1 package Perlanet::Trait::OPML;
2  
3 11 ▶use 5.10.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 11 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 11 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 11 ▶use POSIX qw(setlocale LC_ALL);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 =head1 NAME
13  
14 Perlanet::Trait::OPML - generate an OPML file
15  
16 =head1 SYNOPSIS
17  
18 my $perlanet = Perlanet->new_with_traits(
19 traits => [ 'Perlanet::Trait::OPML' ]
20 );
21  
22 $perlanet->run;
23  
24 =head1 DESCRIPTION
25  
26 Generates an OPML file of all feeds that are being aggregated by the planet.
27  
28 =head1 ATTRIBUTES
29  
30 =head2 opml_generator
31  
32 An L<XML::OPML::SimpleGen> object to generate the XML for the OPML file
33  
34 =cut
35  
36 11 has 'opml_generator' => (
37 is => 'ro',
38 isa => 'Maybe[XML::OPML::SimpleGen]',
39 builder => '_build_opml_generator',
40 predicate => 'has_opml',
41 required => 1,
42 );
43  
44 11 ▶sub _build_opml_generator {
Subroutine _build_opml_generator: called CC=2 SCAR=7.4
45 11 my $self = shift;
46  
47 11 eval { require XML::OPML::SimpleGen; };
48  
49 11 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 11 11
50 0 warn 'You need to install XML::OPML::SimpleGen to enable OPML ' .
51 "support\n";
52 0 $self->opml_file(undef);
53 0 return;
54 }
55  
56 11 my $loc = setlocale(LC_ALL, 'C');
57 11 my $opml = XML::OPML::SimpleGen->new;
58 11 setlocale(LC_ALL, $loc);
59 11 $opml->head(
60 title => $self->title,
61 );
62  
63 11 return $opml;
64 }
65  
66  
67 =head2 opml_file
68  
69 Where to save the OPML feed when it has been created
70  
71 =cut
72  
73 11 has 'opml_file' => (
74 isa => 'Maybe[Str]',
75 is => 'ro',
76 );
77  
78 =head1 METHODS
79  
80 =head2 update_opml
81  
82 Updates the OPML file of all contributors to this planet. If the L<opml_file>
83 attribute does not have a value, this method does nothing, otherwise it inserts
84 each author into the OPML file and saves it to disk.
85  
86 =cut
87  
88 12 ▶sub update_opml {
Subroutine update_opml: called CC=4 SCAR=13.9
Pod documented
89 12 my $self = shift;
90 12 my ($feeds) = @_;
91  
92 12 foreach my $f (@$feeds) {
93  
94 11 ▶ return unless $self->opml_file and $self->has_opml;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->opml_file and $self->has_opml 9 2 11
Condition66%2/3
$self->opml_file and $self->has_opml
!ll&&!rl&&r
902
MC/DC50%1/2
$self->opml_file and $self->has_opml
$self->opml_file $self->has_opml
Truth table66%2/3
A and B
A= $self->opml_fileB= $self->has_opml
ABresult
0X0
100
111
95  
96 2 $self->opml_generator->insert_outline(
97 title => $f->title,
98 text => $f->title,
99 xmlUrl => $f->feed,
100 htmlUrl => $f->feed,
101 );
102 }
103  
104 3 $self->save_opml;
105 }
106  
107 =head2 save_opml
108  
109 Save the OPML file, by default to disk.
110  
111 =cut
112  
113 4 ▶sub save_opml {
Subroutine save_opml: called CC=1 SCAR=0.0
Pod documented
114 4 my $self = shift;
115 4 $self->opml_generator->save($self->opml_file);
116 }
117  
118 12 ▶around 'fetch_feeds' => sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
119 12 my $orig = shift;
120 12 my $self = shift;
121 12 my ($feeds) = @_;
122 12 $feeds = $self->$orig($feeds);
123 12 ▶ $self->update_opml($feeds) if $self->has_opml;
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_opml 12 0 12
124 12 return $feeds;
125 11 };
126  
127 =head1 AUTHOR
128  
129 Dave Cross, <dave@perlhacks.com>
130  
131 =head1 COPYRIGHT AND LICENSE
132  
133 Copyright (c) 2010 by Magnum Solutions Ltd.
134  
135 This library is free software; you can redistribute it and/or modify
136 it under the same terms as Perl itself, either Perl version 5.10.0 or,
137 at your option, any later version of Perl 5 you may have available.
138  
139 =cut
140  
141 11 1;
« Perlanet/Feed.pm ↑ Summary Perlanet/Trait/FeedFile.pm »