| 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
MC/DC0%0/1
delete $args{'interval'} || 60
delete $args{'interval'}
Truth table0%0/2
A
A= delete $args{'interval'}
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 0 | ▶ | unless ($username && $password) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$username and $password
MC/DC0%0/2
$username and $password
$username
$password
Truth table0%0/3
A and B
A= $usernameB= $password
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 38 | 0 | ▶ | my $feed = XML::Atom::Feed->new(\$body) or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | 0 | for my $e ($feed->entries) { | |||||||||||||||||||||||||||
| 40 | 0 | ▶ | unless ($seen{$e->id}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 {
}
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 {
}
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||