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