Daemon/Snippet/Time.pm untested

filter: Statementstmt 0.0% 0 / 26 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 40 CC 4 SCAR 23.0
CC
4
Cov
0%
better_localtime
20.0
new
2.0
BEGIN
2.0
CRAP 10.0
1 package Author::Daemon::Snippet::Time;
2  
3 use v5.28;
4 use warnings;
5 use strict;
6 use experimental 'signatures';
7  
8 sub new ($class) {
9 my $self = {
10 'month_as_short' => [
11 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
12 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'
13 ],
14 'day_as_short' => [ 'Sun', 'Mon', 'Tue', 'Wed', 'Thr', 'Fri', 'Sat' ]
15 };
16  
17 bless $self, $class;
18 return $self;
19 }
20  
21 sub better_localtime ( $self, $template = undef ) {
22 my ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) =
23 localtime(time);
24  
25 # Create a place to store our object
26 my $time_object = {
27 'second' => sprintf( "%02d", $sec ),
28 'minute' => sprintf( "%02d", $min ),
29 'hour' => sprintf( "%02d", $hour ),
30 'month_day' => sprintf( "%02d", $mday + 1 ),
31 'month_short' => $self->{'month_as_short'}->[$mon],
32 'month' => sprintf( "%02d", $mon + 1 ),
33 'year' => $year + 1900,
34 'weekday' => $wday ? $wday : 7,
35 'weekday_as_short' => $self->{'day_as_short'}->[$wday],
36 'year_day' => sprintf( "%03d", $yday + 1 )
37 };
38  
39 # Do we have a template?
40 if ($template) {
41 my $check_forward = sub ( $name = '' ) {
42 defined $time_object->{$name}
43 ? $time_object->{$name}
44 : '__' . $name . '__';
45 };
46 $template =~ s#__([a-z_]+)__#$check_forward->($1)#ge;
47 }
48  
49 return $template;
50 }
51  
52  
53 1;