File Coverage

blib/lib/Data/Image.pm
Criterion Covered Total %
statement 27 27 100.0
branch n/a
condition n/a
subroutine 6 6 100.0
pod 0 1 0.0
total 33 34 97.0


line stmt bran cond sub pod time code
1             package Data::Image;
2              
3 12     12   212741 use strict;
  12         23  
  12         542  
4 12     12   73 use warnings;
  12         32  
  12         765  
5              
6 12     12   5892 use Mo qw(build is);
  12         8185  
  12         67  
7 12     12   30024 use Mo::utils 0.28 qw(check_code check_isa check_length check_number check_number_id check_required);
  12         226342  
  12         307  
8 12     12   9656 use Mo::utils::URI qw(check_location);
  12         1069240  
  12         423  
9              
10             our $VERSION = 0.05;
11              
12             has author => (
13             is => 'ro',
14             );
15              
16             has comment => (
17             is => 'ro',
18             );
19              
20             has dt_created => (
21             is => 'ro',
22             );
23              
24             has height => (
25             is => 'ro',
26             );
27              
28             has id => (
29             is => 'ro',
30             );
31              
32             has size => (
33             is => 'ro',
34             );
35              
36             has url => (
37             is => 'ro',
38             );
39              
40             has url_cb => (
41             is => 'ro',
42             );
43              
44             has width => (
45             is => 'ro',
46             );
47              
48             sub BUILD {
49 25     25 0 4916062 my $self = shift;
50              
51             # Check author.
52 25         135 check_length($self, 'author', 255);
53              
54             # Check comment.
55 24         452 check_length($self, 'comment', 1000);
56              
57             # Check date created.
58 23         257 check_isa($self, 'dt_created', 'DateTime');
59              
60             # Check height.
61 23         311 check_number($self, 'height');
62              
63             # Check id.
64 23         253 check_number_id($self, 'id');
65              
66             # Check size.
67 22         238 check_number($self, 'size');
68              
69             # Check URL.
70 22         215 check_length($self, 'url', 255);
71 21         323 check_location($self, 'url');
72              
73             # Check URL callback.
74 20         72497 check_code($self, 'url_cb');
75              
76             # Check width.
77 20         252 check_number($self, 'width');
78              
79 20         230 return;
80             }
81              
82             1;
83              
84             __END__
85              
86             =pod
87              
88             =encoding utf8
89              
90             =head1 NAME
91              
92             Data::Image - Data object for image.
93              
94             =head1 SYNOPSIS
95              
96             use Data::Image;
97              
98             my $obj = Data::Image->new(%params);
99             my $author = $obj->author;
100             my $comment = $obj->comment;
101             my $dt_created = $obj->dt_created;
102             my $height = $obj->height;
103             my $id = $obj->id;
104             my $size = $obj->size;
105             my $url = $obj->url;
106             my $url_cb = $obj->url_cb;
107             my $width = $obj->width;
108              
109             =head1 METHODS
110              
111             =head2 C<new>
112              
113             my $obj = Data::Image->new(%params);
114              
115             Constructor.
116              
117             =over 8
118              
119             =item * C<author>
120              
121             Image author.
122              
123             It's optional.
124              
125             Default value is undef.
126              
127             =item * C<comment>
128              
129             Image comment.
130              
131             It's optional.
132              
133             Default value is undef.
134              
135             =item * C<dt_created>
136              
137             Date and time the image was created.
138              
139             Value must be L<DateTime> object.
140              
141             It's optional.
142              
143             =item * C<height>
144              
145             Image height.
146              
147             It's optional.
148              
149             Default value is undef.
150              
151             =item * C<id>
152              
153             Image id.
154              
155             It's optional.
156              
157             Default value is undef.
158              
159             =item * C<size>
160              
161             Image size.
162              
163             It's optional.
164              
165             Default value is undef.
166              
167             =item * C<url>
168              
169             URL (location) of image.
170              
171             It's optional.
172              
173             Default value is undef.
174              
175             =item * C<url_cb>
176              
177             URL callback. To get URL from code.
178              
179             It's optional.
180              
181             Default value is undef.
182              
183             =item * C<width>
184              
185             Image width.
186              
187             It's optional.
188              
189             Default value is undef.
190              
191             =back
192              
193             Returns instance of object.
194              
195             =head2 C<author>
196              
197             my $author = $obj->author;
198              
199             Get image author.
200              
201             Returns string.
202              
203             =head2 C<comment>
204              
205             my $comment = $obj->comment;
206              
207             Get image comment.
208              
209             Returns string.
210              
211             =head2 C<dt_created>
212              
213             my $dt_created = $obj->dt_created;
214              
215             Get date and time the image was created.
216              
217             Returns L<DateTime> object.
218              
219             =head2 C<height>
220              
221             my $height = $obj->height;
222              
223             Get image height.
224              
225             Returns number.
226              
227             =head2 C<id>
228              
229             my $id = $obj->id;
230              
231             Get image id.
232              
233             Returns number.
234              
235             =head2 C<size>
236              
237             my $size = $obj->size;
238              
239             Get image size.
240              
241             Returns number.
242              
243             =head2 C<url>
244              
245             my $url = $obj->url;
246              
247             Get URL (location) of image.
248              
249             Returns string.
250              
251             =head2 C<url_cb>
252              
253             my $url_cb = $obj->url_cb;
254              
255             Get URL callback.
256              
257             Returns code.
258              
259             =head2 C<width>
260              
261             my $width = $obj->width;
262              
263             Get image width.
264              
265             Returns number.
266              
267             =head1 ERRORS
268              
269             new():
270             From Mo::utils:
271             Parameter 'author' has length greater than '255'.
272             Value: %s
273             Parameter 'comment' has length greater than '1000'.
274             Value: %s
275             Parameter 'dt_created' must be a 'DateTime' object.
276             Value: %s
277             Reference: %s
278             Parameter 'height' must a number.
279             Value: %s
280             Parameter 'id' must be a natural number.
281             Value: %s
282             Parameter 'size' must a number.
283             Value: %s
284             Parameter 'url' has length greater than '255'.
285             Value: %s
286             Parameter 'url_cb' must be a code.
287             Value: %s
288             Parameter 'width' must a number.
289             Value: %s
290              
291             From Mo::utils::URI:
292             Parameter 'url' doesn't contain valid location.
293             Value: %s
294              
295             =head1 EXAMPLE
296              
297             =for comment filename=create_and_print_image.pl
298              
299             use strict;
300             use warnings;
301              
302             use Data::Image;
303             use DateTime;
304              
305             my $obj = Data::Image->new(
306             'author' => 'Zuzana Zonova',
307             'comment' => 'Michal from Czechia',
308             'dt_created' => DateTime->new(
309             'day' => 1,
310             'month' => 1,
311             'year' => 2022,
312             ),
313             'height' => 2730,
314             'size' => 1040304,
315             'url' => 'https://upload.wikimedia.org/wikipedia/commons/a/a4/Michal_from_Czechia.jpg',
316             'width' => 4096,
317             );
318              
319             # Print out.
320             print 'Author: '.$obj->author."\n";
321             print 'Comment: '.$obj->comment."\n";
322             print 'Height: '.$obj->height."\n";
323             print 'Size: '.$obj->size."\n";
324             print 'URL: '.$obj->url."\n";
325             print 'Width: '.$obj->width."\n";
326             print 'Date and time the image was created: '.$obj->dt_created."\n";
327              
328             # Output:
329             # Author: Zuzana Zonova
330             # Comment: Michal from Czechia
331             # Height: 2730
332             # Size: 1040304
333             # URL: https://upload.wikimedia.org/wikipedia/commons/a/a4/Michal_from_Czechia.jpg
334             # Width: 4096
335             # Date and time the photo was created: 2022-01-01T00:00:00
336              
337             =head1 DEPENDENCIES
338              
339             L<Mo>,
340             L<Mo::utils>,
341             L<Mo::utils::URI>.
342              
343             =head1 SEE ALSO
344              
345             =over
346              
347             =item L<Data::Commons::Image>
348              
349             Data object for Wikimedia Commons image.
350              
351             =back
352              
353             =head1 REPOSITORY
354              
355             L<https://github.com/michal-josef-spacek/Data-Image>
356              
357             =head1 AUTHOR
358              
359             Michal Josef Špaček L<mailto:skim@cpan.org>
360              
361             L<http://skim.cz>
362              
363             =head1 LICENSE AND COPYRIGHT
364              
365             © 2022-2025 Michal Josef Špaček
366              
367             BSD 2-Clause License
368              
369             =head1 VERSION
370              
371             0.05
372              
373             =cut