File Coverage

blib/lib/Data/Message/Board/Comment.pm
Criterion Covered Total %
statement 24 24 100.0
branch n/a
condition n/a
subroutine 6 6 100.0
pod 0 1 0.0
total 30 31 96.7


line stmt bran cond sub pod time code
1             package Data::Message::Board::Comment;
2              
3 16     16   132864 use strict;
  16         57  
  16         538  
4 16     16   65 use warnings;
  16         28  
  16         975  
5              
6 16     16   3503 use Mo qw(build default is);
  16         4871  
  16         95  
7 16     16   26404 use Mo::utils 0.28 qw(check_isa check_length check_required);
  16         118477  
  16         765  
8 16     16   5200 use Mo::utils::Number qw(check_positive_natural);
  16         18223  
  16         1953  
9              
10             our $VERSION = 0.06;
11              
12             has author => (
13             is => 'ro',
14             );
15              
16             has date => (
17             is => 'ro',
18             );
19              
20             has id => (
21             is => 'ro',
22             );
23              
24             has message => (
25             is => 'ro',
26             );
27              
28             sub BUILD {
29 29     29 0 6282595 my $self = shift;
30              
31             # Check author.
32 29         155 check_required($self, 'author');
33 28         389 check_isa($self, 'author', 'Data::Person');
34              
35             # Check date.
36 26         727 check_required($self, 'date');
37 25         172 check_isa($self, 'date', 'DateTime');
38              
39             # Check id.
40 23         489 check_positive_natural($self, 'id');
41              
42             # Check message.
43 22         401 check_required($self, 'message');
44 21         178 check_length($self, 'message', 4096);
45              
46 20         244 return;
47             }
48              
49             1;
50              
51             __END__
52              
53             =pod
54              
55             =encoding utf8
56              
57             =head1 NAME
58              
59             Data::Message::Board::Comment - Data object for Message board comment.
60              
61             =head1 SYNOPSIS
62              
63             use Data::Message::Board::Comment;
64              
65             my $obj = Data::Message::Board::Comment->new(%params);
66             my $author = $obj->author;
67             my $date = $obj->date;
68             my $id = $obj->id;
69             my $message = $obj->message;
70              
71             =head1 METHODS
72              
73             =head2 C<new>
74              
75             my $obj = Data::Message::Board::Comment->new(%params);
76              
77             Constructor.
78              
79             =over 8
80              
81             =item * C<author>
82              
83             Author object which is L<Data::Person> instance.
84              
85             It's required.
86              
87             =item * C<date>
88              
89             Date of comment which is L<DateTime> instance.
90              
91             It's required.
92              
93             =item * C<id>
94              
95             Id.
96              
97             Default value is undef.
98              
99             =item * C<message>
100              
101             Main comment message. Max length of message is 4096 character.
102              
103             It's required.
104              
105             =back
106              
107             Returns instance of object.
108              
109             =head2 C<author>
110              
111             my $author = $obj->author;
112              
113             Get author instance.
114              
115             Returns L<Data::Person> instance.
116              
117             =head2 C<date>
118              
119             my $date = $obj->date;
120              
121             Get datetime of comment.
122              
123             Returns L<DateTime> instance.
124              
125             =head2 C<id>
126              
127             my $id = $obj->id;
128              
129             Get comment id.
130              
131             Returns natural number.
132              
133             =head2 C<>
134              
135             my $message = $obj->message;
136              
137             Get comment message.
138              
139             Returns string.
140              
141             =head1 ERRORS
142              
143             new():
144             From Mo::utils::check_isa():
145             Parameter 'author' must be a 'Data::Person' object.
146             Value: %s
147             Reference: %s
148             Parameter 'date' must be a 'DateTime' object.
149             Value: %s
150             Reference: %s
151              
152             From Mo::utils::check_length():
153             Parameter 'message' has length greater than '4096'.
154             Value: %s
155              
156             From Mo::utils::check_required():
157             Parameter 'author' is required.
158             Parameter 'date' is required.
159             Parameter 'message' is required.
160              
161             From Mo::utils::Number::check_positive_natural():
162             Parameter 'id' must be a positive natural number.
163             Value: %s
164              
165             =head1 EXAMPLE
166              
167             =for comment filename=comment.pl
168              
169             use strict;
170             use warnings;
171              
172             use Data::Message::Board::Comment;
173             use Data::Person;
174             use DateTime;
175             use Unicode::UTF8 qw(decode_utf8 encode_utf8);
176              
177             my $obj = Data::Message::Board::Comment->new(
178             'author' => Data::Person->new(
179             'email' => 'skim@cpan.org',
180             'name' => decode_utf8('Michal Josef Špaček'),
181             ),
182             'date' => DateTime->now,
183             'id' => 7,
184             'message' => 'I am fine.',
185             );
186              
187             # Print out.
188             print 'Author name: '.encode_utf8($obj->author->name)."\n";
189             print 'Author email: '.$obj->author->email."\n";
190             print 'Date: '.$obj->date."\n";
191             print 'Id: '.$obj->id."\n";
192             print 'Comment message: '.$obj->message."\n";
193              
194             # Output:
195             # Author name: Michal Josef Špaček
196             # Author email: skim@cpan.org
197             # Date: 2024-05-27T09:54:28
198             # Id: 7
199             # Comment message: I am fine.
200              
201             =head1 DEPENDENCIES
202              
203             L<Mo>,
204             L<Mo::utils>,
205             L<Mo::utils::Number>.
206              
207             =head1 REPOSITORY
208              
209             L<https://github.com/michal-josef-spacek/Data-Message-Board>
210              
211             =head1 AUTHOR
212              
213             Michal Josef Špaček L<mailto:skim@cpan.org>
214              
215             L<http://skim.cz>
216              
217             =head1 LICENSE AND COPYRIGHT
218              
219             © 2024-2025 Michal Josef Špaček
220              
221             BSD 2-Clause License
222              
223             =head1 VERSION
224              
225             0.06
226              
227             =cut