File Coverage

blib/lib/Mo/utils/Binary.pm
Criterion Covered Total %
statement 27 27 100.0
branch 6 6 100.0
condition 3 3 100.0
subroutine 8 8 100.0
pod 1 1 100.0
total 45 45 100.0


line stmt bran cond sub pod time code
1             package Mo::utils::Binary;
2              
3 3     3   186772 use base qw(Exporter);
  3         6  
  3         836  
4 3     3   41 use strict;
  3         5  
  3         101  
5 3     3   15 use warnings;
  3         5  
  3         247  
6              
7 3     3   1696 use Error::Pure qw(err);
  3         30703  
  3         77  
8 3     3   228 use Readonly;
  3         6  
  3         384  
9              
10             Readonly::Array our @EXPORT_OK => qw(check_bytes_len);
11              
12             our $VERSION = 0.01;
13              
14             sub check_bytes_len {
15 6     6 1 430423 my ($self, $key, $length) = @_;
16              
17 6 100       24 _check_key($self, $key) && return;
18              
19 3     3   1566 use bytes;
  3         1772  
  3         19  
20 4 100       16 if (length($self->{$key}) > $length) {
21             err "Parameter '".$key."' has bad bytes length.",
22             'Value', $self->{$key},
23             'Expected bytes length', $length,
24 1         10 'Real bytes length', length($self->{$key}),
25             ;
26             }
27              
28 3         9 return;
29             }
30              
31             sub _check_key {
32 6     6   14 my ($self, $key) = @_;
33              
34 6 100 100     42 if (! exists $self->{$key} || ! defined $self->{$key}) {
35 2         12 return 1;
36             }
37              
38 4         13 return 0;
39             }
40              
41             1;
42              
43             __END__