Aggregator/Deduper.pm

filter: Statementstmt 48.7% 20 / 41 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 45.4% 5 / 11 Podpod 100% 1 / 1 totaltotal 38.8% 26 / 67 CC 7 SCAR 31.8
CC
7
Cov
38%
_register
56.0
__ANON__
2.0
__ANON__
2.0
CRAP 23.9
↑ Summary Aggregator/Sort.pm »
1 package XML::Feed::Aggregator::Deduper;
2 6 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
3 6 $XML::Feed::Aggregator::Deduper::VERSION = '0.0401';
4 }
5 6 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 6 ▶use MooseX::Types::Moose qw/Int HashRef/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 6 ▶use HTML::Scrubber;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 6 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 6 requires 'add_entry';
11 6 requires 'all_entries';
12 6 requires 'grep_entries';
13  
14 has body_register => (
15 is => 'ro',
16 isa => HashRef,
17 0 ▶ default => sub { {} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
18 6 traits => ['Hash'],
19 handles => {
20 _register_body_sig => 'set',
21 _body_sig_exists => 'exists'
22 }
23 );
24  
25 has title_register => (
26 is => 'ro',
27 isa => HashRef,
28 0 ▶ default => sub { {} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
29 6 traits => ['Hash'],
30 handles => {
31 _register_title_sig => 'set',
32 _title_sig_exists => 'exists'
33 }
34 );
35  
36 has id_register => (
37 is => 'ro',
38 isa => HashRef,
39 0 ▶ default => sub { {} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
40 6 traits => ['Hash'],
41 handles => {
42 _register_id => 'set',
43 _id_exists => 'exists'
44 }
45 );
46  
47 0 ▶sub deduplicate {
Subroutine deduplicate: not called CC=1 SCAR=6.9
Pod documented
48 0 my ($self) = @_;
49 0 ▶ $self->grep_entries( sub { $self->_register($_) } );
Subroutine __ANON__: not called CC=1 SCAR=6.9
50 0 return $self;
51 }
52  
53 0 ▶sub _register {
Subroutine _register: not called CC=7 SCAR=40.3
54 0 my ($self, $entry) = @_;
55  
56 0 ▶ my $body = length($entry->content->body || '')
Branch: 1 branch
BranchTrueFalseTotal
length($entry->content->body || '') >= length($entry->summary->body || '') ? : 0 0 0
Condition0%0/4
$entry->content->body || ''
l!l
00
$entry->summary->body || ''
l!l
00
MC/DC0%0/1
$entry->content->body || ''
$entry->content->body
MC/DC0%0/1
$entry->summary->body || ''
$entry->summary->body
Truth table0%0/2
A
A= $entry->content->body
Aresult
11
00
Truth table0%0/2
A
A= $entry->summary->body
Aresult
11
00
57 >= length($entry->summary->body || '')
58 ? $entry->content->body : $entry->summary->body;
59  
60 0 my $body_sig = HTML::Scrubber->new->scrub($body);
61  
62 0 $body_sig =~ s/^\s+|\s+$//g;
63 0 $body_sig =~ s/\s+/ /g;
64  
65 0 my $title_sig = $entry->title;
66 0 $title_sig =~ s/^\s+|\s+$//g;
67  
68 0 ▶ return if $self->_id_exists($entry->id);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_id_exists($entry->id) 0 0 0
69 0 $self->_register_id($entry->id, 1);
70 0 ▶ return if $self->_title_sig_exists($title_sig);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_title_sig_exists($title_sig) 0 0 0
71 0 $self->_register_title_sig($title_sig, 1);
72 0 ▶ return if $self->_body_sig_exists($body_sig);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_body_sig_exists($body_sig) 0 0 0
73 0 $self->_register_body_sig($body_sig, 1);
74  
75 0 return 1;
76 }
77  
78 6 1;
79  
80  
81  
82 =pod
83  
84 =head1 NAME
85  
86 XML::Feed::Aggregator::Deduper
87  
88 =head1 VERSION
89  
90 version 0.0401
91  
92 =head1 NAME
93  
94 XML::Feed::Aggregator::Deduper - role for deduplication
95  
96 =head1 METHODS
97  
98 =head2 deduplicate
99  
100 deduplicates entries with an aggregator object.
101  
102 =head1 SEE ALSO
103  
104 L<XML::Feed::Aggregator>
105  
106 L<XML::Feed::Aggregator::Sort>
107  
108 =head1 AUTHOR
109  
110 Robin Edwards <robin.ge@gmail.com>
111  
112 =head1 COPYRIGHT AND LICENSE
113  
114 This software is copyright (c) 2011 by Robin Edwards.
115  
116 This is free software; you can redistribute it and/or modify it under
117 the same terms as the Perl 5 programming language system itself.
118  
119 =cut
120  
121  
122 __END__
↑ Summary Aggregator/Sort.pm »