blib/lib/XML/NewsML_G2/News_Item.pm

filter: Statementstmt 100% 77 / 77 Branchbran 100% 10 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 20 / 20 Podpod 100% 3 / 3 totaltotal 100% 110 / 110 CC 6 SCAR 4.4
CC
6
Cov
100%
add_media_topic
3.0
add_location
3.0
add_paragraph
2.0
CRAP 1.6
« blib/lib/XML/NewsML_G2/Scheme.pm ↑ Summary blib/lib/XML/NewsML_G2.pm »
1 package XML::NewsML_G2::News_Item;
2  
3 # $Id: News_Item.pm 47068 2013-07-03 12:17:55Z apatecgortan $
4  
5 10 ▶use XML::LibXML qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
6 10 ▶use UUID::Tiny ':std';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 10 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 10 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11  
12 10 has 'language', isa => 'Str', is => 'ro', required => 1;
13  
14 # document properties
15 2 ▶has 'guid', isa => 'Str', is => 'ro', default => sub {create_uuid_as_string()};
Subroutine __ANON__: called CC=1 SCAR=0.0
16 10 has 'doc_version', isa => 'Int', is => 'ro', default => '1';
17 10 has 'provider', isa => 'XML::NewsML_G2::Provider', is => 'ro', required => 1;
18 10 has 'service', isa => 'XML::NewsML_G2::Service', is => 'ro', predicate => 'has_service';
19 10 has 'doc_status', isa => 'Str', is => 'ro', default => 'usable';
20 10 has 'title', isa => 'Str', is => 'ro', required => 1;
21 10 has 'subtitle', isa => 'Str', is => 'rw';
22 10 has 'paragraphs', isa => 'XML::LibXML::Node', is => 'rw';
23 2 ▶has 'content_created', isa => 'DateTime', is => 'ro', default => sub {DateTime->now()};
Subroutine __ANON__: called CC=1 SCAR=0.0
24 10 has 'content_modified', isa => 'DateTime', is => 'ro';
25 10 has 'embargo', isa => 'DateTime', is => 'rw';
26 10 has 'embargo_text', isa => 'Str', is => 'rw';
27  
28 10 has 'priority', isa => 'Int', is => 'ro', default => 5;
29 10 has 'message_id', isa => 'Str', is => 'ro';
30 10 has 'slugline', isa => 'Str', is => 'ro';
31 10 has 'slugline_sep', isa => 'Str', is => 'ro', default => '/';
32 10 has 'note', isa => 'Str', is => 'ro';
33 10 has 'closing', isa => 'Str', is => 'rw';
34 10 has 'see_also', isa => 'Str', is => 'rw';
35  
36 5 ▶has 'sources', isa => 'ArrayRef[Str]', is => 'rw', default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
37 10 traits => ['Array'], handles => {add_source => 'push'};
38 5 ▶has 'authors', isa => 'ArrayRef[Str]', is => 'rw', default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
39 10 traits => ['Array'], handles => {add_author => 'push'};
40 5 ▶has 'indicators', isa => 'ArrayRef[Str]', is => 'rw', default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
41 10 traits => ['Array'], handles => {add_indicator => 'push'};
42 5 ▶has 'cities', isa => 'ArrayRef[Str]', is => 'rw', default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
43 10 traits => ['Array'], handles => {add_city => 'push'};
44  
45 5 ▶has 'genres', isa => 'ArrayRef[XML::NewsML_G2::Genre]', is => 'rw', default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
46 10 traits => ['Array'], handles => {add_genre => 'push'};
47 5 ▶has 'organisations', isa => 'ArrayRef[XML::NewsML_G2::Organisation]', is => 'rw', default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
48 10 traits => ['Array'], handles => {add_organisation => 'push', has_organisations => 'count'};
49 5 ▶has 'topics', isa => 'ArrayRef[XML::NewsML_G2::Topic]', is => 'rw', default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
50 10 traits => ['Array'], handles => {add_topic => 'push', has_topics => 'count'};
51 5 ▶has 'products', isa => 'ArrayRef[XML::NewsML_G2::Product]', is => 'rw', default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
52 10 traits => ['Array'], handles => {add_product => 'push', has_products => 'count'};
53 5 ▶has 'desks', isa => 'ArrayRef[XML::NewsML_G2::Desk]', is => 'rw', default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
54 10 traits => ['Array'], handles => {add_desk => 'push', has_desks => 'count'};
55 5 ▶has 'media_topics', isa => 'HashRef[XML::NewsML_G2::Media_Topic]', is => 'rw', default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
56 10 traits => ['Hash'], handles => {has_media_topics => 'count'};
57 5 ▶has 'locations', isa => 'HashRef[XML::NewsML_G2::Location]', is => 'rw', default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
58 10 traits => ['Hash'], handles => {has_locations => 'count'};
59  
60  
61 # public methods
62  
63 sub add_media_topic {
64 12 ▶ my ($self, $mt) = @_;
Subroutine add_media_topic: called CC=3 SCAR=11.0
Pod documented
65 12 ▶ return if exists $self->media_topics->{$mt->qcode};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->media_topics->{$mt->qcode} 3 9 12
66 9 $self->media_topics->{$mt->qcode} = $mt;
67 9 ▶ $self->add_media_topic($mt->parent) if ($mt->parent);
Branch: 1 branch
BranchTrueFalseTotal
if $mt->parent 6 3 9
68 9 return 1;
69 }
70  
71 sub add_location {
72 12 ▶ my ($self, $l) = @_;
Subroutine add_location: called CC=3 SCAR=11.0
Pod documented
73 12 ▶ return if exists $self->locations->{$l->qcode};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->locations->{$l->qcode} 3 9 12
74 9 $self->locations->{$l->qcode} = $l;
75 9 ▶ $self->add_location($l->parent) if $l->parent;
Branch: 1 branch
BranchTrueFalseTotal
if $l->parent 6 3 9
76 9 return 1;
77 }
78  
79 sub add_paragraph {
80 4 ▶ my ($self, $text) = @_;
Subroutine add_paragraph: called CC=2 SCAR=6.9
Pod documented
81 4 my $paras = $self->paragraphs;
82 4 ▶ unless ($paras) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($paras) 3 1 4
83 3 $self->paragraphs($paras = XML::LibXML->createDocument()->createElement('paragraphs'));
84 }
85 4 my $doc = $paras->getOwnerDocument;
86 4 my $p = $doc->createElementNS('http://www.w3.org/1999/xhtml', 'p');
87 4 $p->appendChild($doc->createTextNode($text));
88 4 $paras->appendChild($p);
89 4 return 1;
90 }
91  
92 10 __PACKAGE__->meta->make_immutable;
93  
94 10 1;
95 __END__
96  
97 =head1 NAME
98  
99 XML::NewsML_G2::News_Item - a news item (story)
100  
101 =for test_synopsis
102 my ($provider, $service, $genre1, $genre2);
103  
104 =head1 SYNOPSIS
105  
106 my $ni = XML::NewsML_G2::News_Item->new
107 (guid => "tag:example.com,2013:service:date:number",
108 title => "Story title",
109 slugline => "the/slugline",
110 language => 'de',
111 provider => $provider,
112 service => $service,
113 );
114  
115 $ni->add_genre($genre1, $genre2);
116 $ni->add_source('APA');
117 $ni->add_paragraph('blah blah blah');
118  
119  
120 =head1 ATTRIBUTES
121  
122 =over 4
123  
124 =item authors
125  
126 List of strings containing names of the news item's authors
127  
128 =item cities
129  
130 List of strings containing city names where the story has been written
131 down (as opposed to: where the story occured)
132  
133 =item closing
134  
135 Final comment on planned updates of this story
136  
137 =item content_created
138  
139 DateTime instance, defaults to now
140  
141 =item content_modified
142  
143 DateTime instance
144  
145 =item desks
146  
147 List of L<XML::NewsML_G2::Desk> instances
148  
149 =item doc_status
150  
151 Defaults to "usable".
152  
153 =item doc_version
154  
155 Defaults to "1"
156  
157 =item embargo
158  
159 DateTime instance
160  
161 =item embargo_text
162  
163 additional text for specifying details on the embargo
164  
165 =item genres
166  
167 List of L<XML::NewsML_G2::Genre> instances
168  
169 =item guid
170  
171 "identifier that is guaranteed to be globally unique for all time and
172 independent of location". Defaults to a UUID
173  
174 =item indicators
175  
176 List of strings to signal additional information
177  
178 =item language
179  
180 language of the story, required. E.g. "en", "de", ...
181  
182 =item locations
183  
184 Hash mapping qcodes to L<XML::NewsML_G2::Location> instances
185  
186 =item media_topics
187  
188 Hash mapping qcodes to L<XML::NewsML_G2::Media_Topic> instances
189  
190 =item message_id
191  
192 Human-readable alternative ID of the story
193  
194 =item note
195  
196 Editorial notes
197  
198 =item organisations
199  
200 List of L<XML::NewsML_G2::Organisation> instances
201  
202 =item paragraphs
203  
204 An L<XML::LibXML::Node> instance containing the content (quite likely
205 C<p> elements, hence the name) of the story - to be put into the XHTML
206 body. Use the C<add_paragraph> method to add text unless you want more
207 control of the output.
208  
209 =item priority
210  
211 Numeric message priority, defaults to 5
212  
213 =item products
214  
215 List of L<XML::NewsML_G2::Product> instances
216  
217 =item provider
218  
219 List of L<XML::NewsML_G2::Provider> instances
220  
221 =item see_also
222  
223 Free-format string
224  
225 =item service
226  
227 L<XML::NewsML_G2::Service> instance
228  
229 =item slugline
230  
231 String containing the slugline
232  
233 =item slugline_sep
234  
235 Slugline separator, defaults to "/"
236  
237 =item sources
238  
239 List of strings containing story source names
240  
241 =item subtitle
242  
243 Subtitle string
244  
245 =item title
246  
247 Title string
248  
249 =item topics
250  
251 List of L<XML::NewsML_G2::Topic> instances
252  
253 =back
254  
255 =head1 METHODS
256  
257 =over 4
258  
259 =item add_author
260  
261 Add a string to the authors
262  
263 =item add_city
264  
265 Add a string to the cities
266  
267 =item add_desk
268  
269 Add a L<XML::NewsML_G2::Desk> instance
270  
271 =item add_genre
272  
273 Add a L<XML::NewsML_G2::Genre> instance
274  
275 =item add_indicator
276  
277 Add a string to the indicators
278  
279 =item add_location
280  
281 Add a new L<XML::NewsML_G2::Location> instance
282  
283 =item add_media_topic
284  
285 Add a new L<XML::NewsML_G2::MediaTopic> instance
286  
287 =item add_organisation
288  
289 Add a new L<XML::NewsML_G2::Organisation> instance
290  
291 =item add_paragraph
292  
293 Takes a string to be added to the C<paragraphs> Node instance as a
294 C<p> element. To have more control over the created XHTML output,
295 directly set the C<paragraphs> attribute with a Node instance you
296 created by yourself.
297  
298 =item add_product
299  
300 Add a new L<XML::NewsML_G2::Product> instance
301  
302 =item add_source
303  
304 Add a string to the sources
305  
306 =item add_topic
307  
308 Add a new L<XML::NewsML_G2::Topic> instance
309  
310 =back
311  
312 =head1 AUTHOR
313  
314 Philipp Gortan C<< <philipp.gortan@apa.at> >>
315  
316 =head1 LICENCE AND COPYRIGHT
317  
318 Copyright (c) 2013, APA-IT. All rights reserved.
319  
320 See L<XML::NewsML_G2> for the license.
« blib/lib/XML/NewsML_G2/Scheme.pm ↑ Summary blib/lib/XML/NewsML_G2.pm »