blib/lib/XML/NewsML_G2/Writer/News_Item.pm

filter: Statementstmt 9.6% 28 / 290 Branchbran 7.4% 7 / 94 Conditioncond 0.0% 0 / 23 MC/DCmcdc 0.0% 0 / 12 Subroutinesub 19.2% 5 / 26 Podpod n/a totaltotal 8.9% 40 / 445 CC 85 SCAR 46.7
CC
85
Cov
9%
_create_content_meta
420.0
_sort_subjects_locations
90.0
_create_subjects_location
72.0
CRAP 106.6
↑ Summary blib/lib/XML/NewsML_G2/Role/Writer/News_Item_Picture.pm »
1 package XML::NewsML_G2::Writer::News_Item;
2  
3 20 ▶use Scalar::Util qw(looks_like_number);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 20 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 20 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 20 extends 'XML::NewsML_G2::Writer';
8  
9 20 has 'news_item',
10 isa => 'XML::NewsML_G2::News_Item',
11 is => 'ro',
12 required => 1;
13  
14 sub _build__root_item {
15 12 ▶ my $self = shift;
Subroutine _build__root_item: called CC=1 SCAR=0.0
16 12 return $self->news_item;
17 }
18  
19 sub _create_rights_info {
20 9 ▶ my ( $self, $root ) = @_;
Subroutine _create_rights_info: called CC=6 SCAR=18.0
21 9 ▶ return unless $self->news_item->copyright_holder;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->news_item->copyright_holder 3 6 9
22  
23 6 my $ri = $self->create_element('rightsInfo');
24  
25 6 $ri->appendChild(
26 my $crh = $self->create_element(
27 'copyrightHolder',
28 _name_text => $self->news_item->copyright_holder
29 )
30 );
31 6 ▶ $crh->setAttribute( 'uri', $self->news_item->copyright_holder->uri )
Branch: 1 branch
BranchTrueFalseTotal
if $self->news_item->copyright_holder->uri 6 0 6
32 if $self->news_item->copyright_holder->uri;
33 6 ▶ if ( my $qcode = $self->news_item->copyright_holder->qcode ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $qcode = $self->news_item->copyright_holder->qcode) 6 0 6
34 6 $self->scheme_manager->add_qcode_or_literal( $crh,
35 'copyright_holder', $qcode );
36 }
37  
38 6 $self->_create_copyright_holder_remoteinfo($crh);
39  
40 6 my $notice = $self->news_item->copyright_holder->notice;
41 6 ▶ $ri->appendChild(
Branch: 1 branch
BranchTrueFalseTotal
if $notice 6 0 6
42 $self->create_element( 'copyrightNotice', _text => $notice ) )
43 if $notice;
44 6 ▶ $ri->appendChild(
Branch: 1 branch
BranchTrueFalseTotal
if $self->news_item->usage_terms 5 1 6
45 $self->create_element(
46 'usageTerms', _text => $self->news_item->usage_terms
47 )
48 ) if $self->news_item->usage_terms;
49  
50 6 $root->appendChild($ri);
51 6 return;
52 }
53  
54 sub _create_hierarchy {
55  
56 # my ($self, $node, $schema) = @_;
57 # code moved to Writer_2_9
58 0 ▶ return;
Subroutine _create_hierarchy: not called CC=1 SCAR=6.9
59 }
60  
61 sub _create_icon {
62  
63 #overwrite me
64 0 ▶ return;
Subroutine _create_icon: not called CC=1 SCAR=6.9
65 }
66  
67 sub _create_subjects_desk {
68 0 ▶ my $self = shift;
Subroutine _create_subjects_desk: not called CC=3 SCAR=24.8
69 0 my @res;
70  
71 0 ▶ push @res, $self->doc->createComment('desks')
Branch: 1 branch
BranchTrueFalseTotal
if $self->news_item->has_desks 0 0 0
72 if $self->news_item->has_desks;
73 0 foreach ( sort { $a->qcode cmp $b->qcode } @{ $self->news_item->desks } )
74 {
75 0 push @res,
76 my $s = $self->create_element(
77 'subject',
78 type => 'cpnat:abstract',
79 _name_text => $_
80 );
81 0 $self->scheme_manager->add_qcode_or_literal( $s, 'desk', $_->qcode );
82 }
83 0 return @res;
84 }
85  
86 sub _create_subjects_storytypes {
87 0 ▶ my $self = shift;
Subroutine _create_subjects_storytypes: not called CC=3 SCAR=24.8
88 0 my @res;
89  
90 push @res, $self->doc->createComment('storytypes')
91 0 ▶ if ( @{ $self->news_item->storytypes } );
Branch: 1 branch
BranchTrueFalseTotal
if @{$self->news_item->storytypes;} 0 0 0
92  
93 0 foreach ( sort { $a->qcode cmp $b->qcode }
94 0 @{ $self->news_item->storytypes } ) {
95 0 push @res,
96 my $s = $self->create_element(
97 'subject',
98 type => 'cpnat:abstract',
99 _name_text => $_
100 );
101 0 $self->scheme_manager->add_qcode_or_literal( $s, 'storytype',
102 $_->qcode );
103 }
104 0 return @res;
105 }
106  
107 sub _create_subjects_media_topic {
108 0 ▶ my $self = shift;
Subroutine _create_subjects_media_topic: not called CC=7 SCAR=40.3
109 0 my @res;
110  
111 0 ▶ push @res, $self->doc->createComment('media topics')
Branch: 1 branch
BranchTrueFalseTotal
if $self->news_item->has_media_topics 0 0 0
112 if $self->news_item->has_media_topics;
113 0 foreach my $mt_qcode ( sort keys %{ $self->news_item->media_topics } ) {
114 0 my $mt = $self->news_item->media_topics->{$mt_qcode};
115 0 ▶ my $why = $mt->direct ? 'why:direct' : 'why:ancestor';
Branch: 1 branch
BranchTrueFalseTotal
$mt->direct ? : 0 0 0
116 0 push @res,
117 my $s = $self->create_element(
118 'subject',
119 type => 'cpnat:abstract',
120 why => $why,
121 _name_text => $mt
122 );
123 0 $self->scheme_manager->add_qcode_or_literal( $s, 'medtop',
124 $mt->qcode );
125 0 foreach my $lang ( sort keys %{ $mt->translations } ) {
126 $s->appendChild(
127 $self->create_element(
128 'name',
129 'xml:lang' => $lang,
130 0 _text => $mt->translations->{$lang}
131 )
132 );
133 }
134 0 ▶ if ( $mt->parent ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mt->parent) 0 0 0
135 0 $s->appendChild( my $b = $self->create_element('broader') );
136 0 $self->scheme_manager->add_qcode_or_literal( $b, 'medtop',
137 $mt->parent->qcode );
138 0 my $hierarchy = $self->_create_hierarchy( $mt, 'medtop' );
139 0 ▶ $b->appendChild($hierarchy) if $hierarchy;
Branch: 1 branch
BranchTrueFalseTotal
if $hierarchy 0 0 0
140 }
141 }
142 0 return @res;
143 }
144  
145 sub _create_subject_concept {
146 0 ▶ my ( $self, $name, $item, $qcode_prefix ) = @_;
Subroutine _create_subject_concept: not called CC=2 SCAR=17.9
147  
148 0 my $elem = $self->create_element( $name, _name_text => $item );
149 0 $self->scheme_manager->add_qcode_or_literal( $elem, $qcode_prefix,
150 $item->qcode );
151 0 foreach my $lang ( sort keys %{ $item->translations } ) {
152 $elem->appendChild(
153 $self->create_element(
154 'name',
155 'xml:lang' => $lang,
156 0 _text => $item->translations->{$lang}
157 )
158 );
159 }
160 0 return $elem;
161 }
162  
163 sub _create_subjects_concepts {
164 0 ▶ my ($self) = @_;
Subroutine _create_subjects_concepts: not called CC=4 SCAR=30.0
165  
166 0 my @res;
167 0 ▶ push @res, $self->doc->createComment('concepts')
Branch: 1 branch
BranchTrueFalseTotal
if $self->news_item->has_concepts 0 0 0
168 if $self->news_item->has_concepts;
169 0 foreach my $concept_uid ( sort keys %{ $self->news_item->concepts } ) {
170 0 my $concept = $self->news_item->concepts->{$concept_uid};
171 0 push @res, my $s = $self->create_element('subject');
172 0 $s->appendChild(
173 $self->_create_subject_concept(
174 'mainConcept', $concept->main, 'medtop'
175 )
176 );
177 0 foreach my $facet_qcode ( sort keys %{ $concept->facets } ) {
178 0 my $facet = $concept->facets->{$facet_qcode};
179 0 my ($facet_cls) = reverse split '::', $facet->meta->name;
180 0 $s->appendChild(
181 $self->_create_subject_concept(
182 'facetConcept', $facet, lc $facet_cls
183 )
184 );
185 }
186 }
187  
188 0 return @res;
189 }
190  
191 sub _sort_subjects_locations {
192 0 ▶ if ( looks_like_number($a) && looks_like_number($b) ) {
Subroutine _sort_subjects_locations: not called CC=9 SCAR=45.0
Branch: 1 branch
BranchTrueFalseTotal
if (&looks_like_number($a) and &looks_like_number($b)) { } 0 0 0
Condition0%0/3
&looks_like_number($a) and &looks_like_number($b)
!ll&&!rl&&r
000
MC/DC0%0/2
&looks_like_number($a) and &looks_like_number($b)
&looks_like_number($a) &looks_like_number($b)
Truth table0%0/3
A and B
A= &looks_like_number($a)B= &looks_like_number($b)
ABresult
0X0
100
111
193 0 ▶ return ( $b->relevance // 0 ) <=> ( $a->relevance // 0 )
Condition0%0/7
($b->relevance // 0) <=> ($a->relevance // 0) || $a->qcode <=> $b->qcode
l!l&&r!l&&!r
000
$b->relevance // 0
l!l
00
$a->relevance // 0
l!l
00
MC/DC0%0/2
($b->relevance // 0) <=> ($a->relevance // 0) || $a->qcode <=> $b->qcode
$b->relevance $a->qcode <=> $b->qcode
MC/DC0%0/1
$a->relevance // 0
$a->relevance
Truth table0%0/3
A || B
A= $b->relevanceB= $a->qcode <=> $b->qcode
ABresult
1X1
011
000
Truth table0%0/2
A
A= $a->relevance
Aresult
11
00
194 || $a->qcode <=> $b->qcode;
195 }
196 else {
197 0 ▶ return ( $b->relevance // 0 ) <=> ( $a->relevance // 0 )
Condition0%0/7
($b->relevance // 0) <=> ($a->relevance // 0) || $a->qcode cmp $b->qcode
l!l&&r!l&&!r
000
$b->relevance // 0
l!l
00
$a->relevance // 0
l!l
00
MC/DC0%0/2
($b->relevance // 0) <=> ($a->relevance // 0) || $a->qcode cmp $b->qcode
$b->relevance $a->qcode cmp $b->qcode
MC/DC0%0/1
$a->relevance // 0
$a->relevance
Truth table0%0/3
A || B
A= $b->relevanceB= $a->qcode cmp $b->qcode
ABresult
1X1
011
000
Truth table0%0/2
A
A= $a->relevance
Aresult
11
00
198 || $a->qcode cmp $b->qcode;
199 }
200 }
201  
202 sub _create_subjects_location {
203 0 ▶ my $self = shift;
Subroutine _create_subjects_location: not called CC=8 SCAR=42.8
204 0 my @res;
205  
206 0 ▶ push @res, $self->doc->createComment('locations')
Branch: 1 branch
BranchTrueFalseTotal
if $self->news_item->has_locations 0 0 0
207 if $self->news_item->has_locations;
208  
209 0 foreach my $l (
210 0 sort _sort_subjects_locations values %{ $self->news_item->locations }
211 ) {
212 0 ▶ my $why = $l->direct ? 'why:direct' : 'why:ancestor';
Branch: 1 branch
BranchTrueFalseTotal
$l->direct ? : 0 0 0
213 0 push @res,
214 my $s = $self->create_element(
215 'subject',
216 type => 'cpnat:geoArea',
217 why => $why,
218 _name_text => $l
219 );
220 0 ▶ $s->setAttribute( 'relevance', $l->relevance )
Branch: 1 branch
BranchTrueFalseTotal
if defined $l->relevance 0 0 0
221 if defined $l->relevance;
222 0 $self->scheme_manager->add_qcode_or_literal( $s, 'geo', $l->qcode );
223 0 ▶ if ( $l->iso_code ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($l->iso_code) 0 0 0
224 0 $s->appendChild( my $sa = $self->create_element('sameAs') );
225 0 $self->scheme_manager->add_qcode_or_literal( $sa, 'iso3166_1a2',
226 $l->iso_code );
227 }
228 0 ▶ if ( $l->parent ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($l->parent) 0 0 0
229 0 $s->appendChild( my $b = $self->create_element('broader') );
230 0 $self->scheme_manager->add_qcode_or_literal( $b, 'geo',
231 $l->parent->qcode );
232 0 my $hierarchy = $self->_create_hierarchy( $l, 'geo' );
233 0 ▶ $b->appendChild($hierarchy) if $hierarchy;
Branch: 1 branch
BranchTrueFalseTotal
if $hierarchy 0 0 0
234 }
235 }
236 0 return @res;
237 }
238  
239 sub _create_subjects_organisation {
240 0 ▶ my $self = shift;
Subroutine _create_subjects_organisation: not called CC=3 SCAR=24.8
241 0 my @res;
242  
243 0 ▶ push @res, $self->doc->createComment('organisations')
Branch: 1 branch
BranchTrueFalseTotal
if $self->news_item->has_organisations 0 0 0
244 if $self->news_item->has_organisations;
245 0 foreach my $org ( @{ $self->news_item->organisations } ) {
246 0 push @res,
247 my $o = $self->create_element(
248 'subject',
249 type => 'cpnat:organisation',
250 _name_text => $org
251 );
252 0 $self->scheme_manager->add_qcode_or_literal( $o, 'org', $org->qcode );
253 }
254 0 return @res;
255 }
256  
257 sub _create_subjects_topic {
258 0 ▶ my $self = shift;
Subroutine _create_subjects_topic: not called CC=3 SCAR=24.8
259 0 my @res;
260  
261 0 ▶ push @res, $self->doc->createComment('topics')
Branch: 1 branch
BranchTrueFalseTotal
if $self->news_item->has_topics 0 0 0
262 if $self->news_item->has_topics;
263  
264 0 foreach my $topic ( @{ $self->news_item->topics } ) {
265 0 push @res,
266 my $t = $self->create_element(
267 'subject',
268 type => 'cpnat:abstract',
269 _name_text => $topic
270 );
271 0 $self->scheme_manager->add_qcode_or_literal( $t, 'topic',
272 $topic->qcode );
273 }
274  
275 0 return @res;
276 }
277  
278 sub _create_subjects_product {
279 0 ▶ my $self = shift;
Subroutine _create_subjects_product: not called CC=5 SCAR=34.0
280 0 my @res;
281  
282 0 ▶ push @res, $self->doc->createComment('products')
Branch: 1 branch
BranchTrueFalseTotal
if $self->news_item->has_products 0 0 0
283 if $self->news_item->has_products;
284  
285 0 foreach my $product ( @{ $self->news_item->products } ) {
286 0 push @res,
287 my $p = $self->create_element(
288 'subject',
289 type => 'cpnat:object',
290 _name_text => $product
291 );
292 0 ▶ if ( $product->isbn ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($product->isbn) { } 0 0 0
elsif ($product->ean) { } 0 0 0
293 0 $self->scheme_manager->add_qcode_or_literal( $p, 'isbn',
294 $product->isbn );
295 }
296 elsif ( $product->ean ) {
297 0 $self->scheme_manager->add_qcode_or_literal( $p, 'ean',
298 $product->ean );
299 }
300 }
301  
302 0 return @res;
303 }
304  
305 sub _create_subjects {
306 0 ▶ my $self = shift;
Subroutine _create_subjects: not called CC=2 SCAR=17.9
307 0 my @res;
308  
309 0 push @res, $self->_create_subjects_storytypes();
310 0 push @res, $self->_create_subjects_desk();
311 0 push @res, $self->_create_subjects_media_topic();
312 0 ▶ push @res, $self->_create_subjects_concepts()
Branch: 1 branch
BranchTrueFalseTotal
if $self->news_item->has_concepts 0 0 0
313 if $self->news_item->has_concepts;
314 0 push @res, $self->_create_subjects_location();
315 0 push @res, $self->_create_subjects_organisation();
316 0 push @res, $self->_create_subjects_topic();
317 0 push @res, $self->_create_subjects_product();
318  
319 0 return @res;
320 }
321  
322 sub _create_company_data {
323 0 ▶ my ( $self, $org, $root ) = @_;
Subroutine _create_company_data: not called CC=4 SCAR=30.0
324 0 ▶ return unless ( $self->scheme_manager->crel );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->scheme_manager->crel 0 0 0
325  
326 0 my $crel_alias = $self->scheme_manager->crel->alias;
327 $root->appendChild(
328 $self->create_element(
329 'related',
330 rel => "$crel_alias:index",
331 _name_text => $_
332 )
333 0 ) foreach ( @{ $org->indices } );
334 $root->appendChild(
335 $self->create_element(
336 'related',
337 rel => "$crel_alias:exchange",
338 _name_text => $_
339 )
340 0 ) foreach ( @{ $org->stock_exchanges } );
341 0 return;
342 }
343  
344 sub _create_asserts_organisation {
345 0 ▶ my $self = shift;
Subroutine _create_asserts_organisation: not called CC=6 SCAR=37.4
346  
347 0 my @res;
348 0 ▶ push @res, $self->doc->createComment('organisations')
Branch: 1 branch
BranchTrueFalseTotal
if $self->news_item->has_organisations 0 0 0
349 if $self->news_item->has_organisations;
350  
351 0 foreach my $org ( @{ $self->news_item->organisations } ) {
352 0 push @res,
353 my $a = $self->create_element( 'assert', _name_text => $org );
354 0 $self->scheme_manager->add_qcode_or_literal( $a, 'org', $org->qcode );
355  
356 0 foreach ( @{ $org->isins } ) {
357 0 $a->appendChild( my $sa = $self->create_element('sameAs') );
358 0 $self->scheme_manager->add_qcode_or_literal( $sa, 'isin', $_ );
359 }
360 0 ▶ if ( $org->has_websites ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($org->has_websites) 0 0 0
361 0 $a->appendChild( my $od =
362 $self->create_element('organisationDetails') );
363 0 $od->appendChild( my $ci = $self->create_element('contactInfo') );
364 $ci->appendChild( $self->create_element( 'web', _text => $_ ) )
365 0 foreach @{ $org->websites };
366 }
367 0 $self->_create_company_data( $org, $a );
368 }
369 0 return @res;
370 }
371  
372 sub _create_asserts_location {
373 0 ▶ my $self = shift;
Subroutine _create_asserts_location: not called CC=5 SCAR=34.0
374 0 my @res;
375  
376 0 foreach my $loc_k ( sort keys %{ $self->news_item->locations } ) {
377 0 my $location = $self->news_item->locations->{$loc_k};
378 next
379 0 ▶ unless ( defined $location->longitude
Branch: 1 branch
BranchTrueFalseTotal
unless defined $location->longitude and defined $location->latitude 0 0 0
Condition0%0/3
defined $location->longitude and defined $location->latitude
!ll&&!rl&&r
000
MC/DC0%0/2
defined $location->longitude and defined $location->latitude
defined $location->longitude defined $location->latitude
Truth table0%0/3
A and B
A= defined $location->longitudeB= defined $location->latitude
ABresult
0X0
100
111
380 && defined $location->latitude );
381 0 push @res, my $l = $self->create_element('assert');
382 0 $self->scheme_manager->add_qcode_or_literal( $l, 'geo',
383 $location->qcode );
384  
385 0 $l->appendChild( my $geo_area_details =
386 $self->create_element('geoAreaDetails') );
387 0 $geo_area_details->appendChild( my $pos =
388 $self->create_element('position') );
389  
390 0 $pos->setAttribute( $_, $location->$_ ) for qw/latitude longitude/;
391 }
392  
393 0 return @res;
394 }
395  
396 sub _create_asserts {
397 0 ▶ my $self = shift;
Subroutine _create_asserts: not called CC=1 SCAR=6.9
398 0 my @res;
399  
400 0 push @res, $self->_create_asserts_organisation();
401 0 push @res, $self->_create_asserts_location();
402  
403 0 return @res;
404 }
405  
406 sub _create_infosources {
407 0 ▶ my ( $self, $root ) = @_;
Subroutine _create_infosources: not called CC=3 SCAR=24.8
408 0 foreach ( @{ $self->news_item->sources } ) {
409 0 ▶ next if $_ eq uc $self->news_item->provider->qcode;
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq uc $self->news_item->provider->qcode 0 0 0
410 0 $root->appendChild( my $i =
411 $self->create_element( 'infoSource', _name_text => $_ ) );
412 0 $self->scheme_manager->add_role( $i, 'isrol', 'originfo' );
413 }
414 0 return;
415 }
416  
417 sub _create_authors {
418 0 ▶ my ( $self, $root ) = @_;
Subroutine _create_authors: not called CC=2 SCAR=17.9
419 0 foreach ( @{ $self->news_item->authors } ) {
420 0 $root->appendChild( $self->_create_creator($_) );
421 }
422 0 return;
423 }
424  
425 sub _create_content_meta {
426 0 ▶ my ( $self, $root ) = @_;
Subroutine _create_content_meta: not called CC=20 SCAR=60.4
427  
428 0 my $cm = $self->create_element('contentMeta');
429  
430 0 $self->_create_icon($cm);
431  
432 0 $cm->appendChild(
433 $self->create_element(
434 'urgency', _text => $self->news_item->priority
435 )
436 );
437  
438 0 ▶ if ( $self->news_item->content_created ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->news_item->content_created) 0 0 0
439 0 my $t =
440 $self->_formatter->format_datetime(
441 $self->news_item->content_created );
442 0 $cm->appendChild(
443 $self->create_element( 'contentCreated', _text => $t ) );
444 }
445 0 ▶ if ( $self->news_item->content_modified
Branch: 1 branch
BranchTrueFalseTotal
if ($self->news_item->content_modified and $self->news_item->content_created != $self->news_item->content_modified) 0 0 0
Condition0%0/3
$self->news_item->content_modified and $self->news_item->content_created != $self->news_item->content_modified
!ll&&!rl&&r
000
MC/DC0%0/2
$self->news_item->content_modified and $self->news_item->content_created != $self->news_item->content_modified
$self->news_item->content_modified $self->news_item->content_created != $self->news_item->content_modified
Truth table0%0/3
A and B
A= $self->news_item->content_modifiedB= $self->news_item->content_created != $self->news_item->content_modified
ABresult
0X0
100
111
446 and $self->news_item->content_created !=
447 $self->news_item->content_modified ) {
448 0 my $t =
449 $self->_formatter->format_datetime(
450 $self->news_item->content_modified );
451 0 $cm->appendChild(
452 $self->create_element( 'contentModified', _text => $t ) );
453 }
454  
455 0 foreach ( @{ $self->news_item->cities } ) {
456 0 $cm->appendChild(
457 $self->create_element( 'located', _name_text => $_ ) );
458 }
459  
460 0 ▶ if ( my $electiondistrict = $self->news_item->electiondistrict ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $electiondistrict = $self->news_item->electiondistrict) 0 0 0
461 0 $cm->appendChild(
462 my $ed = $self->create_element(
463 'located', _text => $electiondistrict->name
464 )
465 );
466 0 $self->scheme_manager->add_qcode( $ed, 'electiondistrict',
467 $electiondistrict->qcode );
468  
469 0 ▶ if ( my $electionprovince = $electiondistrict->province ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $electionprovince = $electiondistrict->province) 0 0 0
470 0 my $ep = $self->create_element( 'located',
471 _text => $electionprovince->name );
472 0 $self->scheme_manager->add_qcode( $ep, 'electionprovince',
473 $electionprovince->qcode );
474  
475 0 $ed->appendChild($ep);
476 }
477 }
478  
479 0 $self->_create_infosources($cm);
480 0 $self->_create_authors($cm);
481  
482 0 ▶ if ( $self->news_item->message_id ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->news_item->message_id) 0 0 0
483 0 $cm->appendChild(
484 $self->create_element(
485 'altId', _text => $self->news_item->message_id
486 )
487 );
488 }
489  
490 0 ▶ if ( $self->news_item->byline ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->news_item->byline) 0 0 0
491 0 $cm->appendChild(
492 $self->create_element( 'by', _text => $self->news_item->byline )
493 );
494 }
495  
496 0 ▶ if ( $self->news_item->dateline ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->news_item->dateline) 0 0 0
497 0 $cm->appendChild(
498 $self->create_element(
499 'dateline', _text => $self->news_item->dateline
500 )
501 );
502 }
503  
504 $cm->appendChild(
505 0 $self->create_element(
506 'language', tag => $self->news_item->language
507 )
508 );
509  
510 0 foreach ( @{ $self->news_item->genres } ) {
511 0 $cm->appendChild( my $gn =
512 $self->create_element( 'genre', _name_text => $_ ) );
513 0 $self->scheme_manager->add_qcode_or_literal( $gn, 'genre',
514 $_->qcode );
515 }
516  
517 0 my @subjects = $self->_create_subjects();
518 0 $cm->appendChild($_) foreach (@subjects);
519  
520 0 ▶ if ( $self->news_item->slugline ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->news_item->slugline) 0 0 0
521 0 my $slug =
522 $self->create_element( 'slugline',
523 _text => $self->news_item->slugline );
524 0 ▶ if ( $self->news_item->slugline_sep ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->news_item->slugline_sep) 0 0 0
525 0 $slug->setAttribute( 'separator',
526 $self->news_item->slugline_sep );
527 }
528 0 $cm->appendChild($slug);
529 }
530  
531 $cm->appendChild(
532 0 my $hl1 = $self->create_element(
533 'headline', _text => $self->news_item->title
534 )
535 );
536 0 $self->scheme_manager->add_role( $hl1, 'hltype', 'title' );
537  
538 0 ▶ if ( $self->news_item->subtitle ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->news_item->subtitle) 0 0 0
539 0 $cm->appendChild(
540 my $hl2 = $self->create_element(
541 'headline', _text => $self->news_item->subtitle
542 )
543 );
544 0 $self->scheme_manager->add_role( $hl2, 'hltype', 'subtitle' );
545 }
546  
547 0 ▶ if ( $self->news_item->credit ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->news_item->credit) 0 0 0
548 0 $cm->appendChild(
549 $self->create_element(
550 'creditline', _text => $self->news_item->credit
551 )
552 );
553 }
554  
555 0 foreach ( @{ $self->news_item->keywords } ) {
556 0 $cm->appendChild( $self->create_element( 'keyword', _text => $_ ) );
557 }
558  
559 0 ▶ if ( $self->news_item->caption ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->news_item->caption) 0 0 0
560 0 $cm->appendChild(
561 my $desc = $self->create_element(
562 'description', _text => $self->news_item->caption
563 )
564 );
565 0 $self->scheme_manager->add_role( $desc, 'drol', 'caption' );
566 }
567  
568 0 ▶ if ( $self->news_item->summary ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->news_item->summary) 0 0 0
569 0 $cm->appendChild(
570 my $smry = $self->create_element(
571 'description', _text => $self->news_item->summary
572 )
573 );
574 0 $self->scheme_manager->add_role( $smry, 'drol', 'summary' );
575 }
576  
577 0 $self->_create_teaser($cm);
578  
579 0 $root->appendChild($cm);
580  
581 0 my @asserts = $self->_create_asserts();
582 0 $root->appendChild($_) foreach @asserts;
583 0 return;
584 }
585  
586 sub _create_content {
587 0 ▶ my ( $self, $root ) = @_;
Subroutine _create_content: not called CC=8 SCAR=42.8
588  
589 0 $root->appendChild( my $cs = $self->create_element('contentSet') );
590 0 my $inlinexml = $self->create_element( 'inlineXML',
591 contenttype => 'application/xhtml+xml' );
592 0 my $html = $self->create_element( 'html', _ns => $self->xhtml_ns );
593 0 $html->appendChild( my $head =
594 $self->create_element( 'head', _ns => $self->xhtml_ns ) );
595 0 $head->appendChild(
596 $self->create_element(
597 'title',
598 _ns => $self->xhtml_ns,
599 _text => $self->news_item->title
600 )
601 );
602 0 $inlinexml->appendChild($html);
603  
604 0 $html->appendChild( my $body =
605 $self->create_element( 'body', _ns => $self->xhtml_ns ) );
606  
607 0 $body->appendChild(
608 $self->create_element(
609 'h1',
610 _ns => $self->xhtml_ns,
611 _text => $self->news_item->title
612 )
613 );
614 0 ▶ $body->appendChild(
Branch: 1 branch
BranchTrueFalseTotal
if $self->news_item->subtitle 0 0 0
615 $self->create_element(
616 'h2',
617 _ns => $self->xhtml_ns,
618 _text => $self->news_item->subtitle
619 )
620 ) if $self->news_item->subtitle;
621  
622 0 ▶ my @paras =
Branch: 1 branch
BranchTrueFalseTotal
$self->news_item->paragraphs ? : 0 0 0
623 $self->news_item->paragraphs
624 ? $self->news_item->paragraphs->getChildNodes()
625 : ();
626 0 $body->appendChild($_) foreach (@paras);
627  
628 0 $cs->appendChild($inlinexml);
629 0 foreach ( sort keys %{ $self->news_item->remotes } ) {
630 0 my $rc = $self->create_element( 'remoteContent', href => $_ );
631 0 $self->_create_remote_content( $rc, $self->news_item->remotes->{$_} );
632 0 $cs->appendChild($rc);
633 }
634 0 foreach ( @{ $self->news_item->inlinedata } ) {
635 0 my %args;
636 0 ▶ if ( $_->isa('XML::NewsML_G2::Inline_CData') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->isa('XML::NewsML_G2::Inline_CData')) { } 0 0 0
637 0 $args{_cdata} = $_->data;
638 }
639 else {
640 0 $args{_text} = $_->data;
641 }
642 0 ▶ $args{contenttype} = $_->mimetype if $_->mimetype;
Branch: 1 branch
BranchTrueFalseTotal
if $_->mimetype 0 0 0
643 0 my $data = $self->create_element( 'inlineData', %args );
644 0 $cs->appendChild($data);
645 }
646 0 return;
647 }
648  
649 20 __PACKAGE__->meta->make_immutable;
650  
651 20 1;
652 __END__
653  
654 =head1 NAME
655  
656 XML::NewsML_G2::Writer::News_Item - create DOM tree conforming to
657 NewsML-G2 for News Items
658  
659 =for test_synopsis
660 my ($ni, $sm);
661  
662 =head1 SYNOPSIS
663  
664 my $w = XML::NewsML_G2::Writer::News_Item->new
665 (news_item => $ni, scheme_manager => $sm);
666  
667 my $p = $w->create_element('p', class => 'main', _text => 'blah');
668  
669 my $dom = $w->create_dom();
670  
671 =head1 DESCRIPTION
672  
673 This module implements the creation of a DOM tree conforming to
674 NewsML-G2 for News Items. Depending on the version of the standard
675 specified, a version-dependent role will be applied. For the API of
676 this module, see the documentation of the superclass L<XML::NewsML_G2::Writer>.
677  
678 =head1 ATTRIBUTES
679  
680 =over 4
681  
682 =item news_item
683  
684 L<XML::NewsML_G2::News_Item> instance used to create the output document
685  
686 =back
687  
688 =head1 AUTHOR
689  
690 Philipp Gortan C<< <philipp.gortan@apa.at> >>
691  
692 =head1 LICENCE AND COPYRIGHT
693  
694 Copyright (c) 2013-2014, APA-IT. All rights reserved.
695  
696 See L<XML::NewsML_G2> for the license.
↑ Summary blib/lib/XML/NewsML_G2/Role/Writer/News_Item_Picture.pm »