Contacts.pm

filter: Statementstmt 27.4% 40 / 146 Branchbran 11.1% 2 / 18 Conditioncond 33.3% 2 / 6 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 31.2% 10 / 32 Podpod 100% 17 / 17 totaltotal 32.2% 72 / 223 CC 14 SCAR 17.0
CC
14
Cov
26%
get_groups
20.0
new_group
12.0
_create_or_update_contact
12.0
CRAP 5.5
« Contacts/Server.pm ↑ Summary Contacts/Type/Rel.pm »
1 package WWW::Google::Contacts;
2 {
3 17 $WWW::Google::Contacts::VERSION = '0.39';
4 }
5  
6 # ABSTRACT: Google Contacts Data API
7  
8 17 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 17 ▶use Carp qw/croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 17 ▶use WWW::Google::Contacts::Server;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 17 ▶use WWW::Google::Contacts::Contact;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 17 ▶use WWW::Google::Contacts::ContactList;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 17 ▶use WWW::Google::Contacts::Group;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 17 ▶use WWW::Google::Contacts::GroupList;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 has username => (
19 isa => 'Str',
20 is => 'rw',
21 0 ▶ default => sub { $ENV{GOOGLE_USERNAME} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
22 17 );
23  
24 has password => (
25 isa => 'Str',
26 is => 'rw',
27 0 ▶ default => sub { $ENV{GOOGLE_PASSWORD} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
28 17 );
29  
30 17 has protocol => (
31 isa => 'Str',
32 is => 'ro',
33 default => 'http',
34 );
35  
36 17 has server => (
37 isa => 'Object',
38 is => 'ro',
39 lazy_build => 1,
40 );
41  
42 # backward compability
43 has email =>
44 0 ▶ ( isa => 'Str', is => 'rw', trigger => sub { $_[0]->username( $_[1] ) } );
Subroutine __ANON__: not called CC=1 SCAR=1.2
45 has pass =>
46 0 ▶ ( isa => 'Str', is => 'rw', trigger => sub { $_[0]->password( $_[1] ) } );
Subroutine __ANON__: not called CC=1 SCAR=1.2
47  
48 2 ▶sub _build_server {
Subroutine _build_server: called CC=1 SCAR=0.0
49 2 my $self = shift;
50 2 return WWW::Google::Contacts::Server->new(
51 {
52 username => $self->username,
53 password => $self->password,
54 protocol => $self->protocol
55 }
56 );
57 }
58  
59 3 ▶sub new_contact {
Subroutine new_contact: called CC=3 SCAR=11.0
Pod documented
60 3 my $self = shift;
61 my $args =
62 ( scalar(@_) == 1 and ref( $_[0] ) eq 'HASH' )
63 3 ▶ ? { %{ $_[0] }, server => $self->server }
Branch: 1 branch
BranchTrueFalseTotal
scalar @_ == 1 && ref $_[0] eq 'HASH' ? : 1 2 3
Condition66%2/3
scalar @_ == 1 and ref $_[0] eq "HASH"
!ll&&!rl&&r
201
MC/DC50%1/2
scalar @_ == 1 and ref $_[0] eq "HASH"
scalar @_ == 1 ref $_[0] eq "HASH"
Truth table66%2/3
A and B
A= scalar @_ == 1B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
64 : { @_, server => $self->server };
65 3 return WWW::Google::Contacts::Contact->new($args);
66 }
67  
68 0 ▶sub contact {
Subroutine contact: not called CC=1 SCAR=6.9
Pod documented
69 0 my ( $self, $id ) = @_;
70 0 return WWW::Google::Contacts::Contact->new( id => $id,
71 server => $self->server )->retrieve;
72 }
73  
74 0 ▶sub contacts {
Subroutine contacts: not called CC=1 SCAR=6.9
Pod documented
75 0 my $self = shift;
76  
77 0 my $list =
78 WWW::Google::Contacts::ContactList->new( server => $self->server );
79 0 return $list;
80 }
81  
82 0 ▶sub new_group {
Subroutine new_group: not called CC=3 SCAR=24.8
Pod documented
83 0 my $self = shift;
84 my $args =
85 ( scalar(@_) == 1 and ref( $_[0] ) eq 'HASH' )
86 0 ▶ ? { %{ $_[0] }, server => $self->server }
Branch: 1 branch
BranchTrueFalseTotal
scalar @_ == 1 && ref $_[0] eq 'HASH' ? : 0 0 0
Condition0%0/3
scalar @_ == 1 and ref $_[0] eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @_ == 1 and ref $_[0] eq "HASH"
scalar @_ == 1 ref $_[0] eq "HASH"
Truth table0%0/3
A and B
A= scalar @_ == 1B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
87 : { @_, server => $self->server };
88 0 return WWW::Google::Contacts::Group->new($args);
89 }
90  
91 0 ▶sub group {
Subroutine group: not called CC=1 SCAR=6.9
Pod documented
92 0 my ( $self, $id ) = @_;
93 0 return WWW::Google::Contacts::Group->new( id => $id,
94 server => $self->server )->retrieve;
95 }
96  
97 0 ▶sub groups {
Subroutine groups: not called CC=1 SCAR=6.9
Pod documented
98 0 my $self = shift;
99  
100 0 my $list = WWW::Google::Contacts::GroupList->new( server => $self->server );
101 0 return $list;
102 }
103  
104 # All code below is for backwards compability
105  
106 0 ▶sub login {
Subroutine login: not called CC=1 SCAR=6.9
Pod documented
107 0 my ( $self, $email, $pass ) = @_;
108 0 warn "This method is deprecated and will be removed shortly";
109 0 $self->email($email);
110 0 $self->pass($pass);
111 0 my $server = WWW::Google::Contacts::Server->new(
112 { username => $self->email, password => $self->password } );
113 0 $server->authenticate;
114 0 return 1;
115 }
116  
117 0 ▶sub create_contact {
Subroutine create_contact: not called CC=2 SCAR=17.9
Pod documented
118 0 my $self = shift;
119 0 warn "This method is deprecated and will be removed shortly";
120 0 ▶ my $data = scalar @_ % 2 ? shift : {@_};
Branch: 1 branch
BranchTrueFalseTotal
scalar @_ % 2 ? : 0 0 0
121  
122 0 my $contact = $self->new_contact;
123 0 return $self->_create_or_update_contact( $contact, $data );
124 }
125  
126 0 ▶sub _create_or_update_contact {
Subroutine _create_or_update_contact: not called CC=3 SCAR=24.8
127 0 my ( $self, $contact, $data ) = @_;
128  
129 0 $contact->given_name( $data->{givenName} );
130 0 $contact->family_name( $data->{familyName} );
131 0 $contact->notes( $data->{Notes} );
132 $contact->email(
133 {
134 type => "work",
135 primary => 1,
136 value => $data->{primaryMail},
137 display_name => $data->{displayName},
138 }
139 0 );
140 0 ▶ if ( $contact->{secondaryMail} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($contact->{"secondaryMail"}) 0 0 0
141 $contact->add_email(
142 {
143 type => "home",
144 value => $data->{secondaryMail},
145 }
146 0 );
147 }
148  
149 # if ( $contact->{groupMembershipInfo} ) {
150 # $data->{'atom:entry'}->{'gContact:groupMembershipInfo'} = {
151 # deleted => 'false',
152 # href => $contact->{groupMembershipInfo}
153 # };
154 # }
155 0 ▶ if ( $contact->create_or_update ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($contact->create_or_update) 0 0 0
156 0 return 1;
157 }
158 0 return 0;
159 }
160  
161 0 ▶sub get_contacts {
Subroutine get_contacts: not called CC=2 SCAR=17.9
Pod documented
162 0 my $self = shift;
163  
164 0 warn "This method is deprecated and will be removed shortly";
165 0 my $list = $self->contacts;
166 0 my @contacts;
167 0 foreach my $c ( @{ $list->elements } ) {
168 0 my $d = $c;
169 ( $d->{id} ) =
170 0 map { $_->{href} }
171 0 grep { $_->{rel} eq 'self' } @{ $d->{link} };
172 0 $d->{name} = $d->{'gd:name'};
173 0 $d->{email} = $d->{'gd:email'};
174 0 $d->{groupMembershipInfo} = $d->{'gContact:groupMembershipInfo'};
175 0 push @contacts, $d;
176 }
177 0 return @contacts;
178 }
179  
180 0 ▶sub get_contact {
Subroutine get_contact: not called CC=1 SCAR=6.9
Pod documented
181 0 my ( $self, $id ) = @_;
182  
183 0 warn "This method is deprecated and will be removed shortly";
184 0 my $contact = $self->new_contact( id => $id )->retrieve;
185 0 my $data = $contact->raw_data_for_backwards_compability;
186 0 $data->{name} = $data->{'gd:name'};
187 0 $data->{email} = $data->{'gd:email'};
188 0 $data->{groupMembershipInfo} = $data->{'gContact:groupMembershipInfo'};
189 0 return $data;
190 }
191  
192 0 ▶sub update_contact {
Subroutine update_contact: not called CC=1 SCAR=6.9
Pod documented
193 0 my ( $self, $id, $contact ) = @_;
194  
195 0 warn "This method is deprecated and will be removed shortly";
196 0 my $c = $self->new_contact( id => $id )->retrieve;
197 0 return $self->_create_or_update_contact( $c, $contact );
198 }
199  
200 0 ▶sub delete_contact {
Subroutine delete_contact: not called CC=1 SCAR=6.9
Pod documented
201 0 my ( $self, $id ) = @_;
202  
203 0 warn "This method is deprecated and will be removed shortly";
204 0 $self->new_contact( id => $id )->delete;
205 }
206  
207 0 ▶sub get_groups {
Subroutine get_groups: not called CC=4 SCAR=30.0
Pod documented
208 0 my $self = shift;
209  
210 0 warn "This method is deprecated and will be removed shortly";
211 0 my $list = $self->groups;
212 0 my @groups;
213 0 foreach my $d ( @{ $list->elements } ) {
214 0 ▶ my $link = ref( $d->{link} ) eq 'ARRAY' ? $d->{link} : [ $d->{link} ];
Branch: 1 branch
BranchTrueFalseTotal
ref $d->{'link'} eq 'ARRAY' ? : 0 0 0
215 ( $d->{id} ) =
216 0 map { $_->{href} }
217 0 grep { $_->{rel} eq 'self' } @{$link};
218 push @groups,
219 {
220 id => $d->{id},
221 title => $d->{title},
222 updated => $d->{updated},
223 exists $d->{'gContact:systemGroup'}
224 0 ▶ ? ( 'gContact:systemGroup' => $d->{'gContact:systemGroup'}->{'id'} )
Branch: 1 branch
BranchTrueFalseTotal
exists $d->{'gContact:systemGroup'} ? : 0 0 0
225 : (),
226 };
227 }
228 0 return @groups;
229 }
230  
231 0 ▶sub get_group {
Subroutine get_group: not called CC=1 SCAR=6.9
Pod documented
232 0 my ( $self, $id ) = @_;
233  
234 0 warn "This method is deprecated and will be removed shortly";
235 0 my $group = $self->new_group( id => $id )->retrieve;
236 0 my $data = $group->raw_data_for_backwards_compability;
237 0 return $data;
238 }
239  
240 0 ▶sub _create_or_update_group {
Subroutine _create_or_update_group: not called CC=2 SCAR=17.9
241 0 my ( $self, $group, $data ) = @_;
242  
243 0 $group->title( $data->{title} );
244 0 ▶ if ( $group->create_or_update ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($group->create_or_update) 0 0 0
245 0 return 1;
246 }
247 0 return 0;
248 }
249  
250 0 ▶sub create_group {
Subroutine create_group: not called CC=2 SCAR=17.9
Pod documented
251 0 my $self = shift;
252 0 ▶ my $data = scalar @_ % 2 ? shift : {@_};
Branch: 1 branch
BranchTrueFalseTotal
scalar @_ % 2 ? : 0 0 0
253  
254 0 warn "This method is deprecated and will be removed shortly";
255 0 my $group = $self->new_group;
256 0 return $self->_create_or_update_group( $group, $data );
257 }
258  
259 0 ▶sub update_group {
Subroutine update_group: not called CC=1 SCAR=6.9
Pod documented
260 0 my ( $self, $id, $args ) = @_;
261  
262 0 warn "This method is deprecated and will be removed shortly";
263 0 my $g = $self->new_group( id => $id )->retrieve;
264 0 return $self->_create_or_update_group( $g, $args );
265 }
266  
267 0 ▶sub delete_group {
Subroutine delete_group: not called CC=1 SCAR=6.9
Pod documented
268 0 my ( $self, $id ) = @_;
269  
270 0 warn "This method is deprecated and will be removed shortly";
271 0 $self->new_group( id => $id )->delete;
272 }
273  
274 17 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
275 17 __PACKAGE__->meta->make_immutable;
276 17 1;
277 __END__
« Contacts/Server.pm ↑ Summary Contacts/Type/Rel.pm »