blib/lib/XML/NewsML_G2/News_Item.pm

filter: Statementstmt 97.8% 89 / 91 Branchbran 81.2% 13 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 96.0% 24 / 25 Podpod 100% 5 / 5 totaltotal 95.6% 131 / 137 CC 9 SCAR 5.3
CC
9
Cov
95%
add_paragraph
3.0
add_media_topic
3.0
add_location
3.0
CRAP 1.7
« blib/lib/XML/NewsML_G2/Scheme.pm ↑ Summary blib/lib/XML/NewsML_G2/Role/Writer_2_18.pm »
1 package XML::NewsML_G2::News_Item;
2  
3 26 ▶use XML::LibXML qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 26 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 26 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 26 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 # document properties
10 26 extends 'XML::NewsML_G2::AnyItem';
11  
12 26 has 'title', isa => 'Str', is => 'ro', required => 1;
13 26 has 'subtitle', isa => 'Str', is => 'rw';
14 26 has 'caption', isa => 'Str', is => 'rw';
15 26 has 'teaser', isa => 'Str', is => 'rw';
16 26 has 'summary', isa => 'Str', is => 'rw';
17 26 has 'byline', isa => 'Str', is => 'rw';
18 26 has 'dateline', isa => 'Str', is => 'rw';
19 26 has 'paragraphs', isa => 'XML::LibXML::Node', is => 'rw';
20 26 has 'content_created',
21 isa => 'DateTime',
22 is => 'ro',
23 lazy => 1,
24 builder => '_build_content_created';
25 26 has 'content_modified', isa => 'DateTime', is => 'ro';
26  
27 26 has 'credit', isa => 'Str', is => 'rw';
28 26 has 'priority', isa => 'Int', is => 'ro', default => 5;
29 26 has 'message_id', isa => 'Str', is => 'ro';
30 26 has 'slugline', isa => 'Str', is => 'rw';
31 26 has 'slugline_sep', isa => 'Str', is => 'rw', default => '/';
32 26 has 'electiondistrict', isa => 'XML::NewsML_G2::ElectionDistrict', is => 'rw';
33  
34 has 'sources',
35 isa => 'ArrayRef[Str]',
36 is => 'rw',
37 18 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
38 26 traits => ['Array'],
39 handles => { add_source => 'push' };
40 has 'authors',
41 isa => 'XML::NewsML_G2::ArrayRefOfCreators',
42 is => 'rw',
43 coerce => 1,
44 18 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
45 26 traits => ['Array'],
46 handles => { add_author => 'push' };
47 has 'cities',
48 isa => 'ArrayRef[Str]',
49 is => 'rw',
50 18 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
51 26 traits => ['Array'],
52 handles => { add_city => 'push' };
53  
54 has 'genres',
55 isa => 'ArrayRef[XML::NewsML_G2::Genre]',
56 is => 'rw',
57 18 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
58 26 traits => ['Array'],
59 handles => { add_genre => 'push' };
60 has 'storytypes',
61 isa => 'ArrayRef[XML::NewsML_G2::StoryType]',
62 is => 'rw',
63 18 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
64 26 traits => ['Array'],
65 handles => { add_storytype => 'push' };
66 has 'organisations',
67 isa => 'ArrayRef[XML::NewsML_G2::Organisation]',
68 is => 'rw',
69 18 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
70 26 traits => ['Array'],
71 handles => { add_organisation => 'push', has_organisations => 'count' };
72 has 'topics',
73 isa => 'ArrayRef[XML::NewsML_G2::Topic]',
74 is => 'rw',
75 18 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
76 26 traits => ['Array'],
77 handles => { add_topic => 'push', has_topics => 'count' };
78 has 'products',
79 isa => 'ArrayRef[XML::NewsML_G2::Product]',
80 is => 'rw',
81 18 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
82 26 traits => ['Array'],
83 handles => { add_product => 'push', has_products => 'count' };
84 has 'desks',
85 isa => 'ArrayRef[XML::NewsML_G2::Desk]',
86 is => 'rw',
87 18 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
88 26 traits => ['Array'],
89 handles => { add_desk => 'push', has_desks => 'count' };
90 has 'media_topics',
91 isa => 'HashRef[XML::NewsML_G2::Media_Topic]',
92 is => 'rw',
93 18 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
94 26 traits => ['Hash'],
95 handles => { has_media_topics => 'count' };
96 has 'concepts',
97 isa => 'HashRef[XML::NewsML_G2::Concept]',
98 is => 'rw',
99 18 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
100 26 traits => ['Hash'],
101 handles => { has_concepts => 'count' };
102 has 'locations',
103 isa => 'HashRef[XML::NewsML_G2::Location]',
104 is => 'rw',
105 18 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
106 26 traits => ['Hash'],
107 handles => { has_locations => 'count' };
108 has 'keywords',
109 isa => 'ArrayRef[Str]',
110 is => 'rw',
111 18 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
112 26 traits => ['Array'],
113 handles => { add_keyword => 'push', has_keywords => 'count' };
114 has 'remotes',
115 isa => 'HashRef',
116 is => 'rw',
117 18 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
118 26 traits => ['Hash'],
119 handles => { has_remotes => 'count' };
120 has 'inlinedata',
121 isa => 'ArrayRef[XML::NewsML_G2::Inline_Data]',
122 is => 'rw',
123 18 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
124 26 traits => ['Array'],
125 handles => { add_inlinedata => 'push', has_inlinedata => 'count' };
126  
127 sub _build_content_created {
128 0 ▶ return DateTime->now( time_zone => 'local' );
Subroutine _build_content_created: not called CC=1 SCAR=6.9
129 }
130  
131 # public methods
132  
133 sub add_media_topic {
134 52 ▶ my ( $self, $mt ) = @_;
Subroutine add_media_topic: called CC=3 SCAR=11.0
Pod documented
135 52 ▶ return if exists $self->media_topics->{ $mt->qcode };
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->media_topics->{$mt->qcode} 13 39 52
136 39 $self->media_topics->{ $mt->qcode } = $mt;
137 39 ▶ $self->add_media_topic( $mt->parent ) if ( $mt->parent );
Branch: 1 branch
BranchTrueFalseTotal
if $mt->parent 26 13 39
138 39 return 1;
139 }
140  
141 sub add_concept {
142 1 ▶ my ( $self, $concept ) = @_;
Subroutine add_concept: called CC=2 SCAR=7.0
Pod documented
143 1 ▶ return if exists $self->concepts->{ $concept->uid };
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->concepts->{$concept->uid} 0 1 1
144 1 $self->concepts->{ $concept->uid } = $concept;
145 1 return 1;
146 }
147  
148 sub add_location {
149 52 ▶ my ( $self, $l ) = @_;
Subroutine add_location: called CC=3 SCAR=11.0
Pod documented
150 52 ▶ return if exists $self->locations->{ $l->qcode };
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->locations->{$l->qcode} 13 39 52
151 39 $self->locations->{ $l->qcode } = $l;
152 39 ▶ $self->add_location( $l->parent ) if $l->parent;
Branch: 1 branch
BranchTrueFalseTotal
if $l->parent 26 13 39
153 39 return 1;
154 }
155  
156 sub add_paragraph {
157 5 ▶ my ( $self, $text_or_xml ) = @_;
Subroutine add_paragraph: called CC=3 SCAR=11.1
Pod documented
158 5 my $paras = $self->paragraphs;
159 5 ▶ unless ($paras) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($paras) 4 1 5
160 4 $self->paragraphs( $paras =
161 XML::LibXML->createDocument()->createElement('paragraphs') );
162 }
163 5 ▶ if ( ref $text_or_xml ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $text_or_xml) { } 0 5 5
164 0 $paras->appendChild($text_or_xml);
165 }
166 else {
167 5 my $doc = $paras->getOwnerDocument;
168 5 my $p = $doc->createElementNS( 'http://www.w3.org/1999/xhtml', 'p' );
169 5 $p->appendChild( $doc->createTextNode($text_or_xml) );
170 5 $paras->appendChild($p);
171 }
172 5 return 1;
173 }
174  
175 sub add_remote {
176 9 ▶ my ( $self, $uri, $remote ) = @_;
Subroutine add_remote: called CC=2 SCAR=7.0
Pod documented
177 9 ▶ return if exists $self->remotes->{$uri};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->remotes->{$uri} 0 9 9
178 9 $self->remotes->{$uri} = $remote;
179  
180 9 return 1;
181 }
182  
183 26 __PACKAGE__->meta->make_immutable;
184  
185 26 1;
186 __END__
187  
188 =head1 NAME
189  
190 XML::NewsML_G2::News_Item - a news item (story)
191  
192 =for test_synopsis
193 my ($provider, $service, $genre1, $genre2);
194  
195 =head1 DESCRIPTION
196  
197 This module acts as a base class for NewsML-G2 news items.
198 Instead of using this class, use the most appropriate subclass,
199 e.g. L<XML::NewsML_G2::News_Item_Text>.
200  
201 =head1 ATTRIBUTES
202  
203 =over 4
204  
205 =item authors
206  
207 List of strings containing names of the news item's authors
208  
209 =item cities
210  
211 List of strings containing city names where the story has been written
212 down (as opposed to: where the story occured)
213  
214 =item closing
215  
216 Final comment on planned updates of this story
217  
218 =item content_created
219  
220 DateTime instance, defaults to now
221  
222 =item content_modified
223  
224 DateTime instance
225  
226 =item credit
227  
228 Human readable credit line
229  
230 =item caption
231  
232 Human readable content description string
233  
234 =item dateline
235  
236 Natural language information indicating the place and time that the content
237 was created
238  
239 =item derived_from
240  
241 Deprecated - use derived_froms and add_derived_from instead!
242  
243 =item derived_froms
244  
245 List of XML::NewsML_G2::Link instances
246  
247 =item desks
248  
249 List of L<XML::NewsML_G2::Desk> instances
250  
251 =item doc_status
252  
253 Defaults to "usable".
254  
255 =item doc_version
256  
257 Defaults to "1"
258  
259 =item embargo
260  
261 DateTime instance
262  
263 =item embargo_text
264  
265 additional text for specifying details on the embargo
266  
267 =item evolved_froms
268  
269 List of XML::NewsML_G2::Link instances
270  
271 =item genres
272  
273 List of L<XML::NewsML_G2::Genre> instances
274  
275 =item guid
276  
277 "identifier that is guaranteed to be globally unique for all time and
278 independent of location". Defaults to a UUID
279  
280 =item indicators
281  
282 List of strings to signal additional information
283  
284 =item language
285  
286 language of the story, required. E.g. "en", "de", ...
287  
288 =item locations
289  
290 Hash mapping qcodes to L<XML::NewsML_G2::Location> instances
291  
292 =item media_topics
293  
294 Hash mapping qcodes to L<XML::NewsML_G2::Media_Topic> instances
295  
296 =item concepts
297  
298 Hash mapping generated uids to L<XML::NewsML_G2::Concept> instances
299  
300 =item message_id
301  
302 Human-readable alternative ID of the story
303  
304 =item note
305  
306 Editorial notes
307  
308 =item organisations
309  
310 List of L<XML::NewsML_G2::Organisation> instances
311  
312 =item paragraphs
313  
314 An L<XML::LibXML::Node> instance containing the content (quite likely
315 C<p> elements, hence the name) of the story - to be put into the XHTML
316 body. Use the C<add_paragraph> method to add text unless you want more
317 control of the output.
318  
319 =item priority
320  
321 Numeric message priority, defaults to 5
322  
323 =item processed_froms
324  
325 List of XML::NewsML_G2::Link instances
326  
327 =item products
328  
329 List of L<XML::NewsML_G2::Product> instances
330  
331 =item provider
332  
333 List of L<XML::NewsML_G2::Provider> instances
334  
335 =item remotes
336  
337 Hash mapping of hrefs to remote object (e.g. XML::NewsML_G2::Picture) instances
338  
339 =item see_also
340  
341 Deprecated - use see_alsos and add_see_also instead!
342  
343 =item see_alsos
344  
345 List of XML::NewsML_G2::Link instances
346  
347 =item service
348  
349 L<XML::NewsML_G2::Service> instance
350  
351 =item slugline
352  
353 String containing the slugline
354  
355 =item slugline_sep
356  
357 Slugline separator, defaults to "/"
358  
359 =item election_district
360  
361 L<XML::NewsML_G2::ElectionDistrict> instance
362  
363 =item sources
364  
365 List of strings containing story source names
366  
367 =item storytypes
368  
369 List of L<XML::NewsML_G2::StoryType> instances
370  
371 =item subtitle
372  
373 Subtitle string
374  
375 =item summary
376  
377 A short overview of all, or at least the most important, facets of the content of the item
378  
379 =item byline
380  
381 A free-text expression of the person or organisation that created the content
382  
383 =item teaser
384  
385 A short description intended to attract the user to view the full content
386  
387 =item title
388  
389 Title string
390  
391 =item topics
392  
393 List of L<XML::NewsML_G2::Topic> instances
394  
395 =item usage_terms
396  
397 String containing human readable usage terms
398  
399 =back
400  
401 =head1 METHODS
402  
403 =over 4
404  
405 =item add_author
406  
407 Add a string to the authors
408  
409 =item add_city
410  
411 Add a string to the cities
412  
413 =item add_derived_from
414  
415 Add a new "derived from" link - either a string, or a
416 XML::NewsML_G2::Link instance
417  
418 =item add_desk
419  
420 Add a L<XML::NewsML_G2::Desk> instance
421  
422 =item add_genre
423  
424 Add a L<XML::NewsML_G2::Genre> instance
425  
426 =item add_indicator
427  
428 Add a string to the indicators
429  
430 =item add_location
431  
432 Add a new L<XML::NewsML_G2::Location> instance
433  
434 =item add_media_topic
435  
436 Add a new L<XML::NewsML_G2::MediaTopic> instance
437  
438 =item add_concept
439  
440 Add a new L<XML::NewsML_G2::Concept> instance
441  
442 =item add_organisation
443  
444 Add a new L<XML::NewsML_G2::Organisation> instance
445  
446 =item add_paragraph
447  
448 Takes a string to be added to the C<paragraphs> Node instance as a
449 C<p> element. To have more control over the created XHTML output,
450 directly set the C<paragraphs> attribute with a Node instance you
451 created by yourself.
452  
453 =item add_product
454  
455 Add a new L<XML::NewsML_G2::Product> instance
456  
457 =item add_remote
458  
459 Add a new remote instance (e.g. XML::NewsML_G2::Picture) with a given href
460  
461 =item add_see_also
462  
463 Add a new "see also" link - either a string, or a XML::NewsML_G2::Link
464 instance
465  
466 =item add_source
467  
468 Add a string to the sources
469  
470 =item add_topic
471  
472 Add a new L<XML::NewsML_G2::Topic> instance
473  
474 =back
475  
476 =head1 AUTHOR
477  
478 Philipp Gortan C<< <philipp.gortan@apa.at> >>
479  
480 =head1 LICENCE AND COPYRIGHT
481  
482 Copyright (c) 2013-2015, APA-IT. All rights reserved.
483  
484 See L<XML::NewsML_G2> for the license.
« blib/lib/XML/NewsML_G2/Scheme.pm ↑ Summary blib/lib/XML/NewsML_G2/Role/Writer_2_18.pm »