| 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"
MC/DC0%0/1
$scope ||= "http://www.google.com/m8/feeds"
$scope
Truth table50%1/2
A
A= $scope
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition0%0/3
$res->is_success and $res->content =~ /^Token=(.+)$/
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=(.+)$/
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 70 | 0 | $self->{xml_content} = $res->content; | |||||||||||||||||||||||||||
| 71 | 0 | ▶ | return $self->{email} = $1 if $self->{xml_content} =~ /<id>(.+?)<\/id>/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||