blib/lib/WebService/Google/Contact.pm

filter: Statementstmt 43.4% 30 / 69 Branchbran 0.0% 0 / 10 Conditioncond 20.0% 1 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 61.5% 8 / 13 Podpod 100% 6 / 6 totaltotal 42.4% 45 / 106 CC 10 SCAR 20.9
CC
10
Cov
37%
get_contact
20.0
upgrade_to_session_token
12.0
get_email
12.0
CRAP 8.0
↑ Summary
1 package WebService::Google::Contact;
2  
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 our $VERSION = '0.1';
8  
9 3 ▶use base qw/Class::Accessor::Fast/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 __PACKAGE__->mk_accessors(qw(email contacts));
11  
12 3 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 3 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 3 ▶use XML::Liberal;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 0 ▶sub name_by_email {
Subroutine name_by_email: not called CC=1 SCAR=6.9
Pod documented
17 0 my $self = shift;
18 0 my ($name) = split '@', $self->email;
19 0 return $name;
20 }
21  
22 1 ▶sub uri_to_login {
Subroutine uri_to_login: called CC=2 SCAR=7.0
Pod documented
23 1 my ($self, $next, $scope) = @_;
24 1 ▶ $scope ||= 'http://www.google.com/m8/feeds';
Condition50%1/2
$scope ||= "http://www.google.com/m8/feeds"
l!l
01
MC/DC0%0/1
$scope ||= "http://www.google.com/m8/feeds"
$scope
Truth table50%1/2
A
A= $scope
Aresult
11
00
25 1 my $base = 'https://www.google.com/accounts/AuthSubRequest';
26 1 my $uri = URI->new( $base );
27 1 $uri->query_form(
28 scope => $scope,
29 session => 1,
30 next => $next,
31 secure => 0,
32 );
33 1 $uri->as_string;
34 }
35  
36 0 ▶sub verify {
Subroutine verify: not called CC=2 SCAR=17.9
Pod documented
37 0 my ($self, $token) = @_;
38 0 ▶ if ( $self->upgrade_to_session_token( $token ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->upgrade_to_session_token($token)) 0 0 0
39 0 return $self->get_email;
40 }
41 0 return;
42 }
43  
44 0 ▶sub upgrade_to_session_token {
Subroutine upgrade_to_session_token: not called CC=3 SCAR=24.8
Pod documented
45 0 my ($self, $token) = @_;
46 0 my $ua = LWP::UserAgent->new();
47 0 my $res = $ua->get(
48 'https://www.google.com/accounts/AuthSubSessionToken',
49 'Content-Type' => 'application/x-www-form-urlencoded',
50 'Authorization' => 'AuthSub token="' . $token . '"',
51 );
52 0 ▶ if ( $res->is_success and $res->content =~ /^Token=(.+)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->is_success and $res->content =~ /^Token=(.+)$/) 0 0 0
Condition0%0/3
$res->is_success and $res->content =~ /^Token=(.+)$/
!ll&&!rl&&r
000
MC/DC0%0/2
$res->is_success and $res->content =~ /^Token=(.+)$/
$res->is_success $res->content =~ /^Token=(.+)$/
Truth table0%0/3
A and B
A= $res->is_successB= $res->content =~ /^Token=(.+)$/
ABresult
0X0
100
111
53 0 $self->{session_token} = $1;
54 0 return 1;
55 }
56 0 Carp::cluck "error upgrade_to_session_token";
57 0 return;
58 }
59  
60 0 ▶sub get_email {
Subroutine get_email: not called CC=3 SCAR=24.8
Pod documented
61 0 my $self = shift;
62 0 my $token = $self->{session_token};
63 0 my $ua = LWP::UserAgent->new();
64 0 my $res = $ua->get(
65 'http://www.google.com/m8/feeds/contacts/default/full',
66 'Content-Type' => 'application/x-www-form-urlencoded',
67 'Authorization' => 'AuthSub token="' . $token . '"',
68 );
69 0 ▶ if ( $res->is_success ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->is_success) 0 0 0
70 0 $self->{xml_content} = $res->content;
71 0 ▶ return $self->{email} = $1 if $self->{xml_content} =~ /<id>(.+?)<\/id>/;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"xml_content"} =~ m[<id>(.+?)</id>] 0 0 0
72 }
73 0 Carp::cluck 'error get_contact';
74 }
75  
76 0 ▶sub get_contact {
Subroutine get_contact: not called CC=4 SCAR=30.0
Pod documented
77 0 my $self = shift;
78 0 my $xml = $self->{xml_content};
79 0 my $parser = XML::Liberal->new;
80 0 my $doc = eval { $parser->parse_string( $xml ) };
81  
82 0 ▶ Carp::cluck $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
83  
84 0 my $root = $doc->documentElement;
85  
86 0 my @entries = $root->findnodes("//*[local-name()='entry']");
87 0 my @contacts;
88 0 for my $entry ( @entries ) {
89 0 my %elems;
90 0 $elems{ $_ } = $entry->findvalue("./*[local-name()='" . $_ . "']") for qw(id updated title);
91 0 $elems{"name"} = $elems{"title"};
92 0 $elems{"email"} = $entry->getElementsByTagName('gd:email')->[0]->getAttribute("address");
93 0 push @contacts, \%elems;
94 }
95 0 return $self->{contacts} = \@contacts;
96 }
97  
98 3 1;
99  
100 __END__
↑ Summary