File Coverage

blib/lib/Data/CEFACT/Unit.pm
Criterion Covered Total %
statement 24 24 100.0
branch n/a
condition n/a
subroutine 7 7 100.0
pod 0 1 0.0
total 31 32 96.8


line stmt bran cond sub pod time code
1             package Data::CEFACT::Unit;
2              
3 10     10   201522 use strict;
  10         21  
  10         391  
4 10     10   65 use warnings;
  10         76  
  10         614  
5              
6 10     10   9265 use Mo qw(build is);
  10         7626  
  10         57  
7 10     10   25490 use Mo::utils 0.15 qw(check_required check_strings);
  10         186533  
  10         276  
8 10     10   1939 use Readonly;
  10         64  
  10         592  
9 10     10   5859 use Unicode::UTF8 qw(decode_utf8);
  10         7083  
  10         3359  
10              
11             Readonly::Array our @STATUSES => ('D', 'X', decode_utf8('¦'));
12              
13             our $VERSION = 0.01;
14              
15             has common_code => (
16             is => 'ro',
17             );
18              
19             has conversion_factor => (
20             is => 'ro',
21             );
22              
23             has description => (
24             is => 'ro',
25             );
26              
27             has level_category => (
28             is => 'ro',
29             );
30              
31             has name => (
32             is => 'ro',
33             );
34              
35             has status => (
36             is => 'ro',
37             );
38              
39             has symbol => (
40             is => 'ro',
41             );
42              
43             sub BUILD {
44 9     9 0 2731864 my $self = shift;
45              
46             # Check 'common_code'.
47 9         59 check_required($self, 'common_code');
48              
49             # Check 'level_category'.
50 8         142 check_required($self, 'level_category');
51              
52             # Check 'name'.
53 8         62 check_required($self, 'name');
54              
55             # Check 'status'.
56             ## Undefined status means valid item.
57 8         87 check_strings($self, 'status', \@STATUSES);
58              
59 8         131 return;
60             }
61              
62             1;
63              
64             =pod
65              
66             =encoding utf8
67              
68             =head1 NAME
69              
70             Data::CEFACT::Unit - Data object for CEFACT unit.
71              
72             =head1 SYNOPSIS
73              
74             use Data::CEFACT::Unit;
75              
76             my $obj = Data::CEFACT::Unit->new(%params);
77             my $common_code = $obj->common_code;
78             my $conversion_factor = $obj->conversion_factor;
79             my $description = $obj->description;
80             my $level_category = $obj->level_category;
81             my $name = $obj->name;
82             my $status = $obj->status;
83             my $symbol = $obj->symbol;
84              
85             =head1 METHODS
86              
87             =head2 C<new>
88              
89             my $obj = Data::CEFACT::Unit->new(%params);
90              
91             Constructor.
92              
93             =over 8
94              
95             =item * C<common_code>
96              
97             Common code of unit.
98              
99             It's required.
100              
101             Default value is undef.
102              
103             =item * C<conversion_factor>
104              
105             Conversion factor of unit.
106              
107             It's optional.
108              
109             Default value is undef.
110              
111             =item * C<description>
112              
113             Unit description.
114              
115             It's optional.
116              
117             Default value is undef.
118              
119             =item * C<level_category>
120              
121             Unit level/category.
122              
123             It's required.
124              
125             Default value is undef.
126              
127             =item * C<name>
128              
129             Unit name.
130              
131             It's required.
132              
133             Default value is undef.
134              
135             =item * C<status>
136              
137             Unit status,
138              
139             Possible statuses are undef as valid, 'D' as deprecated, 'X' as invalid and '¦'
140             as new.
141              
142             It's optional, default value is valid status.
143              
144             Default value is undef.
145              
146             =item * C<symbol>
147              
148             Unit symbol.
149              
150             It's optional.
151              
152             Default value is undef.
153              
154             =back
155              
156             Returns instance of object.
157              
158             =head2 C<common_code>
159              
160             my $common_code = $obj->common_code;
161              
162             Get unit common code.
163              
164             Returns string.
165              
166             =head2 C<conversion_factor>
167              
168             my $conversion_factor = $obj->conversion_factor;
169              
170             Get unit conversion factor.
171              
172             Returns string.
173              
174             =head2 C<description>
175              
176             my $description = $obj->description;
177              
178             Get unit description.
179              
180             Returns string.
181              
182             =head2 C<level_category>
183              
184             my $level_category = $obj->level_category;
185              
186             Get unit level/category.
187              
188             Returns string.
189              
190             =head2 C<name>
191              
192             my $name = $obj->name;
193              
194             Get unit name.
195              
196             Returns string.
197              
198             =head2 C<status>
199              
200             my $status = $obj->status;
201              
202             Get unit status.
203              
204             Returns string or undef.
205              
206             =head2 C<symbol>
207              
208             my $symbol = $obj->symbol;
209              
210             Get unit symbol.
211              
212             Returns string.
213              
214             =head1 EXAMPLE
215              
216             =for comment filename=create_and_print_unit_kilogram.pl
217              
218             use strict;
219             use warnings;
220              
221             use Data::CEFACT::Unit;
222              
223             my $obj = Data::CEFACT::Unit->new(
224             'common_code' => 'KGM',
225             'conversion_factor' => 'kg',
226             'description' => 'A unit of mass equal to one thousand grams.',
227             'level_category' => 1,
228             'name' => 'kilogram',
229             'symbol' => 'kg',
230             );
231              
232             # Print out.
233             print 'Name: '.$obj->name."\n";
234             print 'Description: '.$obj->description."\n";
235             print 'Common code: '.$obj->common_code."\n";
236             print 'Status: '.(! defined $obj->status ? 'valid' : $obj->status)."\n";
237             print 'Symbol: '.$obj->symbol."\n";
238             print 'Level/Category: '.$obj->level_category."\n";
239             print 'Conversion factor: '.$obj->conversion_factor."\n";
240              
241             # Output:
242             # Name: kilogram
243             # Description: A unit of mass equal to one thousand grams.
244             # Common code: KGM
245             # Status: valid
246             # Symbol: kg
247             # Level/Category: 1
248             # Conversion factor: kg
249              
250             =head1 DEPENDENCIES
251              
252             L<Mo>,
253             L<Mo::utils>.
254             L<Readonly>,
255             L<Unicode::UTF8>.
256              
257             =head1 REPOSITORY
258              
259             L<https://github.com/michal-josef-spacek/Data-CEFACT-Unit>
260              
261             =head1 AUTHOR
262              
263             Michal Josef Špaček L<mailto:skim@cpan.org>
264              
265             L<http://skim.cz>
266              
267             =head1 LICENSE AND COPYRIGHT
268              
269             © 2025 Michal Josef Špaček
270              
271             BSD 2-Clause License
272              
273             =head1 VERSION
274              
275             0.01
276              
277             =cut