File Coverage

blib/lib/Data/OFN/Common/Quantity.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::OFN::Common::Quantity;
2              
3 5     5   181613 use strict;
  5         10  
  5         183  
4 5     5   23 use warnings;
  5         16  
  5         315  
5              
6 5     5   2623 use Mo qw(build is);
  5         3299  
  5         26  
7 5     5   11651 use Mo::utils qw(check_required);
  5         85953  
  5         152  
8 5     5   3748 use Mo::utils::CEFACT 0.02 qw(check_cefact_unit);
  5         412783  
  5         141  
9 5     5   3350 use Mo::utils::Number 0.02 qw(check_number);
  5         14171  
  5         116  
10              
11             our $VERSION = 0.03;
12              
13             has unit => (
14             is => 'ro',
15             );
16              
17             has value => (
18             is => 'ro',
19             );
20              
21             sub BUILD {
22 6     6 0 1304506 my $self = shift;
23              
24             # Check 'unit'.
25 6         43 check_required($self, 'unit');
26 5         120 check_cefact_unit($self, 'unit');
27              
28             # Check 'value'.
29 4         1037172 check_required($self, 'value');
30 3         55 check_number($self, 'value');
31              
32 3         98 return;
33             }
34              
35             1;
36              
37             __END__
38              
39             =pod
40              
41             =encoding utf8
42              
43             =head1 NAME
44              
45             Data::OFN::Common::Quantity - OFN common data object for quantity.
46              
47             =head1 SYNOPSIS
48              
49             use Data::OFN::Common::Quantity;
50              
51             my $obj = Data::OFN::Common::Quantity->new(%params);
52             my $unit = $obj->unit;
53             my $value = $obj->value;
54              
55             =head1 DESCRIPTION
56              
57             Immutable data object for OFN (Otevřené formální normy) representation of
58             quantity in the Czech Republic.
59              
60             This object is actual with L<2020-07-01|https://ofn.gov.cz/z%C3%A1kladn%C3%AD-datov%C3%A9-typy/2020-07-01/#mno%C5%BEstv%C3%AD>
61             version of OFN basic data types standard.
62              
63             =head1 METHODS
64              
65             =head2 C<new>
66              
67             my $obj = Data::OFN::Common::Quantity->new(%params);
68              
69             Constructor.
70              
71             =over 8
72              
73             =item * C<unit>
74              
75             Quantity unit defined by UN/CEFACT unit common code.
76              
77             It's required.
78              
79             Default value is undef.
80              
81             =item * C<value>
82              
83             Quantity value in some number form.
84              
85             It's required.
86              
87             Default value is undef.
88              
89             =back
90              
91             Returns instance of object.
92              
93             =head2 C<unit>
94              
95             my $unit = $obj->unit;
96              
97             Get UN/CEFACT unit common code.
98              
99             Returns string.
100              
101             =head2 C<value>
102              
103             my $value = $obj->value;
104              
105             Get value.
106              
107             Returns number.
108              
109             =head1 ERRORS
110              
111             new():
112             From Mo::utils::check_required():
113             Parameter 'unit' is required.
114             Parameter 'value' is required.
115             From Mo::utils::CEFACT::check_cefact_unit():
116             Parameter 'unit' must be a UN/CEFACT unit common code.
117             Value: %s
118             From Mo::utils::Number::check_number():
119             Parameter 'value' must be a number.
120             Value: %s
121              
122             =head1 EXAMPLE1
123              
124             =for comment filename=quantity_kilogram.pl
125              
126             use strict;
127             use warnings;
128              
129             use Data::OFN::Common::Quantity;
130              
131             my $obj = Data::OFN::Common::Quantity->new(
132             'value' => 1,
133             'unit' => 'KGM',
134             );
135              
136             # Print out.
137             print 'Value: '.$obj->value."\n";
138             print 'Unit: '.$obj->unit."\n";
139              
140             # Output:
141             # Value: 1
142             # Unit: KGM
143              
144             =head1 DEPENDENCIES
145              
146             L<Error::Pure>
147             L<Mo>,
148             L<Mo::utils>,
149             L<Mo::utils::CEFACT>,
150             L<Mo::utils::Number>.
151              
152             =head1 REPOSITORY
153              
154             L<https://github.com/michal-josef-spacek/Data-OFN-Common>
155              
156             =head1 AUTHOR
157              
158             Michal Josef Špaček L<mailto:skim@cpan.org>
159              
160             L<http://skim.cz>
161              
162             =head1 LICENSE AND COPYRIGHT
163              
164             © 2023-2025 Michal Josef Špaček
165              
166             BSD 2-Clause License
167              
168             =head1 VERSION
169              
170             0.03
171              
172             =cut