Schema/ResultSet/Feed.pm

filter: Statementstmt 48.4% 16 / 33 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 71.4% 5 / 7 Podpod 0.0% 0 / 2 totaltotal 28.3% 21 / 74 CC 12 SCAR 44.0
CC
12
Cov
28%
filter_unseen
132.0
add_new_blog
6.0
BEGIN
1.0
CRAP 81.6
↑ Summary Schema/Result/Post.pm »
1 package IronMan::Schema::ResultSet::Feed;
2  
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 ▶use base 'DBIx::Class::ResultSet';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 4 ▶use Data::UUID;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use Scalar::Util 'blessed';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 ## Need to check if url is duplicated by normalising it as well as just uniquing what is passed in!
12 0 ▶sub add_new_blog {
Subroutine add_new_blog: not called CC=2 SCAR=17.9
Pod undocumented
13 0 my ($self, %args) = @_;
14  
15 # print STDERR "Add new blog: ", Data::Dumper::Dumper(\%args );
16 0 my $uuids = Data::UUID->new;
17 my $fdb = $self->find_or_new
18 ({
19 id => $uuids->create_str,
20 url => $args{url},
21 title => $args{title},
22 owner => $args{email},
23 },
24 0 { key => 'url' }
25 );
26  
27 0 ▶ if($fdb->in_storage) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fdb->in_storage) 0 0 0
28 0 return (0, $fdb);
29 }
30 0 $fdb->insert;
31  
32 0 return (1, $fdb);
33 }
34  
35 ## Given a feed url that should exist as a unique feed in the db,
36 ## and an arrayref of entry hashes/objects, return ones we dont
37 ## have yet.
38 0 ▶sub filter_unseen {
Subroutine filter_unseen: not called CC=11 SCAR=48.8
Pod undocumented
39 0 my ($self, $feed_url, $entries) = @_;
40  
41 0 ▶ die "filter_unseen not passed a feed_url" if(!$feed_url);
Branch: 1 branch
BranchTrueFalseTotal
unless $feed_url 0 0 0
42  
43 0 ▶ return [] if(!$entries || ref($entries) ne 'ARRAY' || !@$entries);
Branch: 1 branch
BranchTrueFalseTotal
if not $entries or ref $entries ne "ARRAY" or not @$entries 0 0 0
Condition0%0/6
not $entries or ref $entries ne "ARRAY" or not @$entries
l!l&&r!l&&!r
000
not $entries or ref $entries ne "ARRAY"
l!l&&r!l&&!r
000
MC/DC0%0/3
not $entries or ref $entries ne "ARRAY" or not @$entries
not $entries ref $entries ne "ARRAY" not @$entries
Truth table0%0/4
not(A) or B or not(C)
A= not $entriesB= ref $entries ne "ARRAY"C= not @$entries
ABCresult
1XX1
01X1
0011
0000
44  
45 0 my $feed = $self->find({ url => $feed_url}, { key => 'url' });
46 0 ▶ die "No such feed: $feed_url" if(!$feed);
Branch: 1 branch
BranchTrueFalseTotal
unless $feed 0 0 0
47  
48 my %entry_urls = map {
49 0 blessed($_) ?
50 ( $_->can('url') && $_->url )
51 ||
52 ( $_->can('link') && $_->link )
53 0 ▶ : $_->{url} => $_ } @$entries;
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($_) ? : 0 0 0
Condition0%0/9
$_->can("url") and $_->url or $_->can("link") and $_->link
l!l&&r!l&&!r
000
$_->can("url") and $_->url
!ll&&!rl&&r
000
$_->can("link") and $_->link
!ll&&!rl&&r
000
MC/DC0%0/4
$_->can("url") and $_->url or $_->can("link") and $_->link
$_->can("url") $_->url $_->can("link") $_->link
Truth table0%0/7
A and B or C and D
A= $_->can("url")B= $_->urlC= $_->can("link")D= $_->link
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
54  
55 0 my @got_these = $feed->posts->search({ url => { -in => [ keys %entry_urls ] } });
56 0 delete $entry_urls{$_->url} for @got_these;
57  
58 0 return [ values(%entry_urls) ];
59 }
60  
61 4 1;
↑ Summary Schema/Result/Post.pm »