Superfeedr/Notification.pm

filter: Statementstmt 29.4% 20 / 68 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 46.1% 6 / 13 Podpod 0.0% 0 / 5 totaltotal 27.9% 26 / 93 CC 8 SCAR 17.7
CC
8
Cov
27%
node_entries
12.0
entries
12.0
as_atom_feed
6.0
CRAP 5.9
« XMPP/Ext/Superfeedr.pm ↑ Summary Superfeedr.pm »
1 package AnyEvent::Superfeedr::Notification;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use XML::Atom::Entry;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use XML::Atom::Feed;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use AnyEvent::Superfeedr();
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use Object::Tiny qw{
Subroutine BEGIN: called CC=1 SCAR=0.0
9 http_status
10 next_fetch
11 feed_uri
12 items
13 title
14 _node_entries
15 _atom_entries
16 1 };
17  
18 0 ▶sub node_entries {
Subroutine node_entries: not called CC=3 SCAR=24.8
Pod undocumented
19 0 my $notification = shift;
20 0 my $node_entries = $notification->_node_entries;
21 0 ▶ return @$node_entries if $node_entries;
Branch: 1 branch
BranchTrueFalseTotal
if $node_entries 0 0 0
22  
23 0 my @node_entries;
24 0 for my $item (@{ $notification->items }) {
25 ## each item as one entry
26 0 my ($node_entry) = $item->nodes;
27 0 push @node_entries, $node_entry;
28 }
29 0 $notification->{items} = undef;
30 0 $notification->{_node_entries} = \@node_entries;
31 0 return @node_entries;
32 }
33  
34 0 ▶sub entries {
Subroutine entries: not called CC=3 SCAR=24.8
Pod undocumented
35 0 my $notification = shift;
36 0 my $atom_entries = $notification->_atom_entries;
37 0 ▶ return @$atom_entries if $atom_entries;
Branch: 1 branch
BranchTrueFalseTotal
if $atom_entries 0 0 0
38  
39 0 my @atom_entries;
40 0 for my $node_entry ($notification->node_entries) {
41 0 my $str = $node_entry->as_string;
42 0 my $atom_entry = XML::Atom::Entry->new(Stream => \$str);
43 0 push @atom_entries, $atom_entry;
44 }
45 0 return @{$notification->{_atom_entries} } = @atom_entries;
46 }
47  
48 0 ▶sub as_atom_feed {
Subroutine as_atom_feed: not called CC=2 SCAR=17.9
Pod undocumented
49 0 my $notification = shift;
50 0 my $feed = XML::Atom::Feed->new;
51 0 for ($notification->entries) {
52 0 $feed->add_entry($_);
53 }
54 0 return $feed;
55 }
56  
57 0 ▶sub as_xml {
Subroutine as_xml: not called CC=2 SCAR=17.9
Pod undocumented
58 0 my $notification = shift;
59 0 my $id = $notification->tagify;
60 0 my $feed_uri = _xml_encode($notification->feed_uri);
61 0 my $title = _xml_encode($notification->title);
62 0 my $now = _now_as_w3c();
63 0 my $feed = <<EOX;
64 <?xml version="1.0" encoding="utf-8"?>
65 <feed xmlns="http://www.w3.org/2005/Atom">
66 <id>$id</id>
67 <title>$title</title>
68 <updated>$now</updated>
69 <link href="$feed_uri" rel="self" />
70 EOX
71 0 for my $node_entry ($notification->node_entries) {
72 0 $feed .= $node_entry->as_string;
73 }
74 0 $feed .= "</feed>";
75 0 return $feed;
76 }
77  
78 0 ▶sub _now_as_w3c {
Subroutine _now_as_w3c: not called CC=1 SCAR=6.9
79 0 my @time = gmtime;
80 0 sprintf '%4d-%02d-%02dT%02d:%02d:%02dZ',
81 $time[5]+1900, $time[4]+1, @time[3,2,1,0];
82 }
83  
84 1 my %enc = ('&' => '&amp;', '"' => '&quot;', '<' => '&lt;', '>' => '&gt;', '\'' => '&#39;');
85  
86 0 ▶sub _xml_encode {
Subroutine _xml_encode: not called CC=1 SCAR=6.9
87 0 local $_ = shift;
88 0 s/([&"\'<>])/$enc{$1}/g;
89 0 $_;
90 }
91  
92 0 ▶sub tagify {
Subroutine tagify: not called CC=2 SCAR=17.9
Pod undocumented
93 0 my $notification = shift;
94  
95 ## date is based on current time
96 0 my (undef, undef, undef, $mday, $mon, $year) = gmtime();
97 0 $year +=1900;
98  
99 ## specific is based on superfeedr's feed:status
100 0 ▶ my $specific = $notification->feed_uri || "";
Condition0%0/2
$notification->feed_uri || ''
l!l
00
MC/DC0%0/1
$notification->feed_uri || ''
$notification->feed_uri
Truth table0%0/2
A
A= $notification->feed_uri
Aresult
11
00
101 0 $specific =~ s{^\w+://}{};
102 0 $specific =~ tr{#}{/};
103  
104 0 return sprintf "tag:%s,%4d-%02d-%02d:%s",
105 $AnyEvent::Superfeedr::SERVICE,
106 $year, $mon, $mday,
107 $specific;
108 }
109  
110 1 1;
« XMPP/Ext/Superfeedr.pm ↑ Summary Superfeedr.pm »