blib/lib/AnyEvent/Gmail/Feed.pm

filter: Statementstmt 42.2% 19 / 45 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 60.0% 6 / 10 Podpod 0.0% 0 / 1 totaltotal 31.6% 25 / 79 CC 10 SCAR 30.8
CC
10
Cov
30%
__ANON__
42.0
new
30.0
__ANON__
2.0
CRAP 21.7
↑ Summary
1 package AnyEvent::Gmail::Feed;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use 5.008_001;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 our $VERSION = '0.02';
6  
7 1 ▶use AnyEvent;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use AnyEvent::HTTP;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use MIME::Base64;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use XML::Atom::Feed;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 0 ▶sub new {
Subroutine new: not called CC=5 SCAR=34.0
Pod undocumented
13 0 my ($class, %args) = @_;
14  
15 0 my $username = delete $args{username};
16 0 my $password = delete $args{password};
17 0 my $label = delete $args{label};
18 0 ▶ my $interval = delete $args{interval} || 60;
Condition0%0/2
delete $args{'interval'} || 60
l!l
00
MC/DC0%0/1
delete $args{'interval'} || 60
delete $args{'interval'}
Truth table0%0/2
A
A= delete $args{'interval'}
Aresult
11
00
19  
20 0 ▶ unless ($username && $password) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($username and $password) 0 0 0
Condition0%0/3
$username and $password
!ll&&!rl&&r
000
MC/DC0%0/2
$username and $password
$username $password
Truth table0%0/3
A and B
A= $usernameB= $password
ABresult
0X0
100
111
21 0 die "both username and password are required";
22 }
23  
24 0 my $self = bless {}, $class;
25  
26 0 my $auth = MIME::Base64::encode( join(":", $username, $password) );
27 0 my $headers = {Authorization => "Basic $auth"};
28 0 my $uri = 'https://mail.google.com/mail/feed/atom/';
29 0 ▶ $uri .= $label . '/' if $label; ## 'unread' or whatever
Branch: 1 branch
BranchTrueFalseTotal
if $label 0 0 0
30  
31 0 my %seen;
32  
33 my $timer;
34 0 ▶ my $checker; $checker = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
35 0 ▶ http_get $uri, headers => $headers, sub {
Subroutine __ANON__: not called CC=6 SCAR=37.4
36 0 my ($body, $hdr) = @_;
37 0 ▶ return unless $body;
Branch: 1 branch
BranchTrueFalseTotal
unless $body 0 0 0
38 0 ▶ my $feed = XML::Atom::Feed->new(\$body) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $feed = "XML::Atom::Feed"->new(\$body) or return 0 0 0
39 0 for my $e ($feed->entries) {
40 0 ▶ unless ($seen{$e->id}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($seen{$e->id}) 0 0 0
41 0 ▶ ($args{on_new_entry} || sub {})->($e);
Subroutine __ANON__: not called CC=1 SCAR=6.9
Condition0%0/3
$args{'on_new_entry'} || sub { }
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{'on_new_entry'} || sub { }
$args{'on_new_entry'} sub { }
Truth table0%0/3
A || B
A= $args{'on_new_entry'}B= sub { }
ABresult
1X1
011
000
42 };
43 0 $seen{$e->id}++;
44 }
45 0 $timer = AnyEvent->timer( after => $interval, cb => $checker);
46 0 };
47 0 };
48 0 $checker->();
49 0 return $self;
50 }
51  
52 1 1;
53 __END__
↑ Summary