File Coverage

blib/lib/Data/ExternalId.pm
Criterion Covered Total %
statement 17 17 100.0
branch n/a
condition n/a
subroutine 5 5 100.0
pod 0 1 0.0
total 22 23 95.6


line stmt bran cond sub pod time code
1             package Data::ExternalId;
2              
3 6     6   153283 use strict;
  6         12  
  6         253  
4 6     6   58 use warnings;
  6         10  
  6         345  
5              
6 6     6   2827 use Mo qw(build is);
  6         3810  
  6         30  
7 6     6   13102 use Mo::utils 0.28 qw(check_number_id check_required);
  6         89685  
  6         149  
8              
9             our $VERSION = 0.01;
10              
11             has id => (
12             is => 'ro',
13             );
14              
15             has key => (
16             is => 'ro',
17             );
18              
19             has value => (
20             is => 'ro',
21             );
22              
23             sub BUILD {
24 9     9 0 1281807 my $self = shift;
25              
26             # Check id.
27 9         64 check_number_id($self, 'id');
28              
29             # Check key.
30 8         157 check_required($self, 'key');
31              
32             # Check value.
33 7         73 check_required($self, 'value');
34              
35 6         46 return;
36             }
37              
38             1;
39              
40             __END__
41              
42             =pod
43              
44             =encoding utf8
45              
46             =head1 NAME
47              
48             Data::ExternalId - Data object for external identifier.
49              
50             =head1 DESCRIPTION
51              
52             Data object for external identifier. It could be defined as identifier key and
53             value.
54              
55             =head1 SYNOPSIS
56              
57             use Data::ExternalId;
58              
59             my $obj = Data::ExternalId->new(%params);
60             my $id = $obj->id;
61             my $key = $obj->key;
62             my $value = $obj->value;
63              
64             =head1 METHODS
65              
66             =head2 C<new>
67              
68             my $obj = Data::ExternalId->new(%params);
69              
70             Constructor.
71              
72             =over 8
73              
74             =item * C<id>
75              
76             Unique identifier.
77              
78             It's optional.
79              
80             =item * C<key>
81              
82             External identifier key.
83              
84             It's required.
85              
86             =item * C<value>
87              
88             External identifier value.
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 unique identifier.
101              
102             Returns number.
103              
104             =head2 C<key>
105              
106             my $key = $obj->key;
107              
108             Get external identifier key.
109              
110             Returns string.
111              
112             =head2 C<value>
113              
114             my $value = $obj->value;
115              
116             Get external identifier value.
117              
118             Returns string.
119              
120             =head1 ERRORS
121              
122             new():
123             From Mo::utils::check_number_id():
124             Parameter 'id' must be a natural number.
125             Value: %s
126             From Mo::utils::check_required():
127             Parameter 'key' is required.
128             Parameter 'value' is required.
129              
130             =head1 EXAMPLE
131              
132             =for comment filename=create_external_id_and_print.pl
133              
134             use strict;
135             use warnings;
136              
137             use Data::ExternalId;
138              
139             my $obj = Data::ExternalId->new(
140             'key' => 'Wikidata',
141             'value' => 'Q27954834',
142             );
143              
144             # Print out.
145             print "External id key: ".$obj->key."\n";
146             print "External id value: ".$obj->value."\n";
147              
148             # Output:
149             # External id key: Wikidata
150             # External id value: Q27954834
151              
152             =head1 DEPENDENCIES
153              
154             L<Mo>,
155             L<Mo::utils>.
156              
157             =head1 REPOSITORY
158              
159             L<https://github.com/michal-josef-spacek/Data-ExternalId>
160              
161             =head1 AUTHOR
162              
163             Michal Josef Špaček L<mailto:skim@cpan.org>
164              
165             L<http://skim.cz>
166              
167             =head1 LICENSE AND COPYRIGHT
168              
169             © 2025 Michal Josef Špaček
170              
171             BSD 2-Clause License
172              
173             =head1 VERSION
174              
175             0.01
176              
177             =cut