File Coverage

blib/lib/Data/HashType.pm
Criterion Covered Total %
statement 20 20 100.0
branch 2 2 100.0
condition n/a
subroutine 5 5 100.0
pod 0 1 0.0
total 27 28 96.4


line stmt bran cond sub pod time code
1             package Data::HashType;
2              
3 6     6   81244 use strict;
  6         47  
  6         186  
4 6     6   35 use warnings;
  6         22  
  6         172  
5              
6 6     6   2959 use Mo qw(build is);
  6         3367  
  6         35  
7 6     6   12409 use Mo::utils qw(check_bool check_length check_number check_required);
  6         96549  
  6         117  
8              
9             our $VERSION = 0.02;
10              
11             has active => (
12             is => 'ro',
13             );
14              
15             has id => (
16             is => 'ro',
17             );
18              
19             has name => (
20             is => 'ro',
21             );
22              
23             sub BUILD {
24 11     11 0 9611 my $self = shift;
25              
26             # Check active.
27 11 100       60 if (! defined $self->{'active'}) {
28 6         16 $self->{'active'} = 1;
29             }
30 11         49 check_bool($self, 'active');
31              
32             # Check id.
33 10         228 check_number($self, 'id');
34              
35             # Check hash name.
36 9         112 check_required($self, 'name');
37 8         79 check_length($self, 'name', 50);
38              
39 7         98 return;
40             }
41              
42             1;
43              
44             __END__
45              
46             =pod
47              
48             =encoding utf8
49              
50             =head1 NAME
51              
52             Data::HashType - Data object for hash type.
53              
54             =head1 SYNOPSIS
55              
56             use Data::HashType;
57              
58             my $obj = Data::HashType->new(%params);
59             my $active = $obj->active;
60             my $id = $obj->id;
61             my $name = $obj->name;
62              
63             =head1 METHODS
64              
65             =head2 C<new>
66              
67             my $obj = Data::HashType->new(%params);
68              
69             Constructor.
70              
71             =over 8
72              
73             =item * C<active>
74              
75             Flag for activity of hash type.
76             Possible valuea are 0/1.
77             Default value is 1 (active).
78              
79             =item * C<id>
80              
81             Id of record.
82             Id could be number.
83             It's optional.
84             Default value is undef.
85              
86             =item * C<name>
87              
88             Hash type name.
89             Maximal length of value is 50 characters.
90             It's required.
91              
92             =back
93              
94             Returns instance of object.
95              
96             =head2 C<active>
97              
98             my $active = $obj->active;
99              
100             Get active flag.
101              
102             Returns 0/1.
103              
104             =head2 C<id>
105              
106             my $id = $obj->id;
107              
108             Get hash type record id.
109              
110             Returns number.
111              
112             =head2 C<name>
113              
114             my $name = $obj->name;
115              
116             Get hash type name.
117              
118             Returns string.
119              
120             =head1 ERRORS
121              
122             new():
123             Parameter 'active' must be a bool (0/1).
124             Value: %s
125             Parameter 'id' must be a number.
126             Value: %s
127             Parameter 'name' has length greater than '50'.
128             Value: %s
129             Parameter 'name' is required.
130              
131             =head1 EXAMPLE
132              
133             =for comment filename=create_and_print_hash_type.pl
134              
135             use strict;
136             use warnings;
137              
138             use Data::HashType;
139              
140             my $obj = Data::HashType->new(
141             'active' => 1,
142             'id' => 10,
143             'name' => 'SHA-256',
144             );
145              
146             # Print out.
147             print 'Name: '.$obj->name."\n";
148             print 'Active: '.$obj->active."\n";
149             print 'Id: '.$obj->id."\n";
150              
151             # Output:
152             # Name: SHA-256
153             # Active: 1
154             # Id: 10
155              
156             =head1 DEPENDENCIES
157              
158             L<Mo>,
159             L<Mo::utils>.
160              
161             =head1 REPOSITORY
162              
163             L<https://github.com/michal-josef-spacek/Data-HashType>
164              
165             =head1 AUTHOR
166              
167             Michal Josef Špaček L<mailto:skim@cpan.org>
168              
169             L<http://skim.cz>
170              
171             =head1 LICENSE AND COPYRIGHT
172              
173             © 2023 Michal Josef Špaček
174              
175             BSD 2-Clause License
176              
177             =head1 VERSION
178              
179             0.02
180              
181             =cut