Plagger/Plugin/Subscription/FOAF.pm untested

filter: Statementstmt 0.0% 0 / 34 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 60 CC 2 SCAR 10.6
CC
2
Cov
0%
load_foaf
6.0
register
2.0
load
2.0
CRAP 2.9
1 package Plagger::Plugin::Subscription::FOAF;
2  
3 use strict;
4 use warnings;
5  
6 use base qw(Plagger::Plugin);
7 use Plagger::Util;
8  
9 use XML::FOAF;
10  
11 sub register {
12 my ( $self, $context ) = @_;
13  
14 $context->register_hook( $self, 'subscription.load' => \&load );
15 }
16  
17 sub load {
18 my ( $self, $context ) = @_;
19  
20 my $uri = URI->new( $self->conf->{url} )
21 or $context->error("config 'url' is missing");
22  
23 $self->load_foaf( $context, $uri );
24 }
25  
26 sub load_foaf {
27 my ( $self, $context, $uri ) = @_;
28  
29 my $content = Plagger::Util::load_uri($uri);
30  
31 my $person = eval { XML::FOAF->new( \$content, $uri )->person };
32  
33 unless ($person) {
34 $context->log( error => "Error loading FOAF file $uri: " . ($@ || XML::FOAF->errstr) );
35 return;
36 }
37  
38 for my $friend ( @{ $person->knows } ) {
39 my $blog = $friend->weblog or next;
40  
41 my $feed = Plagger::Feed->new;
42 $feed->url($blog);
43  
44 $context->subscription->add($feed);
45 }
46  
47 return 1;
48 }
49  
50 1;
51  
52 =head1 NAME
53  
54 Plagger::Plugin::Subscription::FOAF - Simple subscription of friends' blogs
55  
56 =head1 SYNOPSIS
57  
58 - module: Subscription::FOAF
59 config:
60 url: http://user.livejournal.com/data/foaf
61  
62 =head1 DESCRIPTION
63  
64 This module subscribes to your friends' blogs in a FOAF file.
65  
66 =head1 AUTHOR
67  
68 Ilmari Vacklin <ilmari.vacklin@helsinki.fi>
69  
70 =head1 SEE ALSO
71  
72 L<Plagger>, L<http://xmlns.com/foaf/0.1/>
73  
74 =head1 LICENSE
75  
76 This module is free software; you can redistribute it and/or modify it under
77 the same terms as Perl itself.