Contacts/Base.pm

filter: Statementstmt 58.2% 46 / 79 Branchbran 46.6% 14 / 30 Conditioncond 33.3% 5 / 15 MC/DCmcdc 11.1% 1 / 9 Subroutinesub 66.6% 8 / 12 Podpod 0.0% 0 / 4 totaltotal 49.6% 74 / 149 CC 25 SCAR 29.0
CC
25
Cov
52%
get_xml_key
42.0
to_xml_hashref
22.3
set_from_server
20.0
CRAP 18.3
« Contacts/Roles/List.pm ↑ Summary Contacts/Contact.pm »
1 package WWW::Google::Contacts::Base;
2 {
3 20 $WWW::Google::Contacts::Base::VERSION = '0.39';
4 }
5  
6 20 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 20 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 20 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 20 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 51 ▶sub xml_attributes {
Subroutine xml_attributes: called CC=1 SCAR=0.0
Pod undocumented
12 51 my $self = shift;
13 51 return grep { $_->does('XmlField') } $self->meta->get_all_attributes;
14 }
15  
16 0 ▶sub get_xml_key {
Subroutine get_xml_key: not called CC=6 SCAR=37.4
Pod undocumented
17 0 my ( $self, $field ) = @_;
18  
19 0 foreach my $attr ( $self->xml_attributes ) {
20 0 my $name = $attr->name;
21 0 my $val = $self->$name;
22 0 ▶ if ( $name eq $field ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($name eq $field) { } 0 0 0
elsif (builtin::blessed($val) and $val->can('to_xml_hashref')) { } 0 0 0
23 0 return $attr->xml_key;
24 }
25 ▶ elsif ( blessed($val) and $val->can("to_xml_hashref") ) {
Condition0%0/3
builtin::blessed($val) and $val->can("to_xml_hashref")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($val) and $val->can("to_xml_hashref")
builtin::blessed($val) $val->can("to_xml_hashref")
Truth table0%0/3
A and B
A= builtin::blessed($val)B= $val->can("to_xml_hashref")
ABresult
0X0
100
111
26 0 my $recurse = $val->get_xml_key($field);
27 0 ▶ if ($recurse) {
Branch: 1 branch
BranchTrueFalseTotal
if ($recurse) 0 0 0
28 0 my $parent = $attr->xml_key;
29 0 return { $parent => $recurse };
30 }
31 }
32 }
33 0 return undef;
34 }
35  
36 3 ▶sub to_xml_hashref {
Subroutine to_xml_hashref: called CC=13 SCAR=31.1
Pod undocumented
37 3 my $self = shift;
38  
39 3 my $to_return = {};
40 3 foreach my $attr ( $self->xml_attributes ) {
41 9 my $incl = $attr->include_in_xml;
42 9 ▶ next unless $self->$incl;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->$incl 3 6 9
43  
44 6 my $predicate = $attr->predicate;
45  
46 next
47 6 ▶ if defined $predicate
Branch: 1 branch
BranchTrueFalseTotal
if defined $predicate and not $self->$predicate and not $attr->is_lazy 0 6 6
Condition33%2/6
defined $predicate and not $self->$predicate and not $attr->is_lazy
!ll&&!rl&&r
600
defined $predicate and not $self->$predicate
!ll&&!rl&&r
060
MC/DC0%0/3
defined $predicate and not $self->$predicate and not $attr->is_lazy
defined $predicate not $self->$predicate not $attr->is_lazy
Truth table25%1/4
A and not(B) and not(C)
A= defined $predicateB= not $self->$predicateC= not $attr->is_lazy
ABCresult
0XX0
10X0
1100
1111
48 and not $self->$predicate
49 and not $attr->is_lazy;
50  
51 6 my $name = $attr->name;
52 6 my $val = $self->$name;
53  
54 6 ▶ next if ( not $val );
Branch: 1 branch
BranchTrueFalseTotal
unless $val 0 6 6
55  
56 $to_return->{ $attr->xml_key } =
57 ( blessed($val) and $val->can("to_xml_hashref") )
58 ? $val->to_xml_hashref
59 : ( ref($val) and ref($val) eq 'ARRAY' )
60 0 ▶ ? [ map { $_->to_xml_hashref } @{$val} ]
Branch: 1 branch
BranchTrueFalseTotal
$attr->has_to_xml ? : 0 4 4
61 0 ▶ : $attr->has_to_xml ? do { my $code = $attr->to_xml; &$code($val) }
Branch: 3 branches
BranchTrueFalseTotal
builtin::blessed($val) && $val->can('to_xml_hashref') ? : 2 4 6
ref $val && ref $val eq 'ARRAY' ? : 0 4 4
$attr->is_element ? : 0 4 4
Condition50%3/6
builtin::blessed($val) and $val->can("to_xml_hashref")
!ll&&!rl&&r
402
ref $val and ref $val eq "ARRAY"
!ll&&!rl&&r
400
MC/DC50%1/2
builtin::blessed($val) and $val->can("to_xml_hashref")
builtin::blessed($val) $val->can("to_xml_hashref")
MC/DC0%0/2
ref $val and ref $val eq "ARRAY"
ref $val ref $val eq "ARRAY"
Truth table66%2/3
A and B
A= builtin::blessed($val)B= $val->can("to_xml_hashref")
ABresult
0X0
100
111
Truth table33%1/3
A and B
A= ref $valB= ref $val eq "ARRAY"
ABresult
0X0
100
111
62 : $attr->is_element ? [$val]
63 : $val;
64 }
65 3 return $to_return;
66 }
67  
68 0 ▶sub set_from_server {
Subroutine set_from_server: not called CC=4 SCAR=30.0
Pod undocumented
69 0 my ( $self, $data ) = @_;
70  
71 0 foreach my $attr ( $self->xml_attributes ) {
72 0 ▶ if ( defined $data->{ $attr->xml_key } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$data{$attr->xml_key}) 0 0 0
73 0 ▶ if ( my $writer = $attr->writer ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $writer = $attr->writer) { } 0 0 0
74  
75 # write attributes that are read only to the user
76 0 $self->$writer( $data->{ $attr->xml_key } );
77 }
78 else {
79 0 my $name = $attr->name;
80 0 ▶ try {
Subroutine __ANON__: not called CC=1 SCAR=6.9
81 0 $self->$name( $data->{ $attr->xml_key } );
82 }
83 0 ▶ catch {
Subroutine __ANON__: not called CC=1 SCAR=6.9
84 0 my @err = split m{\n}, $_;
85 0 print "\nERROR - Failed to set attribute\n";
86 0 print "-------------------------------\n";
87 0 print "Attribute: " . $name . "\n";
88 0 print "Value: " . Dumper $data->{ $attr->xml_key };
89 0 print "Error: " . $err[0] . "\n";
90 0 print
91 "\nPlease include the above in an email bug report to magnus\@erixzon.com\n";
92 0 print
93 "Remove personal content in the 'value' hash, but please leave the structure intact.\n\n";
94 0 die "\n";
95 0 };
96 }
97 }
98 }
99 0 return $self;
100 }
101  
102 48 ▶around BUILDARGS => sub {
Subroutine __ANON__: called CC=5 SCAR=16.1
103 48 my $orig = shift;
104 48 my $class = shift;
105  
106 48 ▶ return $class->$orig() unless (@_);
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 48 48
107  
108 # let's see if we need to mangle xml fields
109 48 my $data;
110 48 ▶ if ( @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) { } 31 17 48
111 31 $data = {@_};
112 }
113 else {
114 17 $data = shift @_;
115 }
116  
117 48 foreach my $attr ( $class->xml_attributes ) {
118 208 ▶ if ( defined $data->{ $attr->xml_key } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$data{$attr->xml_key}) 15 193 208
119 15 $data->{ $attr->name } = delete $data->{ $attr->xml_key };
120 }
121 }
122 48 return $class->$orig($data);
123 20 };
124  
125 20 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
126 20 __PACKAGE__->meta->make_immutable;
127 20 1;
128 __END__
« Contacts/Roles/List.pm ↑ Summary Contacts/Contact.pm »