blib/lib/Date/strftimeq.pm

filter: Statementstmt 100% 57 / 57 Branchbran 66.6% 4 / 6 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 13 / 13 Podpod 100% 1 / 1 totaltotal 95.0% 76 / 80 CC 5 SCAR 7.8
CC
5
Cov
95%
strftimeq
5.0
BEGIN
1.0
BEGIN
1.0
CRAP 2.2
↑ Summary
1 ## no critic: Modules::ProhibitAutomaticExportation
2  
3 package Date::strftimeq;
4  
5 2 our $DATE = '2020-02-01'; # DATE
6 2 our $DIST = 'Date-strftimeq'; # DIST
7 2 our $VERSION = '0.003'; # VERSION
8  
9 2 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 2 ▶use POSIX ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use Scalar::Util 'blessed';
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 2 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
17 2 our @EXPORT = qw(strftimeq);
18  
19 2 our $regex = qr{
20 (?(DEFINE)
21 (?<def_code> ( [^()]+ | \((?&def_code)\) )*)
22 )
23 (?<all>
24  
25 (?<convspec>
26 %
27 (?<flags> [_0^#-]+)?
28 (?<width> [0-9]+)?
29 (?<alt>[EO])?
30 (?<convletter> [%aAbBcCdDeEFgGhHIjklmMnOpPrRsStTuUVwWxXyYZz+])
31 )|
32 (?<qconvspec>
33 %\(
34 (?<code> (?&def_code))
35 \)q)
36 )
37 }x;
38  
39 # faster version, without using named capture
40 2 if (0) {
41 }
42  
43 5 ▶sub strftimeq {
Subroutine strftimeq: called CC=5 SCAR=16.1
Pod documented
44 5 my ($format, @time) = @_;
45  
46 5 my ($caller_pkg) = caller();
47 5 my %compiled_code;
48  
49 5 $format =~ s{$regex}{
50 # for faster acccess
51 16 my %m = %+;
52  
53 #use DD; dd \%m; # DEBUG
54  
55 16 ▶ if (exists $m{code}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $m{'code'}) { } 3 13 16
56 3 ▶ unless (defined $compiled_code{$m{code}}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $compiled_code{$m{"code"}}) 3 0 3
57 #say "D: compiling $m{code}"; # DEBUG
58 3 ▶ $compiled_code{$m{code}} = eval "package $caller_pkg; no strict; no warnings; sub { $m{code} }";
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
59 3 ▶ die "Can't compile code in $m{all}: $@" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 3 3
60 }
61 3 my $code_res = $compiled_code{$m{code}}->(@time);
62 3 ▶ $code_res //= "";
Condition50%1/2
$code_res //= ""
l!l
30
MC/DC0%0/1
$code_res //= ""
$code_res
Truth table50%1/2
A
A= $code_res
Aresult
11
00
63 3 $code_res =~ s/%/%%/g;
64 3 $code_res;
65 } else {
66 13 $m{all};
67 }
68 }xego;
69  
70 5 POSIX::strftime($format, @time);
71 }
72  
73 2 1;
74 # ABSTRACT: POSIX::strftime() with support for embedded perl code in %(...)q
75  
76 __END__
↑ Summary