blib/lib/Mo/utils/Time.pm

filter: Statementstmt 83.3% 10 / 12 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 87.5% 14 / 16 CC 1 SCAR 0.7
CC
1
Cov
83%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
↑ Summary
1 package Mo::utils::Time;
2  
3 2 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 0 ▶use Error::Pure qw(err);
Subroutine BEGIN: called CC=1 SCAR=2.6
8 use Readonly;
9  
10 Readonly::Array our @EXPORT_OK => qw(check_time_24hhmm check_time_24hhmmss);
11  
12 our $VERSION = 0.01;
13  
14 sub check_time_24hhmm {
15 my ($self, $key) = @_;
16  
17 _check_key($self, $key) && return;
18  
19 if ($self->{$key} !~ m/^(\d{2})\:(\d{2})$/ms) {
20 err "Parameter '".$key."' doesn't contain valid time in HH:MM format.",
21 'Value', $self->{$key},
22 ;
23 }
24 my ($hour, $min) = ($1, $2);
25 if ($hour > 23) {
26 err "Parameter '".$key."' doesn't contain valid hour in HH:MM time format.",
27 'Value', $self->{$key},
28 ;
29 }
30 if ($min > 59) {
31 err "Parameter '".$key."' doesn't contain valid minute in HH:MM time format.",
32 'Value', $self->{$key},
33 ;
34 }
35  
36 return;
37 }
38  
39 sub check_time_24hhmmss {
40 my ($self, $key) = @_;
41  
42 _check_key($self, $key) && return;
43  
44 if ($self->{$key} !~ m/^(\d{2})\:(\d{2})\:(\d{2})$/ms) {
45 err "Parameter '".$key."' doesn't contain valid time in HH:MM:SS format.",
46 'Value', $self->{$key},
47 ;
48 }
49 my ($hour, $min, $sec) = ($1, $2, $3);
50 if ($hour > 23) {
51 err "Parameter '".$key."' doesn't contain valid hour in HH:MM:SS time format.",
52 'Value', $self->{$key},
53 ;
54 }
55 if ($min > 59) {
56 err "Parameter '".$key."' doesn't contain valid minute in HH:MM:SS time format.",
57 'Value', $self->{$key},
58 ;
59 }
60 if ($sec > 59) {
61 err "Parameter '".$key."' doesn't contain valid second in HH:MM:SS time format.",
62 'Value', $self->{$key},
63 ;
64 }
65  
66 return;
67 }
68  
69 sub _check_key {
70 my ($self, $key) = @_;
71  
72 if (! exists $self->{$key} || ! defined $self->{$key}) {
73 return 1;
74 }
75  
76 return 0;
77 }
78  
79 1;
80  
81 __END__
↑ Summary