File Coverage

blib/lib/XML/NewsML_G2/News_Item.pm
Criterion Covered Total %
statement 33 34 97.0
branch 8 10 80.0
condition n/a
subroutine 8 8 100.0
pod 3 3 100.0
total 52 55 94.5


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