File Coverage

blib/lib/Data/Text/Simple.pm
Criterion Covered Total %
statement 23 23 100.0
branch n/a
condition n/a
subroutine 7 7 100.0
pod 0 1 0.0
total 30 31 96.7


line stmt bran cond sub pod time code
1             package Data::Text::Simple;
2              
3 6     6   243972 use strict;
  6         13  
  6         231  
4 6     6   38 use warnings;
  6         38  
  6         362  
5              
6 6     6   3436 use Mo qw(build is);
  6         7912  
  6         50  
7 6     6   15668 use Mo::utils qw(check_required);
  6         116316  
  6         156  
8 6     6   4790 use Mo::utils::Language 0.05 qw(check_language_639_1);
  6         1876869  
  6         241  
9 6     6   4593 use Mo::utils::Number qw(check_positive_natural);
  6         16513  
  6         149  
10              
11             our $VERSION = 0.03;
12              
13             has id => (
14             is => 'ro',
15             );
16              
17             has lang => (
18             is => 'ro',
19             );
20              
21             has text => (
22             is => 'ro',
23             );
24              
25             sub BUILD {
26 13     13 0 1398317 my $self = shift;
27              
28             # Check id.
29 13         94 check_positive_natural($self, 'id');
30              
31             # Check lang.
32 9         225 check_language_639_1($self, 'lang');
33              
34             # Check text.
35 8         1500 check_required($self, 'text');
36              
37 7         85 return;
38             }
39              
40             1;
41              
42             __END__
43              
44             =pod
45              
46             =encoding utf8
47              
48             =head1 NAME
49              
50             Data::Text::Simple - Data object for text in language.
51              
52             =head1 SYNOPSIS
53              
54             use Data::Text::Simple;
55              
56             my $obj = Data::Text::Simple->new(%params);
57             my $id = $obj->id;
58             my $lang = $obj->lang;
59             my $text = $obj->text;
60              
61             =head1 METHODS
62              
63             =head2 C<new>
64              
65             my $obj = Data::Text::Simple->new(%params);
66              
67             Constructor.
68              
69             =over 8
70              
71             =item * C<id>
72              
73             Id of record.
74             Id could be positive natural number.
75              
76             It's optional.
77              
78             Default value is undef.
79              
80             =item * C<lang>
81              
82             Language ISO 639-1 code.
83              
84             It's optional.
85              
86             =item * C<text>
87              
88             Main text.
89              
90             It's required.
91              
92             =back
93              
94             Returns instance of object.
95              
96             =head2 C<id>
97              
98             my $id = $obj->id;
99              
100             Get id.
101              
102             Returns number.
103              
104             =head2 C<lang>
105              
106             my $lang = $obj->lang;
107              
108             Get language ISO 639-1 code.
109              
110             Returns string.
111              
112             =head2 C<text>
113              
114             my $text = $obj->text;
115              
116             Get text.
117              
118             Returns string.
119              
120             =head1 ERRORS
121              
122             new():
123             From Mo::utils:
124             Parameter 'text' is required.
125             From Mo::utils::Language:
126             Parameter 'lang' doesn't contain valid ISO 639-1 code.
127             Codeset: %s
128             Value: %s
129             From Mo::utils::Number:
130             Parameter 'id' must be a positive natural number.
131             Value: %s
132              
133             =head1 EXAMPLE
134              
135             =for comment filename=create_and_print_text.pl
136              
137             use strict;
138             use warnings;
139              
140             use Data::Text::Simple;
141              
142             my $obj = Data::Text::Simple->new(
143             'id' => 7,
144             'lang' => 'en',
145             'text' => 'This is a text.',
146             );
147              
148             # Print out.
149             print 'Id: '.$obj->id."\n";
150             print 'Language: '.$obj->lang."\n";
151             print 'Text: '.$obj->text."\n";
152              
153             # Output:
154             # Id: 7
155             # Language: en
156             # Text: This is a text.
157              
158             =head1 DEPENDENCIES
159              
160             L<Mo>,
161             L<Mo::utils>,
162             L<Mo::utils::Language>,
163             L<Mo::utils::Number>.
164              
165             =head1 REPOSITORY
166              
167             L<https://github.com/michal-josef-spacek/Data-Text-Simple>
168              
169             =head1 AUTHOR
170              
171             Michal Josef Špaček L<mailto:skim@cpan.org>
172              
173             L<http://skim.cz>
174              
175             =head1 LICENSE AND COPYRIGHT
176              
177             © 2023-2025 Michal Josef Špaček
178              
179             BSD 2-Clause License
180              
181             =head1 VERSION
182              
183             0.03
184              
185             =cut