line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
9
|
|
|
9
|
|
55
|
use strict; |
|
9
|
|
|
|
|
41
|
|
|
9
|
|
|
|
|
377
|
|
2
|
9
|
|
|
9
|
|
65
|
use warnings; |
|
9
|
|
|
|
|
25
|
|
|
9
|
|
|
|
|
446
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package Net::Google::Code::Issue::Util; |
5
|
9
|
|
|
9
|
|
52
|
use Net::Google::Code::Role::HTMLTree; |
|
9
|
|
|
|
|
18
|
|
|
9
|
|
|
|
|
250
|
|
6
|
|
|
|
|
|
|
|
7
|
9
|
|
|
9
|
|
1474
|
use DateTime; |
|
9
|
|
|
|
|
163231
|
|
|
9
|
|
|
|
|
280
|
|
8
|
9
|
|
|
9
|
|
10509
|
use XML::TreePP; |
|
9
|
|
|
|
|
70788
|
|
|
9
|
|
|
|
|
12861
|
|
9
|
|
|
|
|
|
|
my $tpp = XML::TreePP->new; |
10
|
|
|
|
|
|
|
$tpp->set( output_encoding => 'UTF-8' ); |
11
|
|
|
|
|
|
|
$tpp->set( utf8_flag => 1 ); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub write_xml { |
14
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
15
|
0
|
|
|
|
|
0
|
return $tpp->write(shift); |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub translate_from_xml { |
20
|
31
|
|
|
31
|
1
|
57
|
my $class = shift; |
21
|
31
|
|
|
|
|
51
|
my $ref = shift; |
22
|
31
|
50
|
|
|
|
99
|
return unless $ref; |
23
|
31
|
|
|
|
|
87
|
my %args = @_; |
24
|
31
|
50
|
|
|
|
190
|
die "invalid type: $args{type}" unless $args{type} =~ /^(issue|comment)$/; |
25
|
387
|
|
|
|
|
394
|
%$ref = |
26
|
31
|
|
|
|
|
129
|
map { my $new = $_; $new =~ s/^issues://g; $new => $ref->{$_} } |
|
387
|
|
|
|
|
621
|
|
|
387
|
|
|
|
|
1211
|
|
27
|
|
|
|
|
|
|
keys %$ref; |
28
|
|
|
|
|
|
|
|
29
|
31
|
|
|
|
|
216
|
for my $k ( keys %$ref ) { |
30
|
387
|
100
|
|
|
|
2812
|
if ( $k eq 'id' ) { |
31
|
31
|
100
|
|
|
|
78
|
if ( $args{type} eq 'issue' ) { |
|
|
50
|
|
|
|
|
|
32
|
22
|
50
|
|
|
|
157
|
$ref->{id} = $1 if $ref->{id} =~ /(\d+)$/; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
elsif ( $args{type} eq 'comment' ) { |
35
|
9
|
50
|
|
|
|
71
|
$ref->{sequence} = $1 if $ref->{id} =~ /(\d+)$/; |
36
|
9
|
|
|
|
|
20
|
delete $ref->{id}; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
} |
39
|
387
|
100
|
|
|
|
675
|
if ( $k eq 'title' ) { |
40
|
31
|
100
|
|
|
|
87
|
if ( $args{type} eq 'issue' ) { |
41
|
22
|
|
|
|
|
58
|
$ref->{summary} = $ref->{$k}; |
42
|
22
|
|
|
|
|
37
|
delete $ref->{$k}; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
} |
45
|
387
|
100
|
|
|
|
1800
|
if ( $k eq 'author' ) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
46
|
31
|
100
|
|
|
|
121
|
if ( $args{type} eq 'issue' ) { |
|
|
50
|
|
|
|
|
|
47
|
22
|
|
|
|
|
84
|
$ref->{reporter} = $ref->{$k}->{name}; |
48
|
22
|
|
|
|
|
80
|
delete $ref->{author}; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
elsif ( $args{type} eq 'comment' ) { |
51
|
9
|
|
|
|
|
40
|
$ref->{author} = $ref->{$k}->{name}; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
elsif ( $k eq 'content' ) { |
55
|
22
|
|
|
|
|
24
|
my $text; |
56
|
22
|
50
|
|
|
|
83
|
if ( $ref->{$k}{-type} eq 'html' ) { |
57
|
22
|
|
50
|
|
|
211
|
my $tree = |
58
|
|
|
|
|
|
|
Net::Google::Code::Role::HTMLTree->html_tree( html => '' |
59
|
|
|
|
|
|
|
. ( $ref->{$k}->{'#text'} || '' ) |
60
|
|
|
|
|
|
|
. '' ); |
61
|
22
|
50
|
|
|
|
118
|
$text = $tree->as_text if $tree; |
62
|
22
|
|
|
|
|
3556
|
$tree->delete; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
else { |
65
|
0
|
|
|
|
|
0
|
$text = $ref->{$k}->{'#text'}; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
22
|
50
|
|
|
|
5373
|
$text =~ s/\s+$// if $text; |
69
|
|
|
|
|
|
|
|
70
|
22
|
50
|
|
|
|
81
|
if ( $args{type} eq 'issue' ) { |
|
|
0
|
|
|
|
|
|
71
|
22
|
|
|
|
|
59
|
$ref->{description} = $text; |
72
|
22
|
|
|
|
|
92
|
delete $ref->{$k}; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
elsif ( $args{type} eq 'comment' ) { |
75
|
0
|
|
|
|
|
0
|
$ref->{content} = $text; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
elsif ( $k eq 'published' ) { |
79
|
31
|
100
|
|
|
|
92
|
if ( $args{type} eq 'issue' ) { |
|
|
50
|
|
|
|
|
|
80
|
22
|
|
|
|
|
64
|
$ref->{reported} = $class->datetime_from_string( $ref->{$k} ); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
elsif ( $args{type} eq 'comment' ) { |
83
|
9
|
|
|
|
|
27
|
$ref->{date} = $class->datetime_from_string( $ref->{$k} ); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
elsif ( $k eq 'updated' ) { |
87
|
31
|
|
|
|
|
106
|
$ref->{$k} = $class->datetime_from_string( $ref->{$k} ); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
elsif ( $k eq 'owner' ) { |
90
|
22
|
|
|
|
|
39
|
my $tmp = {}; |
91
|
22
|
|
|
|
|
37
|
my $value = $ref->{$k}; |
92
|
22
|
|
|
|
|
86
|
$ref->{$k} = $value->{'issues:username'}; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
elsif ( $k eq 'cc' ) { |
95
|
2
|
50
|
|
|
|
12
|
my @cc = ref $ref->{$k} eq 'ARRAY' ? @{ $ref->{$k} } : $ref->{$k}; |
|
0
|
|
|
|
|
0
|
|
96
|
2
|
|
|
|
|
4
|
$ref->{$k} = []; |
97
|
2
|
|
|
|
|
7
|
for my $cc (@cc) { |
98
|
2
|
|
|
|
|
5
|
push @{$ref->{$k}}, $cc->{'issues:username'}; |
|
2
|
|
|
|
|
14
|
|
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
elsif ( $k eq 'label' ) { |
102
|
22
|
100
|
|
|
|
78
|
$ref->{labels} = |
103
|
|
|
|
|
|
|
ref $ref->{$k} eq 'ARRAY' ? $ref->{$k} : [ $ref->{$k} ]; |
104
|
22
|
|
|
|
|
50
|
delete $ref->{label}; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
elsif ( $k eq 'updates' ) { |
107
|
5
|
|
|
|
|
9
|
my $tmp = {}; |
108
|
5
|
|
|
|
|
12
|
my $value = $ref->{updates}; |
109
|
5
|
|
|
|
|
47
|
for my $k ( keys %$value ) { |
110
|
5
|
|
|
|
|
8
|
my $v = $value->{$k}; |
111
|
5
|
|
|
|
|
18
|
$k =~ s/^issues://; |
112
|
5
|
100
|
|
|
|
32
|
$k .= 's' if $k eq 'label'; |
113
|
5
|
|
|
|
|
13
|
$k =~ s/Update$//; |
114
|
5
|
|
|
|
|
19
|
$tmp->{$k} = $v; |
115
|
|
|
|
|
|
|
} |
116
|
5
|
100
|
100
|
|
|
28
|
if ( exists $tmp->{labels} && !ref $tmp->{labels} ) { |
117
|
2
|
|
|
|
|
35
|
$tmp->{labels} = [ $tmp->{labels} ]; |
118
|
|
|
|
|
|
|
} |
119
|
5
|
|
|
|
|
16
|
$ref->{$k} = $tmp; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
} |
122
|
31
|
|
|
|
|
348
|
return $ref; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub translate_to_xml { |
126
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
127
|
0
|
|
|
|
|
0
|
my $ref = shift; |
128
|
0
|
|
|
|
|
0
|
my %args = @_; |
129
|
|
|
|
|
|
|
|
130
|
0
|
|
|
|
|
0
|
my %entry; |
131
|
0
|
0
|
|
|
|
0
|
if ( $args{type} eq 'create' ) { |
|
|
0
|
|
|
|
|
|
132
|
0
|
|
|
|
|
0
|
for my $key ( keys %$ref ) { |
133
|
0
|
0
|
|
|
|
0
|
if ( $key eq 'author' ) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
134
|
0
|
|
|
|
|
0
|
$entry{'author'}{'name'} = $ref->{$key}; |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
elsif ( $key eq 'comment' ) { |
137
|
0
|
|
|
|
|
0
|
$entry{'content'} = $ref->{$key}; |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
elsif ( $key eq 'summary' ) { |
140
|
0
|
|
|
|
|
0
|
$entry{'title'} = $ref->{$key}; |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
elsif ( $key eq 'cc' ) { |
143
|
0
|
|
|
|
|
0
|
$entry{'issues:cc'}{'issues:username'} = $ref->{$key}; |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
elsif ( $key eq 'owner' ) { |
146
|
0
|
|
|
|
|
0
|
$entry{'issues:owner'}{'issues:username'} = $ref->{$key}; |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
elsif ( $key eq 'labels' ) { |
149
|
0
|
|
|
|
|
0
|
$entry{'issues:label'} = $ref->{$key}; |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
else { |
152
|
0
|
|
|
|
|
0
|
$entry{"issues:$key"} = $ref->{$key}; |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
elsif ( $args{type} eq 'update' ) { |
157
|
0
|
|
|
|
|
0
|
for my $key ( keys %$ref ) { |
158
|
0
|
0
|
|
|
|
0
|
if ( $key eq 'author' ) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
159
|
0
|
|
|
|
|
0
|
$entry{'author'}{'name'} = $ref->{$key}; |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
elsif ( $key eq 'comment' ) { |
162
|
0
|
|
|
|
|
0
|
$entry{'content'} = $ref->{$key}; |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
elsif ( $key eq 'cc' ) { |
165
|
0
|
|
|
|
|
0
|
$entry{'issues:updates'}{'issues:ccUpdate'} = $ref->{$key}; |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
elsif ( $key eq 'owner' ) { |
168
|
0
|
|
|
|
|
0
|
$entry{'issues:updates'}{'issues:ownerUpdate'} = $ref->{$key}; |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
elsif ( $key eq 'labels' ) { |
171
|
0
|
|
|
|
|
0
|
$entry{'issues:updates'}{'issues:label'} = $ref->{$key}; |
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
else { |
174
|
0
|
|
|
|
|
0
|
$entry{'issues:updates'}{"issues:$key"} = $ref->{$key}; |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
} |
178
|
|
|
|
|
|
|
else { |
179
|
0
|
|
|
|
|
0
|
die "invalid type: $args{type}"; |
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
|
182
|
0
|
|
|
|
|
0
|
$ref = { entry => \%entry }; |
183
|
0
|
|
|
|
|
0
|
my $xml = Net::Google::Code::Issue::Util->write_xml($ref); |
184
|
0
|
|
|
|
|
0
|
$xml =~ |
185
|
|
|
|
|
|
|
s!!!; |
186
|
0
|
|
|
|
|
0
|
return $xml; |
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
sub datetime_from_string { |
190
|
62
|
|
|
62
|
1
|
81
|
my $class = shift; |
191
|
62
|
|
|
|
|
82
|
my $string = shift; |
192
|
62
|
50
|
|
|
|
136
|
return unless $string; |
193
|
62
|
50
|
|
|
|
425
|
if ( $string =~ |
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
|
50
|
|
|
|
438
|
my $dt = DateTime->new( |
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
|
|
|
|
|
16049
|
$dt->set_time_zone( 'UTC' ); |
208
|
|
|
|
|
|
|
} |
209
|
|
|
|
|
|
|
} |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
1; |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
__END__ |