Atom.pm

filter: Statementstmt 41.2% 26 / 63 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 80.0% 8 / 10 Podpod n/a totaltotal 45.3% 34 / 75 CC 3 SCAR 13.4
CC
3
Cov
40%
_build_feed
12.0
_build_plugin
2.0
BEGIN
1.0
CRAP 3.8
↑ Summary Atom/Plugin.pm »
1 # ABSTRACT: Atom feed for web
2  
3 package Web::Atom;
4 2 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 $Web::Atom::VERSION = '0.1.0';
6 }
7 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 =head1 NAME
11  
12 Web::Atom - Atom feed for web
13  
14 =head1 VERSION
15  
16 version 0.1.0
17  
18 =head1 DESCRIPTION
19  
20 Write your own plugin to parse webpage and then generate Atom feed.
21  
22 =head1 SYNOPSIS
23  
24 use Web::Atom;
25 my $feed = Web::Atom->new(p => 'Bank::Cathaybk::Creditbank');
26 $feed->id('http://feeds.hasname.com/feed/cathaybk.creditcard.atom');
27 print $feed->as_xml;
28  
29 =cut
30  
31 2 ▶use Any::Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 2 has 'feed' => (is => 'rw', isa => 'XML::Atom::Feed', lazy_build => 1, handles => {as_xml => 'as_xml', id => 'id'});
33 2 has 'p' => (is => 'ro', isa => 'Str', required => 1);
34 2 has 'plugin' => (is => 'rw', isa => 'Web::Atom::Plugin', lazy_build => 1);
35  
36 2 ▶use XML::Atom::Entry;
Subroutine BEGIN: called CC=1 SCAR=0.0
37 2 ▶use XML::Atom::Feed;
Subroutine BEGIN: called CC=1 SCAR=0.0
38 2 ▶use XML::Atom::Link;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 2 ▶use XML::Atom::Person;
Subroutine BEGIN: called CC=1 SCAR=0.0
40  
41 0 ▶sub _build_feed {
Subroutine _build_feed: not called CC=3 SCAR=24.8
42 0 my $self = shift;
43  
44 0 my $plugin = $self->plugin;
45  
46 0 my $author = XML::Atom::Person->new(Version => 1.0);
47 0 $author->email($plugin->author_email);
48 0 $author->name($plugin->author_name);
49  
50 0 my $link = XML::Atom::Link->new(Version => 1.0);
51 0 $link->type('text/html');
52 0 $link->rel('alternate');
53 0 $link->href($plugin->url);
54  
55 0 my $feed = XML::Atom::Feed->new(Version => 1.0);
56 0 $feed->add_link($link);
57 0 $feed->author($author);
58 0 $feed->title($plugin->title);
59  
60 0 foreach my $e (@{$plugin->entries}) {
61 0 my $entry = XML::Atom::Entry->new(Version => 1.0);
62  
63 0 ▶ if (defined $entry->author) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $entry->author) { } 0 0 0
64 0 my $entryAuthor = XML::Atom::Author->new(Version => 1.0);
65 0 $entryAuthor->email($e->author_email);
66 0 $entryAuthor->name($e->author_name);
67 0 $entry->author($entryAuthor);
68 } else {
69 0 $entry->author($author);
70 }
71  
72 0 $entry->id($e->id);
73 0 $entry->content($e->content);
74 0 $entry->title($e->title);
75  
76 0 my $link = XML::Atom::Link->new(Version => 1.0);
77 0 $link->type('text/html');
78 0 $link->rel('alternate');
79 0 $link->href($e->url);
80 0 $entry->add_link($link);
81  
82 0 $feed->add_entry($entry);
83 }
84  
85 0 return $feed;
86 }
87  
88 0 ▶sub _build_plugin {
Subroutine _build_plugin: not called CC=1 SCAR=6.9
89 0 my $self = shift;
90  
91 0 my $p = $self->p;
92 0 my $pname = "Web::Atom::$p";
93  
94 0 eval "require $pname;";
95 0 $pname->new;
96 }
97  
98 =head1 AUTHOR
99  
100 Gea-Suan Lin, C<< <gslin at gslin.org> >>
101  
102 =head1 LICENSE AND COPYRIGHT
103  
104 Copyright 2011 Gea-Suan Lin.
105  
106 This software is released under 3-clause BSD license. See
107 L<http://www.opensource.org/licenses/bsd-license.php> for more
108 information.
109  
110 =cut
111  
112 2 1;
↑ Summary Atom/Plugin.pm »