Contacts/Server.pm

filter: Statementstmt 39.5% 34 / 86 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 53.3% 8 / 15 Podpod 0.0% 0 / 1 totaltotal 34.7% 42 / 121 CC 9 SCAR 18.2
CC
9
Cov
33%
_build_authsub
20.0
authenticate
6.0
get
6.0
CRAP 6.2
« Contacts/Group.pm ↑ Summary Contacts.pm »
1 package WWW::Google::Contacts::Server;
2 {
3 17 $WWW::Google::Contacts::Server::VERSION = '0.38';
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 sub _build_authsub {
46 0 ▶ my $self = shift;
Subroutine _build_authsub: not called CC=4 SCAR=30.0
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
BranchTrueFalseTotal
unless ($res and $res->is_success) 0 0 0
Condition0%0/3
$res and $res->is_success
!ll&&!rl&&r
000
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
ABresult
0X0
100
111
51 0 ▶ if ($res) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res) 0 0 0
52 0 warn $res->{_response}->content;
53 }
54 0 croak "Authentication failed";
55 }
56 0 return $auth;
57 }
58  
59 sub authenticate {
60 0 ▶ my $self = shift;
Subroutine authenticate: not called CC=2 SCAR=17.9
Pod undocumented
61 0 ▶ return 1 if ( $self->authsub );
Branch: 1 branch
BranchTrueFalseTotal
if $self->authsub 0 0 0
62 }
63  
64 17 foreach my $method (qw(get post put delete)) {
65 around $method => sub {
66 0 ▶ my $orig = shift;
Subroutine __ANON__: not called CC=1 SCAR=6.9
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 sub get {
79 0 ▶ my ( $self, $id ) = @_;
Subroutine get: not called CC=2 SCAR=17.9
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
BranchTrueFalseTotal
unless ($res->is_success) 0 0 0
85 0 croak "GET failed: " . $res->status_line;
86 }
87 0 return $res;
88 }
89  
90 sub post {
91 0 ▶ my ( $self, $id, $etag, $content_type, $content ) = @_;
Subroutine post: not called CC=2 SCAR=13.7
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
BranchTrueFalseTotal
unless ($res->is_success) 0 0 0
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 sub put {
106 0 ▶ my ( $self, $id, $etag, $content_type, $content ) = @_;
Subroutine put: not called CC=2 SCAR=14.2
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
BranchTrueFalseTotal
unless ($res->is_success) 0 0 0
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 sub delete {
123 0 ▶ my ( $self, $id, $etag ) = @_;
Subroutine delete: not called CC=2 SCAR=17.9
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
BranchTrueFalseTotal
unless ($res->is_success) 0 0 0
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__
« Contacts/Group.pm ↑ Summary Contacts.pm »