File Coverage

blib/lib/Data/OFN/Thing.pm
Criterion Covered Total %
statement 32 32 100.0
branch n/a
condition n/a
subroutine 8 8 100.0
pod 0 1 0.0
total 40 41 97.5


line stmt bran cond sub pod time code
1             package Data::OFN::Thing;
2              
3 12     12   321088 use strict;
  12         32  
  12         517  
4 12     12   133 use warnings;
  12         37  
  12         755  
5              
6 12     12   3418 use Mo qw(build default is);
  12         4623  
  12         76  
7 12     12   29944 use Mo::utils 0.08 qw(check_isa);
  12         121577  
  12         526  
8 12     12   8682 use Mo::utils::Array qw(check_array_object);
  12         33923  
  12         319  
9 12     12   7083 use Mo::utils::IRI 0.02 qw(check_iri);
  12         3686380  
  12         488  
10 12     12   8971 use Mo::utils::Number qw(check_positive_natural);
  12         30917  
  12         308  
11              
12             our $VERSION = 0.02;
13              
14             has attachment => (
15             default => [],
16             is => 'ro',
17             );
18              
19             has created => (
20             is => 'ro',
21             );
22              
23             has description => (
24             default => [],
25             is => 'ro',
26             );
27              
28             has id => (
29             is => 'ro',
30             );
31              
32             has invalidated => (
33             is => 'ro',
34             );
35              
36             has iri => (
37             is => 'ro',
38             );
39              
40             has name => (
41             default => [],
42             is => 'ro',
43             );
44              
45             has relevant_to => (
46             is => 'ro',
47             );
48              
49             has updated => (
50             is => 'ro',
51             );
52              
53             sub BUILD {
54 27     27 0 8404812 my $self = shift;
55              
56             # Check 'attachment'.
57 27         167 check_array_object($self, 'attachment', 'Data::OFN::DigitalObject',
58             'Digital object');
59              
60             # Check 'created'.
61 25         366 check_isa($self, 'created', 'Data::OFN::Common::TimeMoment');
62              
63             # Check 'description'.
64 25         534 check_array_object($self, 'description', 'Data::Text::Simple', 'Description');
65              
66             # Check 'id'.
67 23         364 check_positive_natural($self, 'id');
68              
69             # Check 'invalidated'.
70 22         431 check_isa($self, 'invalidated', 'Data::OFN::Common::TimeMoment');
71              
72             # Check 'iri'.
73 22         330 check_iri($self, 'iri');
74              
75             # Check 'name'.
76 21         45093 check_array_object($self, 'name', 'Data::Text::Simple', 'Name');
77              
78             # Check 'relevant_to'.
79 19         268 check_isa($self, 'relevant_to', 'Data::OFN::Common::TimeMoment');
80              
81             # Check 'updated'.
82 19         240 check_isa($self, 'updated', 'Data::OFN::Common::TimeMoment');
83              
84 19         305 return;
85             }
86              
87             1;
88              
89             __END__
90              
91             =pod
92              
93             =encoding utf8
94              
95             =head1 NAME
96              
97             Data::OFN::Thing - Data object for OFN thing.
98              
99             =head1 SYNOPSIS
100              
101             use Data::OFN::Thing;
102              
103             my $obj = Data::OFN::Thing->new(%params);
104             my $attachment_ar = $obj->attachment;
105             my $created = $obj->created;
106             my $description_ar = $obj->description;
107             my $id = $obj->id;
108             my $invalidated = $obj->invalidated;
109             my $iri = $obj->iri;
110             my $name_ar = $obj->name;
111             my $relevant_to = $obj->relevant_to;
112             my $updated = $obj->updated;
113              
114             =head1 DESCRIPTION
115              
116             Immutable data object for OFN (Otevřené formální normy) representation of
117             thing in the Czech Republic.
118              
119             This object is actual with L<2020-07-01|https://ofn.gov.cz/v%C4%9Bc/2020-07-01/> version of
120             OFN thing standard.
121              
122             The thing is base object for other OFN objects.
123              
124             =head1 METHODS
125              
126             =head2 C<new>
127              
128             my $obj = Data::OFN::Thing->new(%params);
129              
130             Constructor.
131              
132             =over 8
133              
134             =item * C<attachment>
135              
136             The thing attachments.
137             It's reference to array with L<Data::OFN::DigitalObject> instances.
138              
139             It's optional.
140              
141             Default value is [].
142              
143             =item * C<created>
144              
145             Time moment when the thing was created.
146             It's L<Data::OFN::Comment::TimeMoment> instance.
147              
148             It's optional.
149              
150             Default value is undef.
151              
152             =item * C<description>
153              
154             The description of the thing.
155             It's reference to array with L<Data::Text::Simple> instances.
156              
157             It's optional.
158              
159             Default value is [].
160              
161             =item * C<id>
162              
163             The thing id.
164              
165             This is not official identifier of address in the Czech Republic.
166             It's used for internal identification like database.
167              
168             It's optional.
169              
170             Default value is undef.
171              
172             =item * C<invalidated>
173              
174             Time moment when the thing was invalidated.
175             It's L<Data::OFN::Comment::TimeMoment> instance.
176              
177             It's optional.
178              
179             Default value is undef.
180              
181             =item * C<iri>
182              
183             IRI of the thing.
184              
185             It's optional.
186              
187             Default value is undef.
188              
189             =item * C<name>
190              
191             The name of the thing.
192             It's reference to array with L<Data::Text::Simple> instances.
193              
194             It's optional.
195              
196             Default value is [].
197              
198             =item * C<relevant_to>
199              
200             Time moment to which the thing is relevant.
201             It's L<Data::OFN::Comment::TimeMoment> instance.
202              
203             It's optional.
204              
205             Default value is undef.
206              
207             =item * C<updated>
208              
209             Time moment when the thing was updated.
210             It's L<Data::OFN::Comment::TimeMoment> instance.
211              
212             It's optional.
213              
214             Default value is undef.
215              
216             =back
217              
218             Returns instance of object.
219              
220             =head2 C<attachment>
221              
222             my $attachment_ar = $obj->attachment;
223              
224             Get list of attachments.
225              
226             Returns reference to array with L<Data::OFN::DigitalObject> instances.
227              
228             =head2 C<created>
229              
230             my $created = $obj->created;
231              
232             Get time moment when the thing was created.
233              
234             Returns L<Data::OFN::Common::TimeMoment> instance.
235              
236             =head2 C<description>
237              
238             my $description_ar = $obj->description;
239              
240             Get description of the thing.
241              
242             Returns reference to array with L<Data::Text::Simple> instances.
243              
244             =head2 C<id>
245              
246             my $id = $obj->id;
247              
248             Get OFN thing id.
249              
250             Returns positive natural number.
251              
252             =head2 C<invalidated>
253              
254             my $invalidated = $obj->invalidated;
255              
256             Get time moment when the thing was invalidated.
257              
258             Returns L<Data::OFN::Common::TimeMoment> instance.
259              
260             =head2 C<iri>
261              
262             my $iri = $obj->iri;
263              
264             Get IRI of the thing.
265              
266             Returns string with IRI.
267              
268             =head2 C<name>
269              
270             my $name_ar = $obj->name;
271              
272             Get name of the thing.
273              
274             Returns reference to array with L<Data::Text::Simple> instances.
275              
276             =head2 C<relevant_to>
277              
278             my $relevant_to = $obj->relevant_to;
279              
280             Get time moment to which the thing is relevant.
281              
282             Returns L<Data::OFN::Common::TimeMoment> instance.
283              
284             =head2 C<updated>
285              
286             my $updated = $obj->updated;
287              
288             Get time moment when the thing was updated.
289              
290             Returns L<Data::OFN::Common::TimeMoment> instance.
291              
292             =head1 ERRORS
293              
294             new():
295             From Mo::utils::check_isa():
296             Parameter 'created' must be a 'Data::OFN::Common::TimeMoment' object.
297             Value: %s
298             Reference: %s
299             Parameter 'invalidated' must be a 'Data::OFN::Common::TimeMoment' object.
300             Value: %s
301             Reference: %s
302             Parameter 'relevant_to' must be a 'Data::OFN::Common::TimeMoment' object.
303             Value: %s
304             Reference: %s
305             Parameter 'updated' must be a 'Data::OFN::Common::TimeMoment' object.
306             Value: %s
307             Reference: %s
308              
309             From Mo::utils::Array::check_array_object():
310             Parameter 'attachment' must be a array.
311             Value: %s
312             Reference: %s
313             Parameter 'attachment' with array must contain 'Data::OFN::DigitalObject' objects.
314             Value: %s
315             Reference: %s
316             Parameter 'description' must be a array.
317             Value: %s
318             Reference: %s
319             Parameter 'description' with array must contain 'Data::Text::Simple' objects.
320             Value: %s
321             Reference: %s
322             Parameter 'name' must be a array.
323             Value: %s
324             Reference: %s
325             Parameter 'name' with array must contain 'Data::Text::Simple' objects.
326             Value: %s
327             Reference: %s
328              
329             From Mo::utils::IRI::check_iri():
330             Parameter 'iri' doesn't contain valid IRI.
331             Value: %s
332              
333             From Mo::utils::Number::check_positive_natural():
334             Parameter 'id' must be a positive natural number.
335             Value: %s
336              
337             =head1 EXAMPLE1
338              
339             =for comment filename=thing_simple.pl
340              
341             use strict;
342             use warnings;
343              
344             use Data::OFN::Common::TimeMoment;
345             use Data::OFN::Thing;
346             use Data::Text::Simple;
347             use DateTime;
348             use Unicode::UTF8 qw(decode_utf8 encode_utf8);
349              
350             my $obj = Data::OFN::Thing->new(
351             'created' => Data::OFN::Common::TimeMoment->new(
352             'date_and_time' => DateTime->new(
353             'day' => 27,
354             'month' => 9,
355             'year' => 2019,
356             'hour' => 9,
357             'minute' => 30,
358             'time_zone' => '+02:00',
359             ),
360             ),
361             'description' => [
362             Data::Text::Simple->new(
363             'lang' => 'cs',
364             'text' => decode_utf8("Ve čtvrtek 26. září večer došlo k loupeži banky na Masarykově náměstí.\nLupič pak prchal směrem ven z města. Obsluha městského kamerového systému incident zaznamenala,\nstrážníci městské policie zastavili auto ve Francouzské ulici a přivolali státní policii.\nTi záležitost převzali k dořešení. Pachateli hrozí až 10 let za mřížemi."),
365             ),
366             Data::Text::Simple->new(
367             'lang' => 'en',
368             'text' => decode_utf8("On Thursday evening, September 26, the bank was robbed on Masaryk Square.\nThe robber then fled out of town. The operator of the city's camera system recorded the incident,\nthus the city police officers were able to identify and stop the car in Francouzská Street and called the state police.\nThey took over the matter. Offenders face up to 10 years behind bars."),
369             ),
370             ],
371             'id' => 7,
372             'iri' => decode_utf8('https://www.trebic.cz/zdroj/aktualita/2020/dopadení-lupiče-na-francouzské-ulici'),
373             'name' => [
374             Data::Text::Simple->new(
375             'lang' => 'cs',
376             'text' => decode_utf8('Díky policistům byl lupič dopaden'),
377             ),
378             Data::Text::Simple->new(
379             'lang' => 'en',
380             'text' => 'Culprit was immediately caught, thanks to the police.',
381             ),
382             ],
383             'relevant_to' => Data::OFN::Common::TimeMoment->new(
384             'date_and_time' => DateTime->new(
385             'day' => 27,
386             'month' => 11,
387             'year' => 2019,
388             'hour' => 9,
389             'time_zone' => '+02:00',
390             ),
391             ),
392             );
393              
394             sub _text {
395             my $obj = shift;
396              
397             return encode_utf8($obj->text.' ('.$obj->lang.')');
398             }
399              
400             # Print out.
401             print 'Id: '.$obj->id."\n";
402             print 'Name: '._text($obj->name->[0])."\n";
403             print 'Name: '._text($obj->name->[1])."\n";
404             print 'Description: '._text($obj->description->[0])."\n";
405             print 'Description: '._text($obj->description->[1])."\n";
406             print 'IRI: '.encode_utf8($obj->iri)."\n";
407             print 'Created: '.$obj->created->date_and_time."\n";
408             print 'Relevant to: '.$obj->relevant_to->date_and_time."\n";
409              
410             # Output:
411             # Id: 7
412             # Name: Díky policistům byl lupič dopaden (cs)
413             # Name: Culprit was immediately caught, thanks to the police. (en)
414             # Description: Ve čtvrtek 26. září večer došlo k loupeži banky na Masarykově náměstí.
415             # Lupič pak prchal směrem ven z města. Obsluha městského kamerového systému incident zaznamenala,
416             # strážníci městské policie zastavili auto ve Francouzské ulici a přivolali státní policii.
417             # Ti záležitost převzali k dořešení. Pachateli hrozí až 10 let za mřížemi. (cs)
418             # Description: On Thursday evening, September 26, the bank was robbed on Masaryk Square.
419             # The robber then fled out of town. The operator of the city's camera system recorded the incident,
420             # thus the city police officers were able to identify and stop the car in Francouzská Street and called the state police.
421             # They took over the matter. Offenders face up to 10 years behind bars. (en)
422             # IRI: https://www.trebic.cz/zdroj/aktualita/2020/dopadení-lupiče-na-francouzské-ulici
423             # Created: 2019-09-27T09:30:00
424             # Relevant to: 2019-11-27T09:00:00
425              
426             =head1 EXAMPLE2
427              
428             =for comment filename=thing_invalidated.pl
429              
430             use strict;
431             use warnings;
432              
433             use Data::OFN::Common::TimeMoment;
434             use Data::OFN::Thing;
435             use DateTime;
436              
437             my $obj = Data::OFN::Thing->new(
438             'iri' => 'https://www.spilberk.cz/',
439             'invalidated' => Data::OFN::Common::TimeMoment->new(
440             'date_and_time' => DateTime->new(
441             'day' => 27,
442             'month' => 11,
443             'year' => 2019,
444             'hour' => 9,
445             'time_zone' => '+02:00',
446             ),
447             ),
448             );
449              
450             # Print out.
451             print 'IRI: '.$obj->iri."\n";
452             print 'Invalidated: '.$obj->invalidated->date_and_time."\n";
453              
454             # Output:
455             # IRI: https://www.spilberk.cz/
456             # Invalidated: 2019-11-27T09:00:00
457              
458             =head1 DEPENDENCIES
459              
460             L<Mo>,
461             L<Mo::utils>,
462             L<Mo::utils::Array>,
463             L<Mo::utils::IRI>,
464             L<Mo::utils::Number>.
465              
466             =head1 REPOSITORY
467              
468             L<https://github.com/michal-josef-spacek/Data-OFN-Thing>
469              
470             =head1 AUTHOR
471              
472             Michal Josef Špaček L<mailto:skim@cpan.org>
473              
474             L<http://skim.cz>
475              
476             =head1 LICENSE AND COPYRIGHT
477              
478             © 2023-2025 Michal Josef Špaček
479              
480             BSD 2-Clause License
481              
482             =head1 VERSION
483              
484             0.02
485              
486             =cut