blib/lib/Dancer/Plugin/Formatter.pm

filter: Statementstmt 70.3% 38 / 54 Branchbran 50.0% 6 / 12 Conditioncond 30.0% 3 / 10 MC/DCmcdc 16.6% 1 / 6 Subroutinesub 57.1% 8 / 14 Podpod n/a totaltotal 58.3% 56 / 96 CC 11 SCAR 21.4
CC
11
Cov
62%
__ANON__
30.0
__ANON__
5.5
__ANON__
5.0
CRAP 8.5
↑ Summary
1 package Dancer::Plugin::Formatter;
2  
3 4 our @ISA = qw();
4 4 our $VERSION = '0.05';
5  
6 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 4 ▶use Dancer ':syntax';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use Dancer::Plugin;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 4 ▶use Date::Parse;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 4 ▶use POSIX;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 # see man 3 strftime
16 4 our $default_date_format = '%x'; # The preferred date representation for the current locale without the time.
17 4 our $default_time_format = '%c'; # The preferred date and time representation for the current locale.
18  
19 3 ▶register 'format_date' => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
20 3 ▶ my $format = shift // $default_date_format;
Condition33%1/3
shift() // $Dancer::Plugin::Formatter::default_date_format
l!l&&r!l&&!r
030
MC/DC0%0/2
shift() // $Dancer::Plugin::Formatter::default_date_format
shift() $Dancer::Plugin::Formatter::default_date_format
Truth table33%1/3
A // B
A= shift()B= $Dancer::Plugin::Formatter::default_date_format
ABresult
1X1
011
000
21 4 ▶ return sub {
Subroutine __ANON__: called CC=5 SCAR=16.1
22 4 my $date = shift;
23 4 ▶ return undef unless defined $date;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $date 1 3 4
24 3 ▶ return '' if $date eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $date eq "" 1 2 3
25  
26 2 ▶ my @parts = map { $_ //= 0 } strptime $date;
Condition100%2/2
$_ //= 0
l!l
79
MC/DC100%1/1
$_ //= 0
$_
Truth table100%2/2
A
A= $_
Aresult
11
00
27 # undefined parts set to 0 to prevent error
28 # Use of uninitialized value in subroutine entry
29  
30 2 ▶ @parts = localtime $date
Branch: 1 branch
BranchTrueFalseTotal
if $date =~ /^\d+$/ 1 1 2
31 if $date =~ /^\d+$/; # unixtime - seconds since epoch
32  
33 2 return POSIX::strftime $format, @parts;
34 }
35 3 };
36  
37 0 ▶register 'format_time' => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.0
38 0 ▶ my $format = shift // $default_time_format;
Condition0%0/3
shift() // $Dancer::Plugin::Formatter::default_time_format
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() // $Dancer::Plugin::Formatter::default_time_format
shift() $Dancer::Plugin::Formatter::default_time_format
Truth table0%0/3
A // B
A= shift()B= $Dancer::Plugin::Formatter::default_time_format
ABresult
1X1
011
000
39 0 ▶ return sub {
Subroutine __ANON__: not called CC=5 SCAR=34.0
40 0 my $time = shift;
41 0 ▶ return undef unless defined $time;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $time 0 0 0
42 0 ▶ return '' if $time eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $time eq "" 0 0 0
43  
44 0 ▶ my @parts = map { $_ //= 0 } strptime $time;
Condition0%0/2
$_ //= 0
l!l
00
MC/DC0%0/1
$_ //= 0
$_
Truth table0%0/2
A
A= $_
Aresult
11
00
45 # undefined parts set to 0 to prevent error
46 # Use of uninitialized value in subroutine entry
47  
48 0 ▶ @parts = localtime $time
Branch: 1 branch
BranchTrueFalseTotal
if $time =~ /^\d+$/ 0 0 0
49 if $time =~ /^\d+$/; # unixtime - seconds since epoch
50  
51 0 return POSIX::strftime $format, @parts;
52 }
53 0 };
54  
55 0 ▶register 'set_default_date_format' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
56 0 $default_date_format = shift;
57 0 return;
58 4 };
59  
60 0 ▶register 'set_default_time_format' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
61 0 $default_time_format = shift;
62 0 return;
63 4 };
64  
65  
66 0 ▶register 'format' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
67 0 my $format = shift;
68 0 ▶ return sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
69 0 return sprintf $format, @_;
70 0 };
71 4 };
72  
73 4 register_plugin;
74  
75 4 1;
76  
77 __END__
↑ Summary