Code/Issue/Util.pm

filter: Statementstmt 72.4% 84 / 116 Branchbran 53.2% 49 / 92 Conditioncond 80.0% 4 / 5 MC/DCmcdc 66.6% 2 / 3 Subroutinesub 77.7% 7 / 9 Podpod 100% 4 / 4 totaltotal 65.5% 150 / 229 CC 54 SCAR 45.4
CC
54
Cov
64%
translate_to_xml
272.0
translate_from_xml
39.7
datetime_from_string
4.2
CRAP 93.6
« Code/Issue.pm ↑ Summary Code/Role/HTMLTree.pm »
1 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package Net::Google::Code::Issue::Util;
5 9 ▶use Net::Google::Code::Role::HTMLTree;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 9 ▶use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 9 ▶use XML::TreePP;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 9 my $tpp = XML::TreePP->new;
10 9 $tpp->set( output_encoding => 'UTF-8' );
11 9 $tpp->set( utf8_flag => 1 );
12  
13 0 ▶sub write_xml {
Subroutine write_xml: not called CC=1 SCAR=6.9
Pod documented
14 0 my $self = shift;
15 0 return $tpp->write(shift);
16 }
17  
18  
19 31 ▶sub translate_from_xml {
Subroutine translate_from_xml: called CC=36 SCAR=36.8
Pod documented
20 31 my $class = shift;
21 31 my $ref = shift;
22 31 ▶ return unless $ref;
Branch: 1 branch
BranchTrueFalseTotal
unless $ref 0 31 31
23 31 my %args = @_;
24 31 ▶ die "invalid type: $args{type}" unless $args{type} =~ /^(issue|comment)$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"type"} =~ /^(issue|comment)$/ 0 31 31
25 %$ref =
26 31 map { my $new = $_; $new =~ s/^issues://g; $new => $ref->{$_} }
27 keys %$ref;
28  
29 31 for my $k ( keys %$ref ) {
30 387 ▶ if ( $k eq 'id' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k eq "id") 31 356 387
31 31 ▶ if ( $args{type} eq 'issue' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($args{'type'} eq 'issue') { } 22 9 31
elsif ($args{'type'} eq 'comment') { } 9 0 9
32 22 ▶ $ref->{id} = $1 if $ref->{id} =~ /(\d+)$/;
Branch: 1 branch
BranchTrueFalseTotal
if $ref->{"id"} =~ /(\d+)$/ 22 0 22
33 }
34 elsif ( $args{type} eq 'comment' ) {
35 9 ▶ $ref->{sequence} = $1 if $ref->{id} =~ /(\d+)$/;
Branch: 1 branch
BranchTrueFalseTotal
if $ref->{"id"} =~ /(\d+)$/ 9 0 9
36 9 delete $ref->{id};
37 }
38 }
39 387 ▶ if ( $k eq 'title' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k eq "title") 31 356 387
40 31 ▶ if ( $args{type} eq 'issue' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"type"} eq "issue") 22 9 31
41 22 $ref->{summary} = $ref->{$k};
42 22 delete $ref->{$k};
43 }
44 }
45 387 ▶ if ( $k eq 'author' ) {
Branch: 8 branches
BranchTrueFalseTotal
if ($k eq 'author') { } 31 356 387
elsif ($k eq 'content') { } 22 334 356
elsif ($k eq 'published') { } 31 303 334
elsif ($k eq 'updated') { } 31 272 303
elsif ($k eq 'owner') { } 22 250 272
elsif ($k eq 'cc') { } 2 248 250
elsif ($k eq 'label') { } 22 226 248
elsif ($k eq 'updates') { } 5 221 226
46 31 ▶ if ( $args{type} eq 'issue' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($args{'type'} eq 'issue') { } 22 9 31
elsif ($args{'type'} eq 'comment') { } 9 0 9
47 22 $ref->{reporter} = $ref->{$k}->{name};
48 22 delete $ref->{author};
49 }
50 elsif ( $args{type} eq 'comment' ) {
51 9 $ref->{author} = $ref->{$k}->{name};
52 }
53 }
54 elsif ( $k eq 'content' ) {
55 22 my $text;
56 22 ▶ if ( $ref->{$k}{-type} eq 'html' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ref->{$k}{'-type'} eq 'html') { } 22 0 22
57 my $tree =
58 Net::Google::Code::Role::HTMLTree->html_tree( html => '<pre>'
59 22 ▶ . ( $ref->{$k}->{'#text'} || '' )
Condition50%1/2
$ref->{$k}{'#text'} || ''
l!l
220
MC/DC0%0/1
$ref->{$k}{'#text'} || ''
$ref->{$k}{'#text'}
Truth table50%1/2
A
A= $ref->{$k}{'#text'}
Aresult
11
00
60 . '</pre>' );
61 22 ▶ $text = $tree->as_text if $tree;
Branch: 1 branch
BranchTrueFalseTotal
if $tree 22 0 22
62 22 $tree->delete;
63 }
64 else {
65 0 $text = $ref->{$k}->{'#text'};
66 }
67  
68 22 ▶ $text =~ s/\s+$// if $text;
Branch: 1 branch
BranchTrueFalseTotal
if $text 22 0 22
69  
70 22 ▶ if ( $args{type} eq 'issue' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($args{'type'} eq 'issue') { } 22 0 22
elsif ($args{'type'} eq 'comment') { } 0 0 0
71 22 $ref->{description} = $text;
72 22 delete $ref->{$k};
73 }
74 elsif ( $args{type} eq 'comment' ) {
75 0 $ref->{content} = $text;
76 }
77 }
78 elsif ( $k eq 'published' ) {
79 31 ▶ if ( $args{type} eq 'issue' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($args{'type'} eq 'issue') { } 22 9 31
elsif ($args{'type'} eq 'comment') { } 9 0 9
80 22 $ref->{reported} = $class->datetime_from_string( $ref->{$k} );
81 }
82 elsif ( $args{type} eq 'comment' ) {
83 9 $ref->{date} = $class->datetime_from_string( $ref->{$k} );
84 }
85 }
86 elsif ( $k eq 'updated' ) {
87 31 $ref->{$k} = $class->datetime_from_string( $ref->{$k} );
88 }
89 elsif ( $k eq 'owner' ) {
90 22 my $tmp = {};
91 22 my $value = $ref->{$k};
92 22 $ref->{$k} = $value->{'issues:username'};
93 }
94 elsif ( $k eq 'cc' ) {
95 0 ▶ my @cc = ref $ref->{$k} eq 'ARRAY' ? @{ $ref->{$k} } : $ref->{$k};
Branch: 1 branch
BranchTrueFalseTotal
ref $ref->{$k} eq 'ARRAY' ? : 0 2 2
96 2 $ref->{$k} = [];
97 2 for my $cc (@cc) {
98 2 push @{$ref->{$k}}, $cc->{'issues:username'};
99 }
100 }
101 elsif ( $k eq 'label' ) {
102 $ref->{labels} =
103 22 ▶ ref $ref->{$k} eq 'ARRAY' ? $ref->{$k} : [ $ref->{$k} ];
Branch: 1 branch
BranchTrueFalseTotal
ref $ref->{$k} eq 'ARRAY' ? : 19 3 22
104 22 delete $ref->{label};
105 }
106 elsif ( $k eq 'updates' ) {
107 5 my $tmp = {};
108 5 my $value = $ref->{updates};
109 5 for my $k ( keys %$value ) {
110 5 my $v = $value->{$k};
111 5 $k =~ s/^issues://;
112 5 ▶ $k .= 's' if $k eq 'label';
Branch: 1 branch
BranchTrueFalseTotal
if $k eq "label" 3 2 5
113 5 $k =~ s/Update$//;
114 5 $tmp->{$k} = $v;
115 }
116 5 ▶ if ( exists $tmp->{labels} && !ref $tmp->{labels} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $tmp->{"labels"} and not ref $tmp->{"labels"}) 2 3 5
Condition100%3/3
exists $tmp->{"labels"} and not ref $tmp->{"labels"}
!ll&&!rl&&r
212
MC/DC100%2/2
exists $tmp->{"labels"} and not ref $tmp->{"labels"}
exists $tmp->{"labels"} not ref $tmp->{"labels"}
Truth table100%3/3
A and not(B)
A= exists $tmp->{"labels"}B= not ref $tmp->{"labels"}
ABresult
0X0
100
111
117 2 $tmp->{labels} = [ $tmp->{labels} ];
118 }
119 5 $ref->{$k} = $tmp;
120 }
121 }
122 31 return $ref;
123 }
124  
125 0 ▶sub translate_to_xml {
Subroutine translate_to_xml: not called CC=16 SCAR=56.1
Pod documented
126 0 my $self = shift;
127 0 my $ref = shift;
128 0 my %args = @_;
129  
130 0 my %entry;
131 0 ▶ if ( $args{type} eq 'create' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($args{'type'} eq 'create') { } 0 0 0
elsif ($args{'type'} eq 'update') { } 0 0 0
132 0 for my $key ( keys %$ref ) {
133 0 ▶ if ( $key eq 'author' ) {
Branch: 6 branches
BranchTrueFalseTotal
if ($key eq 'author') { } 0 0 0
elsif ($key eq 'comment') { } 0 0 0
elsif ($key eq 'summary') { } 0 0 0
elsif ($key eq 'cc') { } 0 0 0
elsif ($key eq 'owner') { } 0 0 0
elsif ($key eq 'labels') { } 0 0 0
134 0 $entry{'author'}{'name'} = $ref->{$key};
135 }
136 elsif ( $key eq 'comment' ) {
137 0 $entry{'content'} = $ref->{$key};
138 }
139 elsif ( $key eq 'summary' ) {
140 0 $entry{'title'} = $ref->{$key};
141 }
142 elsif ( $key eq 'cc' ) {
143 0 $entry{'issues:cc'}{'issues:username'} = $ref->{$key};
144 }
145 elsif ( $key eq 'owner' ) {
146 0 $entry{'issues:owner'}{'issues:username'} = $ref->{$key};
147 }
148 elsif ( $key eq 'labels' ) {
149 0 $entry{'issues:label'} = $ref->{$key};
150 }
151 else {
152 0 $entry{"issues:$key"} = $ref->{$key};
153 }
154 }
155 }
156 elsif ( $args{type} eq 'update' ) {
157 0 for my $key ( keys %$ref ) {
158 0 ▶ if ( $key eq 'author' ) {
Branch: 5 branches
BranchTrueFalseTotal
if ($key eq 'author') { } 0 0 0
elsif ($key eq 'comment') { } 0 0 0
elsif ($key eq 'cc') { } 0 0 0
elsif ($key eq 'owner') { } 0 0 0
elsif ($key eq 'labels') { } 0 0 0
159 0 $entry{'author'}{'name'} = $ref->{$key};
160 }
161 elsif ( $key eq 'comment' ) {
162 0 $entry{'content'} = $ref->{$key};
163 }
164 elsif ( $key eq 'cc' ) {
165 0 $entry{'issues:updates'}{'issues:ccUpdate'} = $ref->{$key};
166 }
167 elsif ( $key eq 'owner' ) {
168 0 $entry{'issues:updates'}{'issues:ownerUpdate'} = $ref->{$key};
169 }
170 elsif ( $key eq 'labels' ) {
171 0 $entry{'issues:updates'}{'issues:label'} = $ref->{$key};
172 }
173 else {
174 0 $entry{'issues:updates'}{"issues:$key"} = $ref->{$key};
175 }
176 }
177 }
178 else {
179 0 die "invalid type: $args{type}";
180 }
181  
182 0 $ref = { entry => \%entry };
183 0 my $xml = Net::Google::Code::Issue::Util->write_xml($ref);
184 0 $xml =~
185 s!<entry>!<entry xmlns='http://www.w3.org/2005/Atom' xmlns:issues='http://schemas.google.com/projecthosting/issues/2009'>!;
186 0 return $xml;
187 }
188  
189 62 ▶sub datetime_from_string {
Subroutine datetime_from_string: called CC=4 SCAR=14.5
Pod documented
190 62 my $class = shift;
191 62 my $string = shift;
192 62 ▶ return unless $string;
Branch: 1 branch
BranchTrueFalseTotal
unless $string 0 62 62
193 62 ▶ if ( $string =~
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ /(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.000)?(Z|[+-]\d{2}:\d{2})/) 62 0 62
194 /(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.000)?(Z|[+-]\d{2}:\d{2})/ )
195 {
196  
197 # 2009-06-01T13:00:10Z
198 62 ▶ my $dt = DateTime->new(
Branch: 1 branch
BranchTrueFalseTotal
$7 eq 'Z' ? : 62 0 62
199 year => $1,
200 month => $2,
201 day => $3,
202 hour => $4,
203 minute => $5,
204 second => $6,
205 time_zone => $7 eq 'Z' ? 'UTC' : $7,
206 );
207 62 $dt->set_time_zone( 'UTC' );
208 }
209 }
210  
211 9 1;
212  
213 __END__
« Code/Issue.pm ↑ Summary Code/Role/HTMLTree.pm »