blib/lib/Ixchel/functions/status.pm untested

filter: Statementstmt 0.0% 0 / 31 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 46 CC 5 SCAR 27.7
CC
5
Cov
0%
status
30.0
BEGIN
2.0
BEGIN
2.0
CRAP 16.0
1 package Ixchel::functions::status;
2  
3 use 5.006;
4 use strict;
5 use warnings;
6 use File::Slurp;
7 use Exporter 'import';
8 our @EXPORT = qw(status);
9  
10 =head1 NAME
11  
12 Ixchel::functions::status - Helper function for creating status lines.
13  
14 =head1 VERSION
15  
16 Version 0.0.1
17  
18 =cut
19  
20 our $VERSION = '0.0.1';
21  
22 =head1 SYNOPSIS
23  
24 use Ixchel::functions::status;
25  
26 $status=$status.status(type=>'Foo', error=>0, status=>'Some status...', no_print=>0);
27  
28 This creates a status text line in the format below...
29  
30 '[' . $timestamp . '] [' . $opts{type} . ', ' . $opts{error} . '] ' . $opts{status}."\n";
31  
32 $timestamp is created as below.
33  
34 my ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) = localtime(time);
35 my $timestamp = sprintf( "%04d-%02d-%02dT%02d:%02d:%02d", $year + 1900, $mon + 1, $mday, $hour, $min, $sec );
36  
37 =head1 Functions
38  
39 =head2 status
40  
41 Creates a new status line for use with functions.
42  
43 =head3 opts
44  
45 =head4 type
46  
47 The type to use. If not set it is set to 'undef'.
48  
49 =head4 status
50  
51 The new status. If undef '' is just returned.
52  
53 =head4 error
54  
55 If it is an error or not. Defaults to 0.
56  
57 =head4 no_print
58  
59 If it should print it or not.
60  
61 =cut
62  
63 sub status {
64 my (%opts) = @_;
65  
66 if ( !defined( $opts{status} ) ) {
67 return '';
68 }
69 chomp( $opts{status} );
70  
71 if ( !defined( $opts{error} ) ) {
72 $opts{error} = 0;
73 }
74  
75 if ( !defined( $opts{type} ) ) {
76 $opts{type} = 'undef';
77 }
78  
79 my ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) = localtime(time);
80 my $timestamp = sprintf( "%04d-%02d-%02dT%02d:%02d:%02d", $year + 1900, $mon + 1, $mday, $hour, $min, $sec );
81  
82 my $status = '[' . $timestamp . '] [' . $opts{type} . ', ' . $opts{error} . '] ' . $opts{status} . "\n";
83  
84 if ( !$opts{no_print} ) {
85 print $status;
86 }
87  
88 return $status;
89 } ## end sub status
90  
91 1;