File Coverage

blib/lib/Data/Image.pm
Criterion Covered Total %
statement 22 22 100.0
branch n/a
condition n/a
subroutine 5 5 100.0
pod 0 1 0.0
total 27 28 96.4


line stmt bran cond sub pod time code
1              
2             use strict;
3 11     11   56038 use warnings;
  11         67  
  11         234  
4 11     11   37  
  11         18  
  11         313  
5             use Mo qw(build is);
6 11     11   3712 use Mo::utils qw(check_code check_length check_number check_required);
  11         4402  
  11         41  
7 11     11   16347  
  11         127885  
  11         150  
8             our $VERSION = 0.01;
9              
10             has author => (
11             is => 'ro',
12             );
13              
14             has comment => (
15             is => 'ro',
16             );
17              
18             has height => (
19             is => 'ro',
20             );
21              
22             has id => (
23             is => 'ro',
24             );
25              
26             has size => (
27             is => 'ro',
28             );
29              
30             has url => (
31             is => 'ro',
32             );
33              
34             has url_cb => (
35             is => 'ro',
36             );
37              
38             has width => (
39             is => 'ro',
40             );
41              
42             my $self = shift;
43              
44 20     20 0 19598 # Check author.
45             check_length($self, 'author', 255);
46              
47 20         68 # Check comment.
48             check_length($self, 'comment', 1000);
49              
50 20         233 # Check height.
51             check_number($self, 'height');
52              
53 19         146 # Check id.
54             check_number($self, 'id');
55              
56 19         141 # Check size.
57             check_number($self, 'size');
58              
59 19         132 # Check URL.
60             check_length($self, 'url', 255);
61              
62 19         130 # Check URL callback.
63             check_code($self, 'url_cb');
64              
65 18         159 # Check width.
66             check_number($self, 'width');
67              
68 18         131 return;
69             }
70 18         109  
71             1;
72              
73              
74             =pod
75              
76             =encoding utf8
77              
78             =head1 NAME
79              
80             Data::Image - Data object for image.
81              
82             =head1 SYNOPSIS
83              
84             use Data::Image;
85              
86             my $obj = Data::Image->new(%params);
87             my $author = $obj->author;
88             my $comment = $obj->comment;
89             my $height = $obj->height;
90             my $id = $obj->id;
91             my $size = $obj->size;
92             my $url = $obj->url;
93             my $url_cb = $obj->url_cb;
94             my $width = $obj->width;
95              
96             =head1 METHODS
97              
98             =head2 C<new>
99              
100             my $obj = Data::Image->new(%params);
101              
102             Constructor.
103              
104             Returns instance of object.
105              
106             =over 8
107              
108             =item * C<author>
109              
110             Image author.
111             It's optional.
112             Default value is undef.
113              
114             =item * C<comment>
115              
116             Image comment.
117             It's optional.
118             Default value is undef.
119              
120             =item * C<height>
121              
122             Image height.
123             It's optional.
124             Default value is undef.
125              
126             =item * C<id>
127              
128             Image id.
129             It's optional.
130             Default value is undef.
131              
132             =item * C<size>
133              
134             Image size.
135             It's optional.
136             Default value is undef.
137              
138             =item * C<url>
139              
140             URL of image.
141             It's optional.
142             Default value is undef.
143              
144             =item * C<url_cb>
145              
146             URL callback. To get URL from code.
147             It's optional.
148             Default value is undef.
149              
150             =item * C<width>
151              
152             Image width.
153             It's optional.
154             Default value is undef.
155              
156             =back
157              
158             =head2 C<author>
159              
160             my $author = $obj->author;
161              
162             Get image author.
163              
164             Returns string.
165              
166             =head2 C<comment>
167              
168             my $comment = $obj->comment;
169              
170             Get image comment.
171              
172             Returns string.
173              
174             =head2 C<height>
175              
176             my $height = $obj->height;
177              
178             Get image height.
179              
180             Returns number.
181              
182             =head2 C<id>
183              
184             my $id = $obj->id;
185              
186             Get image id.
187              
188             Returns number.
189              
190             =head2 C<size>
191              
192             my $size = $obj->size;
193              
194             Get image size.
195              
196             Returns number.
197              
198             =head2 C<url>
199              
200             my $url = $obj->url;
201              
202             Get URL of image.
203              
204             Returns string.
205              
206             =head2 C<url_cb>
207              
208             my $url_cb = $obj->url_cb;
209              
210             Get URL callback.
211              
212             Returns code.
213              
214             =head2 C<width>
215              
216             my $width = $obj->width;
217              
218             Get image width.
219              
220             Returns number.
221              
222             =head1 EXAMPLE
223              
224             =for comment filename=create_and_print_image.pl
225              
226             use strict;
227             use warnings;
228              
229             use Data::Image;
230              
231             my $obj = Data::Image->new(
232             'author' => 'Zuzana Zonova',
233             'comment' => 'Michal from Czechia',
234             'height' => 2730,
235             'size' => 1040304,
236             'url' => 'https://upload.wikimedia.org/wikipedia/commons/a/a4/Michal_from_Czechia.jpg',
237             'width' => 4096,
238             );
239              
240             # Print out.
241             print 'Author: '.$obj->author."\n";
242             print 'Comment: '.$obj->comment."\n";
243             print 'Height: '.$obj->height."\n";
244             print 'Size: '.$obj->size."\n";
245             print 'URL: '.$obj->url."\n";
246             print 'Width: '.$obj->width."\n";
247              
248             # Output:
249             # Author: Zuzana Zonova
250             # Comment: Michal from Czechia
251             # Height: 2730
252             # Size: 1040304
253             # URL: https://upload.wikimedia.org/wikipedia/commons/a/a4/Michal_from_Czechia.jpg
254             # Width: 4096
255              
256             =head1 DEPENDENCIES
257              
258             L<Mo>,
259             L<Mo::utils>.
260              
261             =head1 REPOSITORY
262              
263             L<https://github.com/michal-josef-spacek/Data-Image>
264              
265             =head1 AUTHOR
266              
267             Michal Josef Špaček L<mailto:skim@cpan.org>
268              
269             L<http://skim.cz>
270              
271             =head1 LICENSE AND COPYRIGHT
272              
273             © 2022 Michal Josef Špaček
274              
275             BSD 2-Clause License
276              
277             =head1 VERSION
278              
279             0.01
280              
281             =cut