Contacts/Roles/CRUD.pm

filter: Statementstmt 32.6% 15 / 46 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 33.3% 3 / 9 Podpod 0.0% 0 / 6 totaltotal 26.0% 18 / 69 CC 5 SCAR 14.4
CC
5
Cov
28%
create_or_update
6.0
retrieve
6.0
update
6.0
CRAP 4.2
« Contacts/Type/Rel.pm ↑ Summary Contacts/InternalTypes.pm »
1 package WWW::Google::Contacts::Roles::CRUD;
2 {
3 17 $WWW::Google::Contacts::Roles::CRUD::VERSION = '0.38';
4 }
5  
6 17 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 17 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 17 ▶use WWW::Google::Contacts::Data;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 17 requires 'create_url';
11  
12 17 has raw_data_for_backwards_compability => ( is => 'rw' );
13 17 has server => ( is => 'ro', required => 1 );
14  
15 sub as_xml {
16 0 ▶ my $self = shift;
Subroutine as_xml: not called CC=1 SCAR=6.9
Pod undocumented
17 my $entry = {
18 entry => {
19 'xmlns' => 'http://www.w3.org/2005/Atom',
20 'xmlns:gd' => 'http://schemas.google.com/g/2005',
21 'xmlns:gContact' => 'http://schemas.google.com/contact/2008',
22 0 %{ $self->to_xml_hashref },
23 },
24 };
25 0 my $xml = WWW::Google::Contacts::Data->encode_xml($entry);
26 0 return $xml;
27 }
28  
29 sub create_or_update {
30 0 ▶ my $self = shift;
Subroutine create_or_update: not called CC=2 SCAR=17.9
Pod undocumented
31 0 ▶ if ( $self->has_id ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_id) { } 0 0 0
32 0 return $self->update;
33 }
34 else {
35 0 return $self->create;
36 }
37 }
38  
39 sub create {
40 0 ▶ my $self = shift;
Subroutine create: not called CC=1 SCAR=6.9
Pod undocumented
41  
42 0 my $xml = $self->as_xml;
43 0 my $res =
44 $self->server->post( $self->create_url, undef, 'application/atom+xml',
45 $xml );
46 0 my $data = WWW::Google::Contacts::Data->decode_xml( $res->content );
47 0 $self->set_from_server($data);
48 0 1;
49 }
50  
51 sub retrieve {
52 0 ▶ my $self = shift;
Subroutine retrieve: not called CC=2 SCAR=17.9
Pod undocumented
53 0 ▶ croak "No id set" unless $self->id;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->id 0 0 0
54  
55 0 my $res = $self->server->get( $self->id );
56 0 my $data = WWW::Google::Contacts::Data->decode_xml( $res->content );
57 0 $self->raw_data_for_backwards_compability($data);
58 0 $self->set_from_server($data);
59 0 $self;
60 }
61  
62 sub update {
63 0 ▶ my $self = shift;
Subroutine update: not called CC=2 SCAR=17.9
Pod undocumented
64 0 ▶ croak "No id set" unless $self->id;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->id 0 0 0
65  
66 0 my $xml = $self->as_xml;
67 0 $self->server->put( $self->id, $self->etag, 'application/atom+xml', $xml );
68 0 $self;
69 }
70  
71 sub delete {
72 0 ▶ my $self = shift;
Subroutine delete: not called CC=2 SCAR=17.9
Pod undocumented
73 0 ▶ croak "No id set" unless $self->id;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->id 0 0 0
74  
75 0 $self->server->delete( $self->id, $self->etag );
76 0 1;
77 }
78  
79 17 1;
« Contacts/Type/Rel.pm ↑ Summary Contacts/InternalTypes.pm »