| 1 | package WWW::Google::Contacts::Server; | ||||||||||||||||||||||||||||
| 2 | { | ||||||||||||||||||||||||||||
| 3 | 17 | $WWW::Google::Contacts::Server::VERSION = '0.39'; | |||||||||||||||||||||||||||
| 4 | } | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 17 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 17 | ▶ | use LWP::UserAgent; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 17 | ▶ | use Net::Google::AuthSub; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 17 | ▶ | use Carp qw( croak ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | has ua => ( | ||||||||||||||||||||||||||||
| 12 | is => 'ro', | ||||||||||||||||||||||||||||
| 13 | 2 | ▶ | default => sub { LWP::UserAgent->new }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 17 | ); | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 17 | has authsub => ( | |||||||||||||||||||||||||||
| 17 | is => 'ro', | ||||||||||||||||||||||||||||
| 18 | lazy_build => 1, | ||||||||||||||||||||||||||||
| 19 | ); | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 17 | has username => ( | |||||||||||||||||||||||||||
| 22 | isa => 'Str', | ||||||||||||||||||||||||||||
| 23 | is => 'ro', | ||||||||||||||||||||||||||||
| 24 | required => 1, | ||||||||||||||||||||||||||||
| 25 | ); | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 17 | has password => ( | |||||||||||||||||||||||||||
| 28 | isa => 'Str', | ||||||||||||||||||||||||||||
| 29 | is => 'ro', | ||||||||||||||||||||||||||||
| 30 | required => 1, | ||||||||||||||||||||||||||||
| 31 | ); | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 17 | has protocol => ( | |||||||||||||||||||||||||||
| 34 | isa => 'Str', | ||||||||||||||||||||||||||||
| 35 | is => 'ro', | ||||||||||||||||||||||||||||
| 36 | default => 'http', | ||||||||||||||||||||||||||||
| 37 | ); | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 17 | has gdata_version => ( | |||||||||||||||||||||||||||
| 40 | isa => 'Str', | ||||||||||||||||||||||||||||
| 41 | is => 'ro', | ||||||||||||||||||||||||||||
| 42 | default => '3.0', | ||||||||||||||||||||||||||||
| 43 | ); | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 0 | ▶ | sub _build_authsub { | ||||||||||||||||||||||||||
|
Subroutine
_build_authsub: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 46 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 0 | my $auth = Net::Google::AuthSub->new( service => 'cp' ); | |||||||||||||||||||||||||||
| 49 | 0 | my $res = $auth->login( $self->username, $self->password ); | |||||||||||||||||||||||||||
| 50 | 0 | ▶ | unless ( $res and $res->is_success ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$res and $res->is_success
MC/DC0%0/2
$res and $res->is_success
$res
$res->is_success
Truth table0%0/3
A and B
A= $resB= $res->is_success
| |||||||||||||||||||||||||||||
| 51 | 0 | ▶ | if ($res) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | 0 | warn $res->{_response}->content; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | 0 | croak "Authentication failed"; | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | 0 | return $auth; | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 0 | ▶ | sub authenticate { | ||||||||||||||||||||||||||
|
Subroutine
authenticate: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 60 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 61 | 0 | ▶ | return 1 if ( $self->authsub ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 17 | foreach my $method (qw(get post put delete)) { | |||||||||||||||||||||||||||
| 65 | 0 | ▶ | around $method => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 66 | 0 | my $orig = shift; | |||||||||||||||||||||||||||
| 67 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 68 | 0 | my $id = shift; | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | # ENSURE we use right protocol.. Even though we've specified https, | ||||||||||||||||||||||||||||
| 71 | # references in the data from google points to http:// | ||||||||||||||||||||||||||||
| 72 | 0 | my $proto = $self->protocol; | |||||||||||||||||||||||||||
| 73 | 0 | $id =~ s{^\w+://}{$proto://}; | |||||||||||||||||||||||||||
| 74 | 0 | return $self->$orig( $id, @_ ); | |||||||||||||||||||||||||||
| 75 | 68 | }; | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 0 | ▶ | sub get { | ||||||||||||||||||||||||||
|
Subroutine
get: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 79 | 0 | my ( $self, $id ) = @_; | |||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 0 | my %headers = $self->authsub->auth_params; | |||||||||||||||||||||||||||
| 82 | 0 | $headers{'GData-Version'} = $self->gdata_version; | |||||||||||||||||||||||||||
| 83 | 0 | my $res = $self->ua->get( $id, %headers ); | |||||||||||||||||||||||||||
| 84 | 0 | ▶ | unless ( $res->is_success ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | 0 | croak "GET failed: " . $res->status_line; | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | 0 | return $res; | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 0 | ▶ | sub post { | ||||||||||||||||||||||||||
|
Subroutine
post: not called CC=2 SCAR=13.7
| |||||||||||||||||||||||||||||
| 91 | 0 | my ( $self, $id, $etag, $content_type, $content ) = @_; | |||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 0 | my %headers = $self->authsub->auth_params; | |||||||||||||||||||||||||||
| 94 | 0 | $headers{'Content-Type'} = $content_type; | |||||||||||||||||||||||||||
| 95 | 0 | $headers{'GData-Version'} = $self->gdata_version; | |||||||||||||||||||||||||||
| 96 | 0 | my $res = $self->ua->post( $id, %headers, Content => $content ); | |||||||||||||||||||||||||||
| 97 | 0 | ▶ | unless ( $res->is_success ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | 17 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 99 | 0 | print Dumper $res; | |||||||||||||||||||||||||||
| 100 | 0 | croak "POST failed: " . $res->status_line; | |||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | 0 | return $res; | |||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 0 | ▶ | sub put { | ||||||||||||||||||||||||||
|
Subroutine
put: not called CC=2 SCAR=14.2
| |||||||||||||||||||||||||||||
| 106 | 0 | my ( $self, $id, $etag, $content_type, $content ) = @_; | |||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 0 | my %headers = $self->authsub->auth_params; | |||||||||||||||||||||||||||
| 109 | 0 | $headers{'Content-Type'} = $content_type; | |||||||||||||||||||||||||||
| 110 | 0 | $headers{'GData-Version'} = $self->gdata_version; | |||||||||||||||||||||||||||
| 111 | 0 | $headers{'If-Match'} = $etag; | |||||||||||||||||||||||||||
| 112 | 0 | $headers{'X-HTTP-Method-Override'} = 'PUT'; | |||||||||||||||||||||||||||
| 113 | 0 | my $res = $self->ua->post( $id, %headers, Content => $content ); | |||||||||||||||||||||||||||
| 114 | 0 | ▶ | unless ( $res->is_success ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 115 | 17 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 116 | 0 | print Dumper $res; | |||||||||||||||||||||||||||
| 117 | 0 | croak "PUT failed: " . $res->status_line; | |||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | 0 | return $res; | |||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 0 | ▶ | sub delete { | ||||||||||||||||||||||||||
|
Subroutine
delete: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 123 | 0 | my ( $self, $id, $etag ) = @_; | |||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 0 | my %headers = $self->authsub->auth_params; | |||||||||||||||||||||||||||
| 126 | 0 | $headers{'If-Match'} = $etag; | |||||||||||||||||||||||||||
| 127 | 0 | $headers{'X-HTTP-Method-Override'} = 'DELETE'; | |||||||||||||||||||||||||||
| 128 | 0 | $headers{'GData-Version'} = $self->gdata_version; | |||||||||||||||||||||||||||
| 129 | 0 | my $res = $self->ua->post( $id, %headers ); | |||||||||||||||||||||||||||
| 130 | 0 | ▶ | unless ( $res->is_success ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 131 | 0 | croak "DELETE failed: " . $res->status_line; | |||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||
| 133 | 0 | return $res; | |||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 17 | ▶ | no Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 137 | 17 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 138 | 17 | 1; | |||||||||||||||||||||||||||
| 139 | __END__ | ||||||||||||||||||||||||||||