Metadata.pm

filter: Statementstmt 77.7% 7 / 9 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 83.3% 10 / 12 CC 1 SCAR 0.9
CC
1
Cov
78%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
↑ Summary Metadata/KeyValue.pm »
1 package Data::Metadata;
2  
3 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 0 ▶use Mo qw(build is);
Subroutine BEGIN: called CC=1 SCAR=2.6
7 use Mo::utils::Array qw(check_array_object check_array_required);
8 use Mo::utils::Number 0.08 qw(check_positive_natural);
9  
10 our $VERSION = 0.01;
11  
12 has id => (
13 is => 'ro',
14 );
15  
16 has key_values => (
17 is => 'ro',
18 );
19  
20 sub BUILD {
21 my $self = shift;
22  
23 # Check 'id'.
24 check_positive_natural($self, 'id');
25  
26 # Check 'key_values'.
27 check_array_object($self, 'key_values', 'Data::Metadata::KeyValue');
28 check_array_required($self, 'key_values');
29  
30 return;
31 }
32  
33 =pod
34  
35 =encoding utf8
36  
37 =head1 NAME
38  
39 Data::Metadata - Data object for metadata.
40  
41 =head1 SYNOPSIS
42  
43 use Data::Metadata;
44  
45 my $obj = Data::Metadata->new(%params);
46 my $id = $obj->id;
47 my $key_values_ar = $obj->key_values;
48  
49 =head1 DESCRIPTION
50  
51 This class represents metadata as an optional identifier and a required list
52 of L<Data::Metadata::KeyValue> instances.
53  
54 =head1 METHODS
55  
56 =head2 C<new>
57  
58 my $obj = Data::Metadata->new(%params);
59  
60 Constructor.
61  
62 =over 8
63  
64 =item * C<id>
65  
66 Object id. The number is positive natural number.
67  
68 It's optional.
69  
70 =item * C<key_value>
71  
72 Reference to array with L<Data::Metadata::KeyValue> instances.
73  
74 It's required.
75  
76 =back
77  
78 Returns instance of object.
79  
80 =head2 C<id>
81  
82 my $id = $obj->id;
83  
84 Returns number or undef.
85  
86 =head2 C<key_values>
87  
88 my $key_values_ar = $obj->key_values;
89  
90 Returns reference to array with L<Data::Metadata::KeyValue> instances.
91  
92 =head1 ERRORS
93  
94 new():
95 From Mo::utils::Array::check_array_required():
96 Parameter 'key_values' is required.
97 Parameter 'key_values' with array must have at least one item.
98 From Mo::utils::Array::check_array_object():
99 Parameter 'key_values' must be a array.
100 Value: %s
101 Reference: %s
102 Parameter 'key_values' must contain 'Data::Metadata::KeyValue' objects.
103 Value: %s
104 Reference: %s
105 From Mo::utils::Number::check_positive_natural():
106 Parameter 'id' must be a positive decimal number.
107 Value: %s
108  
109 =head1 EXAMPLES
110  
111 =head2 EXAMPLE
112  
113 =for comment filename=data_metadata.pl
114  
115 use strict;
116 use warnings;
117  
118 use Data::Metadata;
119 use Data::Metadata::KeyValue;
120  
121 my $obj = Data::Metadata->new(
122 'id' => 7,
123 'key_values' => [
124 Data::Metadata::KeyValue->new(
125 'id' => 1,
126 'key' => 'text',
127 'value' => 'This is text',
128 ),
129 ],
130 );
131  
132 # Print out.
133 print 'Id: '.$obj->id."\n";
134 print 'Number of key/value items: '.scalar @{$obj->key_values}."\n";
135  
136 # Output:
137 # Id: 7
138 # Number of key/value items: 1
139  
140 =head1 DEPENDENCIES
141  
142 L<Mo>
143 L<Mo::utils::Array>,
144 L<Mo::utils::Number>.
145  
146 =head1 SEE ALSO
147  
148 =over
149  
150 =item L<Data::Metadata::KeyValue>
151  
152 Class for one metadata key/value pair.
153  
154 =back
155  
156 =head1 REPOSITORY
157  
158 L<https://github.com/michal-josef-spacek/Data-Metadata>
159  
160 =head1 AUTHOR
161  
162 Michal Josef Špaček L<mailto:skim@cpan.org>
163  
164 L<http://skim.cz>
165  
166 =head1 LICENSE AND COPYRIGHT
167  
168 © 2025-2026 Michal Josef Špaček
169  
170 BSD 2-Clause License
171  
172 =head1 VERSION
173  
174 0.01
175  
176 =cut
177  
178 1;
↑ Summary Metadata/KeyValue.pm »