File Coverage

blib/lib/Data/Navigation/Item.pm
Criterion Covered Total %
statement 27 27 100.0
branch n/a
condition n/a
subroutine 7 7 100.0
pod 0 1 0.0
total 34 35 97.1


line stmt bran cond sub pod time code
1             package Data::Navigation::Item;
2              
3 9     9   176068 use strict;
  9         24  
  9         363  
4 9     9   51 use warnings;
  9         44  
  9         674  
5              
6 9     9   5011 use Mo qw(build is);
  9         10627  
  9         55  
7 9     9   22865 use Mo::utils 0.28 qw(check_length check_number_id check_required);
  9         185479  
  9         295  
8 9     9   8018 use Mo::utils::CSS 0.02 qw(check_css_class);
  9         117586  
  9         264  
9 9     9   8894 use Mo::utils::URI qw(check_location);
  9         821547  
  9         331  
10              
11             our $VERSION = 0.02;
12              
13             has class => (
14             is => 'ro',
15             );
16              
17             has desc => (
18             is => 'ro',
19             );
20              
21             has id => (
22             is => 'ro',
23             );
24              
25             has image => (
26             is => 'ro',
27             );
28              
29             has location => (
30             is => 'ro',
31             );
32              
33             has title => (
34             is => 'ro',
35             );
36              
37             sub BUILD {
38 21     21 0 2883155 my $self = shift;
39              
40             # Check class.
41 21         142 check_css_class($self, 'class');
42              
43             # Check desc.
44 19         404 check_length($self, 'desc', 1000);
45              
46             # Check id.
47 18         296 check_number_id($self, 'id');
48              
49             # Check image.
50             # XXX check image.
51 17         272 check_location($self, 'image');
52              
53             # Check location.
54 16         15593 check_location($self, 'location');
55              
56             # Check title.
57 15         12802 check_required($self, 'title');
58 14         146 check_length($self, 'title', 100);
59              
60 13         209 return;
61             }
62              
63             1;
64              
65             __END__
66              
67             =pod
68              
69             =encoding utf8
70              
71             =head1 NAME
72              
73             Data::Navigation::Item - Data object for navigation item.
74              
75             =head1 SYNOPSIS
76              
77             use Data::Navigation::Item;
78              
79             my $obj = Data::Navigation::Item->new(%params);
80             my $class = $obj->class;
81             my $desc = $obj->desc;
82             my $id = $obj->id;
83             my $image = $obj->image;
84             my $location = $obj->location;
85             my $title = $obj->title;
86              
87             =head1 METHODS
88              
89             =head2 C<new>
90              
91             my $obj = Data::Navigation::Item->new(%params);
92              
93             Constructor.
94              
95             =over 8
96              
97             =item * C<class>
98              
99             Navigation item class.
100              
101             Value type is same as CSS class.
102              
103             It's optional.
104              
105             Default value is undef.
106              
107             =item * C<desc>
108              
109             Navigation item description.
110              
111             Maximum length is 1000 characters.
112              
113             Default value is undef.
114              
115             =item * C<id>
116              
117             Navigation item id. It's number.
118              
119             It's optional.
120              
121             Default value is undef.
122              
123             =item * C<image>
124              
125             Navigation item image location.
126              
127             It's optional.
128              
129             Default value is undef.
130              
131             =item * C<location>
132              
133             Navigation item location. Link to content.
134              
135             It's optional.
136              
137             Default value is undef.
138              
139             =item * C<title>
140              
141             Navigation item title.
142              
143             Maximum length is 100 characters.
144              
145             It's required.
146              
147             Default value is undef.
148              
149             =back
150              
151             Returns instance of object.
152              
153             =head2 C<class>
154              
155             my $class = $obj->class;
156              
157             Get navigation item class.
158              
159             Returns string.
160              
161             =head2 C<desc>
162              
163             my $desc = $obj->desc;
164              
165             Get navigation item description.
166              
167             Returns string.
168              
169             =head2 C<id>
170              
171             my $id = $obj->id;
172              
173             Get navigation item id.
174              
175             Returns number.
176              
177             =head2 C<image>
178              
179             my $image = $obj->image;
180              
181             Get navigation item image location.
182              
183             Returns string.
184              
185             =head2 C<location>
186              
187             my $location = $obj->location;
188              
189             =head2 C<title>
190              
191             my $title = $obj->title;
192              
193             Get navigation item title;
194              
195             Returns string.
196              
197             =head1 ERRORS
198              
199             new():
200             From Mo::utils:
201             From Mo::utils::check_number_id():
202             Parameter 'id' must be a number.
203             Value: %s
204             From Mo::utils::check_length():
205             Parameter 'desc' has length greater than '1000'.
206             Value: %s
207             Parameter 'title' has length greater than '100'.
208             Value: %s
209             From Mo::utils::check_required():
210             Parameter 'title' is required.
211             From Mo::utils::CSS::check_css_class():
212             Parameter 'class' has bad CSS class name.
213             Value: %s
214             Parameter 'class' has bad CSS class name (number on begin).
215             Value: %s
216             From Mo::utils::URI::check_location():
217             Parameter 'image' doesn't contain valid location.
218             Value: %s
219             Parameter 'location' doesn't contain valid location.
220             Value: %s
221              
222             =head1 EXAMPLE
223              
224             =for comment filename=nav_item.pl
225              
226             use strict;
227             use warnings;
228              
229             use Data::Navigation::Item;
230              
231             my $obj = Data::Navigation::Item->new(
232             'class' => 'nav-item',
233             'desc' => 'This is description',
234             'id' => 1,
235             'image' => '/img/foo.png',
236             'location' => '/title',
237             'title' => 'Title',
238             );
239              
240             # Print out.
241             print 'Class: '.$obj->class."\n";
242             print 'Description: '.$obj->desc."\n";
243             print 'Id: '.$obj->id."\n";
244             print 'Image: '.$obj->image."\n";
245             print 'Location: '.$obj->location."\n";
246             print 'Title: '.$obj->title."\n";
247              
248             # Output:
249             # Class: nav-item
250             # Description: This is description
251             # Id: 1
252             # Image: /img/foo.png
253             # Location: /title
254             # Title: Title
255              
256             =head1 DEPENDENCIES
257              
258             L<Mo>,
259             L<Mo::utils>,
260             L<Mo::utils::CSS>,
261             L<Mo::utils::URI>.
262              
263             =head1 REPOSITORY
264              
265             L<https://github.com/michal-josef-spacek/Data-Navigation-Item>
266              
267             =head1 AUTHOR
268              
269             Michal Josef Špaček L<mailto:skim@cpan.org>
270              
271             L<http://skim.cz>
272              
273             =head1 LICENSE AND COPYRIGHT
274              
275             © 2024 Michal Josef Špaček
276              
277             BSD 2-Clause License
278              
279             =head1 VERSION
280              
281             0.02
282              
283             =cut