blib/lib/POSIX/strftime/GNU/PP.pm

filter: Statementstmt 84.8% 168 / 198 Branchbran 63.7% 37 / 58 Conditioncond 66.6% 36 / 54 MC/DCmcdc 50.0% 15 / 30 Subroutinesub 77.0% 37 / 48 Podpod 100% 1 / 1 totaltotal 75.5% 294 / 389 SCAR 43.0
CC
48
Cov
78%
__ANON__
32.5
__ANON__
10.8
__ANON__
10.4
CRAP 73.4
« inc/Module/Build/My.pm ↑ Summary Build »
1 #!/usr/bin/perl -c
2  
3 package POSIX::strftime::GNU::PP;
4  
5 =head1 NAME
6  
7 POSIX::strftime::GNU::PP - Pure-Perl extension for POSIX::strftime::GNU
8  
9 =head1 SYNOPSIS
10  
11 $ export PERL_POSIX_STRFTIME_GNU_PP=1
12  
13 =head1 DESCRIPTION
14  
15 This is PP extension for POSIX::strftime which implements more character
16 sequences compatible with GNU systems.
17  
18 =cut
19  
20  
21 11 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 11 our $VERSION = '0.0304';
26  
27 11 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
28 11 ▶use POSIX ();
Subroutine BEGIN: called CC=1 SCAR=0.0
29 11 ▶use Time::Local ();
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 11 ▶use constant SEC => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 11 ▶use constant MIN => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 11 ▶use constant HOUR => 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 11 ▶use constant MDAY => 3;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 11 ▶use constant MON => 4;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 11 ▶use constant YEAR => 5;
Subroutine BEGIN: called CC=1 SCAR=0.0
37 11 ▶use constant WDAY => 6;
Subroutine BEGIN: called CC=1 SCAR=0.0
38 11 ▶use constant YDAY => 7;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 11 ▶use constant ISDST => 8;
Subroutine BEGIN: called CC=1 SCAR=0.0
40  
41 # $str = tzoffset (@time)
42 #
43 # Returns the C<+hhmm> or C<-hhmm> numeric timezone (the hour and minute offset
44 # from UTC).
45  
46 my $tzoffset = sub {
47 13 ▶ my ($colons, @t) = @_;
Subroutine __ANON__: called CC=9 SCAR=23.4
48  
49 # Normalize @t array, we need seconds without frac
50 13 $t[SEC] = int $t[SEC];
51  
52 13 ▶ my $diff = (exists $ENV{TZ} and $ENV{TZ} eq 'GMT')
Branch: 1 branch
BranchTrueFalseTotal
exists $ENV{'TZ'} && $ENV{'TZ'} eq 'GMT' ? : 1 12 13
Condition100%3/3
exists $ENV{"TZ"} and $ENV{"TZ"} eq "GMT"
!ll&&!rl&&r
2101
MC/DC100%2/2
exists $ENV{"TZ"} and $ENV{"TZ"} eq "GMT"
exists $ENV{"TZ"} $ENV{"TZ"} eq "GMT"
Truth table100%3/3
A and B
A= exists $ENV{"TZ"}B= $ENV{"TZ"} eq "GMT"
ABresult
0X0
100
111
53 ? 0
54 : Time::Local::timegm(@t) - Time::Local::timelocal(@t);
55  
56 13 my $h = $diff / 60 / 60;
57 13 my $m = $diff / 60 % 60;
58 13 my $s = $diff % 60;
59  
60 13 my $fmt = do {
61 13 ▶ if ($colons == 0) {
Branch: 4 branches
BranchTrueFalseTotal
if ($colons == 0) { } 5 8 13
elsif ($colons == 1) { } 0 8 8
elsif ($colons == 2) { } 0 8 8
elsif ($colons == 3) { } 8 0 8
62 5 '%+03d%02u';
63 }
64 elsif ($colons == 1) {
65 0 '%+03d:%02u';
66 }
67 elsif ($colons == 2) {
68 0 '%+03d:%02u:%02u';
69 }
70 elsif ($colons == 3) {
71 8 ▶ $s ? '%+03d:%02u:%02u' : $m ? '%+03d:%02u' : '%+03d';
Branch: 2 branches
BranchTrueFalseTotal
$s ? : 0 8 8
$m ? : 0 8 8
72 }
73 else {
74 0 '%%' . ':' x $colons . 'z';
75 };
76 };
77  
78 13 return sprintf $fmt, $h, $m, $s;
79 11 };
80  
81 11 my @offset2zone = qw(
82 -11 0 SST -11 0 SST
83 -10 0 HAST -09 1 HADT
84 -10 0 HST -10 0 HST
85 -09:30 0 MART -09:30 0 MART
86 -09 0 AKST -08 1 AKDT
87 -09 0 GAMT -09 0 GAMT
88 -08 0 PST -07 1 PDT
89 -08 0 PST -08 0 PST
90 -07 0 MST -06 1 MDT
91 -07 0 MST -07 0 MST
92 -06 0 CST -05 1 CDT
93 -06 0 GALT -06 0 GALT
94 -05 0 ECT -05 0 ECT
95 -05 0 EST -04 1 EDT
96 -05 1 EASST -06 0 EAST
97 -04:30 0 VET -04:30 0 VET
98 -04 0 AMT -04 0 AMT
99 -04 0 AST -03 1 ADT
100 -03:30 0 NST -02:30 1 NDT
101 -03 0 ART -03 0 ART
102 -03 0 PMST -02 1 PMDT
103 -03 1 AMST -04 0 AMT
104 -03 1 WARST -03 1 WARST
105 -02 0 FNT -02 0 FNT
106 -02 1 UYST -03 0 UYT
107 -01 0 AZOT +00 1 AZOST
108 -01 0 CVT -01 0 CVT
109 +00 0 GMT +00 0 GMT
110 +00 0 WET +01 1 WEST
111 +01 0 CET +02 1 CEST
112 +01 0 WAT +01 0 WAT
113 +02 0 EET +02 0 EET
114 +02 0 IST +03 1 IDT
115 +02 1 WAST +01 0 WAT
116 +03 0 FET +03 0 FET
117 +03:07:04 0 zzz +03:07:04 0 zzz
118 +03:30 0 IRST +04:30 1 IRDT
119 +04 0 AZT +05 1 AZST
120 +04 0 GST +04 0 GST
121 +04:30 0 AFT +04:30 0 AFT
122 +05 0 DAVT +07 0 DAVT
123 +05 0 MVT +05 0 MVT
124 +05:30 0 IST +05:30 0 IST
125 +05:45 0 NPT +05:45 0 NPT
126 +06 0 BDT +06 0 BDT
127 +06:30 0 CCT +06:30 0 CCT
128 +07 0 ICT +07 0 ICT
129 +08 0 HKT +08 0 HKT
130 +08:45 0 CWST +08:45 0 CWST
131 +09 0 JST +09 0 JST
132 +09:30 0 CST +09:30 0 CST
133 +10 0 PGT +10 0 PGT
134 +10:30 1 CST +09:30 0 CST
135 +11 0 CAST +08 0 WST
136 +11 0 NCT +11 0 NCT
137 +11 1 EST +10 0 EST
138 +11 1 LHST +10:30 0 LHST
139 +11:30 0 NFT +11:30 0 NFT
140 +12 0 FJT +12 0 FJT
141 +13 0 TKT +13 0 TKT
142 +13 1 NZDT +12 0 NZST
143 +13:45 1 CHADT +12:45 0 CHAST
144 +14 0 LINT +14 0 LINT
145 +14 1 WSDT +13 0 WST
146 );
147  
148 # $str = tzname (@time)
149 #
150 # Returns the abbreviation of the time zone (e.g. "UTC" or "CEST").
151  
152 my $tzname = sub {
153 5 ▶ my @t = @_;
Subroutine __ANON__: called CC=9 SCAR=23.8
154  
155 5 ▶ return 'GMT' if exists $ENV{TZ} and $ENV{TZ} eq 'GMT';
Branch: 1 branch
BranchTrueFalseTotal
if exists $ENV{"TZ"} and $ENV{"TZ"} eq "GMT" 2 3 5
Condition100%3/3
exists $ENV{"TZ"} and $ENV{"TZ"} eq "GMT"
!ll&&!rl&&r
122
MC/DC100%2/2
exists $ENV{"TZ"} and $ENV{"TZ"} eq "GMT"
exists $ENV{"TZ"} $ENV{"TZ"} eq "GMT"
Truth table100%3/3
A and B
A= exists $ENV{"TZ"}B= $ENV{"TZ"} eq "GMT"
ABresult
0X0
100
111
156  
157 3 my $diff = $tzoffset->(3, @t);
158  
159 2 my @t1 = my @t2 = @t;
160 2 @t1[MDAY,MON] = (1, 1); # winter
161 2 @t2[MDAY,MON] = (1, 7); # summer
162  
163 2 my $diff1 = $tzoffset->(3, @t1);
164 2 my $diff2 = $tzoffset->(3, @t2);
165  
166 2 ▶ for (my $i=0; $i < @offset2zone; $i += 6) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @offset2zone) 60 0 60
167 60 ▶ next unless $offset2zone[$i] eq $diff1 and $offset2zone[$i+3] eq $diff2;
Branch: 1 branch
BranchTrueFalseTotal
unless $offset2zone[$i] eq $diff1 and $offset2zone[$i + 3] eq $diff2 58 2 60
Condition66%2/3
$offset2zone[$i] eq $diff1 and $offset2zone[$i + 3] eq $diff2
!ll&&!rl&&r
5802
MC/DC50%1/2
$offset2zone[$i] eq $diff1 and $offset2zone[$i + 3] eq $diff2
$offset2zone[$i] eq $diff1 $offset2zone[$i + 3] eq $diff2
Truth table66%2/3
A and B
A= $offset2zone[$i] eq $diff1B= $offset2zone[$i + 3] eq $diff2
ABresult
0X0
100
111
168 2 ▶ return $diff2 eq $diff ? $offset2zone[$i+5] : $offset2zone[$i+2];
Branch: 1 branch
BranchTrueFalseTotal
$diff2 eq $diff ? : 1 1 2
169 }
170  
171 0 ▶ if ($diff =~ /^([+-])(\d\d)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($diff =~ /^([+-])(\d\d)$/) 0 0 0
172 0 ▶ return sprintf 'GMT%s%d', $1 eq '-' ? '+' : '-', $2;
Branch: 1 branch
BranchTrueFalseTotal
$1 eq '-' ? : 0 0 0
173 };
174  
175 0 return 'Etc';
176 11 };
177  
178 11 ▶use constant ISO_WEEK_START_WDAY => 1; # Monday
Subroutine BEGIN: called CC=1 SCAR=0.0
179 11 ▶use constant ISO_WEEK1_WDAY => 4; # Thursday
Subroutine BEGIN: called CC=1 SCAR=0.0
180 11 ▶use constant YDAY_MINIMUM => -366;
Subroutine BEGIN: called CC=1 SCAR=0.0
181 11 ▶use constant TM_YEAR_BASE => 1900;
Subroutine BEGIN: called CC=1 SCAR=0.0
182  
183 # ($days, $year_adjust) = isodaysnum (@time)
184 #
185 # Returns the number of the year's day based on ISO-8601 standard and year
186 # adjust value.
187  
188 my $isodaysnum = sub {
189 12 ▶ my @t = @_;
Subroutine __ANON__: called CC=4 SCAR=13.9
190  
191 my $isleap = sub {
192 12 ▶ my ($year) = @_;
Subroutine __ANON__: called CC=3 SCAR=12.5
193 12 ▶ return (($year) % 4 == 0 && (($year) % 100 != 0 || ($year) % 400 == 0));
Condition50%3/6
$year % 4 == 0 && ($year % 100 != 0 || $year % 400 == 0)
!ll&&!rl&&r
606
$year % 100 != 0 or $year % 400 == 0
l!l&&r!l&&!r
600
MC/DC33%1/3
$year % 4 == 0 && ($year % 100 != 0 || $year % 400 == 0)
$year % 4 == 0 $year % 100 != 0 $year % 400 == 0
Truth table50%2/4
A && B or C
A= $year % 4 == 0B= $year % 100 != 0C= $year % 400 == 0
ABCresult
0XX0
1000
11X1
1011
194 12 };
195  
196 my $iso_week_days = sub {
197 24 ▶ my ($yday, $wday) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
198  
199 # Add enough to the first operand of % to make it nonnegative.
200 24 my $big_enough_multiple_of_7 = (int(- YDAY_MINIMUM / 7) + 2) * 7;
201 24 return ($yday
202 - ($yday - $wday + ISO_WEEK1_WDAY + $big_enough_multiple_of_7) % 7
203 + ISO_WEEK1_WDAY - ISO_WEEK_START_WDAY);
204 12 };
205  
206 # Normalize @t array, we need WDAY
207 12 $t[SEC] = int $t[SEC];
208 12 @t = gmtime Time::Local::timegm(@t);
209  
210 # YEAR is a leap year if and only if (tp->tm_year + TM_YEAR_BASE)
211 # is a leap year, except that YEAR and YEAR - 1 both work
212 # correctly even when (tp->tm_year + TM_YEAR_BASE) would
213 # overflow.
214 12 ▶ my $year = ($t[YEAR] + ($t[YEAR] < 0 ? TM_YEAR_BASE % 400 : TM_YEAR_BASE % 400 - 400));
Branch: 1 branch
BranchTrueFalseTotal
$t[5] < 0 ? : 0 12 12
215 12 my $year_adjust = 0;
216 12 my $days = $iso_week_days->($t[YDAY], $t[WDAY]);
217  
218 12 ▶ if ($days < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($days < 0) { } 2 10 12
219 # This ISO week belongs to the previous year.
220 2 $year_adjust = -1;
221 2 $days = $iso_week_days->($t[YDAY] + (365 + $isleap->($year - 1)), $t[WDAY]);
222 }
223 else {
224 10 my $d = $iso_week_days->($t[YDAY] - (365 + $isleap->($year)), $t[WDAY]);
225 10 ▶ if ($d >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($d >= 0) 2 8 10
226 # This ISO week belongs to the next year. */
227 2 $year_adjust = 1;
228 2 $days = $d;
229 };
230 };
231  
232 12 return ($days, $year_adjust);
233 11 };
234  
235 # $num = isoyearnum (@time)
236 #
237 # Returns the number of the year based on ISO-8601 standard. See
238 # L<http://en.wikipedia.org/wiki/ISO_8601> for details.
239  
240 my $isoyearnum = sub {
241 6 ▶ my @t = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
242 6 my ($days, $year_adjust) = $isodaysnum->(@t);
243 6 return sprintf '%04d', $t[YEAR] + TM_YEAR_BASE + $year_adjust;
244 11 };
245  
246 # $num = isoweeknum (@time)
247 #
248 # Returns the number of the week based on ISO-8601 standard. See
249 # L<http://en.wikipedia.org/wiki/ISO_8601> for details.
250  
251 my $isoweeknum = sub {
252 6 ▶ my @t = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
253 6 my ($days, $year_adjust) = $isodaysnum->(@t);
254 6 return sprintf '%02d', int($days / 7) + 1;
255 11 };
256  
257  
258 =head1 FUNCTIONS
259  
260 =head2 strftime_orig
261  
262 $str = strftime_orig (@time)
263  
264 This is original L<POSIX::strftime|POSIX/strftime> function.
265  
266 =cut
267  
268 11 *strftime_orig = *POSIX::strftime;
269  
270 my %format = (
271 2 ▶ C => sub { 19 + int $_[YEAR] / 100 },
Subroutine __ANON__: called CC=1 SCAR=0.0
272 0 ▶ D => sub { '%m/%d/%y' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
273 0 ▶ e => sub { sprintf '%2d', $_[MDAY] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
274 0 ▶ F => sub { '%Y-%m-%d' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
275 G => $isoyearnum,
276 6 ▶ g => sub { sprintf '%02d', $isoyearnum->(@_) % 100 },
Subroutine __ANON__: called CC=1 SCAR=0.0
277 1 ▶ h => sub { '%b' },
Subroutine __ANON__: called CC=1 SCAR=0.0
278 0 ▶ k => sub { sprintf '%2d', $_[HOUR] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
279 0 ▶ l => sub { sprintf '%2d', $_[HOUR] % 12 + ($_[HOUR] % 12 == 0 ? 12 : 0) },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$_[2] % 12 == 0 ? : 0 0 0
280 0 ▶ n => sub { "\n" },
Subroutine __ANON__: not called CC=1 SCAR=6.9
281 0 ▶ N => sub { substr sprintf('%.9f', $_[SEC] - int $_[SEC]), 2 },
Subroutine __ANON__: not called CC=1 SCAR=6.9
282 1 ▶ P => sub { lc strftime_orig('%p', @_) },
Subroutine __ANON__: called CC=1 SCAR=0.0
283 1 ▶ r => sub { '%I:%M:%S %p' },
Subroutine __ANON__: called CC=1 SCAR=0.0
284 0 ▶ R => sub { '%H:%M' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
285 0 ▶ s => sub { int Time::Local::timegm(@_) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
286 0 ▶ t => sub { "\t" },
Subroutine __ANON__: not called CC=1 SCAR=6.9
287 1 ▶ T => sub { '%H:%M:%S' },
Subroutine __ANON__: called CC=1 SCAR=0.0
288 0 ▶ u => sub { my $dw = strftime_orig('%w', @_); $dw += ($dw == 0 ? 7 : 0); $dw },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$dw == 0 ? : 0 0 0
289 V => $isoweeknum,
290 z => $tzoffset,
291 Z => $tzname,
292 3 ▶ '%' => sub { '%%' },
Subroutine __ANON__: called CC=1 SCAR=0.0
293 11 );
294  
295 11 my $formats = join '', sort keys %format;
296  
297  
298 =head2 strftime
299  
300 $str = strftime($format, @time)
301  
302 This is replacement for L<POSIX::strftime|POSIX/strftime> function.
303  
304 The non-POSIX feature is that seconds can be float number.
305  
306 =cut
307  
308 sub strftime {
309 51 ▶ my ($fmt, @t) = @_;
Subroutine strftime: called CC=3 SCAR=11.5
Pod documented
310  
311 51 ▶ Carp::croak 'Usage: POSIX::strftime::GNU::PP::strftime(fmt, sec, min, hour, mday, mon, year, wday = -1, yday = -1, isdst = -1)'
Branch: 1 branch
BranchTrueFalseTotal
unless @t >= 6 and @t <= 9 0 51 51
Condition33%1/3
@t >= 6 and @t <= 9
!ll&&!rl&&r
0051
MC/DC0%0/2
@t >= 6 and @t <= 9
@t >= 6 @t <= 9
Truth table33%1/3
A and B
A= @t >= 6B= @t <= 9
ABresult
0X0
100
111
312 unless @t >= 6 and @t <= 9;
313  
314 my $strftime_modifier = sub {
315 17 ▶ my ($prefix, $modifier, $format, @t) = @_;
Subroutine __ANON__: called CC=22 SCAR=34.8
316 17 my $suffix = '';
317  
318 11 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
319 17 my $str = strftime("%$format", @t);
320  
321 16 for (;;) {
322 20 ▶ if ($modifier eq '_' and $suffix !~ /0/ or $modifier eq '-' and $suffix !~ /0/ and $format =~ /[aAbBDFhnpPrRtTxXZ%]$/) {
Branch: 8 branches
BranchTrueFalseTotal
if ($modifier eq '_' and not $suffix =~ /0/ or $modifier eq '-' and not $suffix =~ /0/ and $format =~ /[aAbBDFhnpPrRtTxXZ%]$/) { } 1 19 20
elsif ($modifier eq '-' and not $suffix =~ /0/ and $format =~ /[CdgGHIjmMNsSuUVwWyYz]$/) { } 0 19 19
elsif ($modifier eq '-') { } 0 19 19
elsif ($modifier eq '0' and not $suffix =~ /_/) { } 0 19 19
elsif ($modifier eq '^' and "$prefix$suffix" =~ /#/ and $format =~ /Z$/) { } 1 18 19
elsif ($modifier eq '^' and not $format =~ /[pP]$/) { } 2 16 18
elsif ($modifier eq '#' and $format =~ /[aAbBh]$/) { } 7 9 16
elsif ($modifier eq '#' and $format =~ /[pZ]$/) { } 4 6 10
Condition58%7/12
$modifier eq "_" and not $suffix =~ /0/ or $modifier eq "-" and not $suffix =~ /0/ and $format =~ /[aAbBDFhnpPrRtTxXZ%]$/
l!l&&r!l&&!r
0119
$modifier eq "_" and not $suffix =~ /0/
!ll&&!rl&&r
2000
$modifier eq "-" and not $suffix =~ /0/ and $format =~ /[aAbBDFhnpPrRtTxXZ%]$/
!ll&&!rl&&r
1901
$modifier eq "-" and not $suffix =~ /0/
!ll&&!rl&&r
1901
MC/DC20%1/5
$modifier eq "_" and not $suffix =~ /0/ or $modifier eq "-" and not $suffix =~ /0/ and $format =~ /[aAbBDFhnpPrRtTxXZ%]$/
$modifier eq "_" not $suffix =~ /0/ $modifier eq "-" not $suffix =~ /0/ $format =~ /[aAbBDFhnpPrRtTxXZ%]$/
Truth table22%2/9
A and not(B) or C and not(D) and E
A= $modifier eq "_"B= not $suffix =~ /0/C= $modifier eq "-"D= not $suffix =~ /0/E= $format =~ /[aAbBDFhnpPrRtTxXZ%]$/
ABCDEresult
11XXX1
0X1111
101111
0X0XX0
0X10X0
0X1100
100XX0
1010X0
101100
323 1 $str =~ s/^([+-])(0+)(\d:.*?|\d$)/' ' x length($2) . $1 . $3/ge;
324 1 $str =~ s/^(0+)(.+?)$/' ' x length($1) . $2/ge;
325 }
326 ▶ elsif ($modifier eq '-' and $suffix !~ /0/ and $format =~ /[CdgGHIjmMNsSuUVwWyYz]$/) {
Condition33%2/6
$modifier eq "-" and not $suffix =~ /0/ and $format =~ /[CdgGHIjmMNsSuUVwWyYz]$/
!ll&&!rl&&r
1900
$modifier eq "-" and not $suffix =~ /0/
!ll&&!rl&&r
1900
MC/DC0%0/3
$modifier eq "-" and not $suffix =~ /0/ and $format =~ /[CdgGHIjmMNsSuUVwWyYz]$/
$modifier eq "-" not $suffix =~ /0/ $format =~ /[CdgGHIjmMNsSuUVwWyYz]$/
Truth table25%1/4
A and not(B) and C
A= $modifier eq "-"B= not $suffix =~ /0/C= $format =~ /[CdgGHIjmMNsSuUVwWyYz]$/
ABCresult
0XX0
10X0
1100
1111
327 0 $str =~ s/^([+-])(0+)(\d:.*?|\d$)/$1$3/g;
328 0 $str =~ s/^(0+)(.+?)$/$2/g;
329 }
330 elsif ($modifier eq '-') {
331 0 $str =~ s/^ +//ge;
332 }
333 ▶ elsif ($modifier eq '0' and $suffix !~ /_/) {
Condition33%1/3
$modifier eq 0 and not $suffix =~ /_/
!ll&&!rl&&r
1900
MC/DC0%0/2
$modifier eq 0 and not $suffix =~ /_/
$modifier eq 0 not $suffix =~ /_/
Truth table33%1/3
A and not(B)
A= $modifier eq 0B= not $suffix =~ /_/
ABresult
0X0
100
111
334 0 $str =~ s/^( +)/'0' x length($1)/ge;
335 }
336 ▶ elsif ($modifier eq '^' and "$prefix$suffix" =~ /#/ and $format =~ /Z$/) {
Condition83%5/6
$modifier eq "^" and "$prefix$suffix" =~ /#/ and $format =~ /Z$/
!ll&&!rl&&r
1531
$modifier eq "^" and "$prefix$suffix" =~ /#/
!ll&&!rl&&r
1504
MC/DC66%2/3
$modifier eq "^" and "$prefix$suffix" =~ /#/ and $format =~ /Z$/
$modifier eq "^" "$prefix$suffix" =~ /#/ $format =~ /Z$/
Truth table75%3/4
A and B and C
A= $modifier eq "^"B= "$prefix$suffix" =~ /#/C= $format =~ /Z$/
ABCresult
0XX0
10X0
1100
1111
337 1 $str = lc($str);
338 }
339 ▶ elsif ($modifier eq '^' and $format !~ /[pP]$/) {
Condition100%3/3
$modifier eq "^" and not $format =~ /[pP]$/
!ll&&!rl&&r
1512
MC/DC100%2/2
$modifier eq "^" and not $format =~ /[pP]$/
$modifier eq "^" not $format =~ /[pP]$/
Truth table100%3/3
A and not(B)
A= $modifier eq "^"B= not $format =~ /[pP]$/
ABresult
0X0
100
111
340 2 $str = uc($str);
341 }
342 ▶ elsif ($modifier eq '#' and $format =~ /[aAbBh]$/) {
Condition100%3/3
$modifier eq "#" and $format =~ /[aAbBh]$/
!ll&&!rl&&r
187
MC/DC100%2/2
$modifier eq "#" and $format =~ /[aAbBh]$/
$modifier eq "#" $format =~ /[aAbBh]$/
Truth table100%3/3
A and B
A= $modifier eq "#"B= $format =~ /[aAbBh]$/
ABresult
0X0
100
111
343 7 $str = uc($str);
344 }
345 ▶ elsif ($modifier eq '#' and $format =~ /[pZ]$/) {
Condition100%3/3
$modifier eq "#" and $format =~ /[pZ]$/
!ll&&!rl&&r
144
MC/DC100%2/2
$modifier eq "#" and $format =~ /[pZ]$/
$modifier eq "#" $format =~ /[pZ]$/
Truth table100%3/3
A and B
A= $modifier eq "#"B= $format =~ /[pZ]$/
ABresult
0X0
100
111
346 4 $str = lc($str);
347 };
348  
349 20 ▶ last unless $prefix =~ s/(.)$//;
Branch: 1 branch
BranchTrueFalseTotal
unless $prefix =~ s/(.)$// 16 4 20
350 4 $suffix = "$modifier$suffix";
351 4 $modifier = $1;
352 };
353  
354 16 return $str;
355 51 };
356  
357 my $strftime_0z = sub {
358 1 ▶ my ($digits, $format, @t) = @_;
Subroutine __ANON__: called CC=2 SCAR=10.1
359 1 $digits --;
360 1 my $str = strftime($format, @t);
361 0 ▶ $str =~ /^([+-])(.*)$/ or return $format;
Branch: 1 branch
BranchTrueFalseTotal
$str =~ /^([+-])(.*)$/ or return $format 0 0 0
362 0 return $1 . sprintf "%0${digits}s", $2;
363 51 };
364  
365 # recursively handle modifiers
366 51 $fmt =~ s/%([_0\^#-]*)([_0\^#-])((?:[1-9][0-9]*)?:*[EO]?[a-zA-Z])/$strftime_modifier->($1, $2, $3, @t)/ge;
367 50 $fmt =~ s/%([_0\^#-]*)([_0\^#-])((?:[1-9][0-9]*)?[%])/$strftime_modifier->($1, $2, $3, @t) . '%'/ge;
368  
369 # numbers before character
370 50 $fmt =~ s/%([1-9][0-9]*)([EO]?[aAbBDeFhklnpPrRtTxXZ])/sprintf("%$1s", strftime("%$2", @t))/ge;
371 50 $fmt =~ s/%([1-9][0-9]*)([%])/sprintf("%$1s%%", '%')/ge;
372 50 $fmt =~ s/%([1-9][0-9]*)([EO]?[CdGgHIjmMsSuUVwWyY])/sprintf("%0$1s", strftime("%$2", @t))/ge;
373 50 $fmt =~ s/%([1-9][0-9]*)([N])/sprintf("%0$1.$1s", strftime("%$2", @t))/ge;
374 50 $fmt =~ s/%([1-9][0-9]*)(:*[z])/$strftime_0z->($1, "%$2", @t)/ge;
375  
376 # "E", "O", ":" modifiers
377 49 $fmt =~ s/%E([CcXxYy])/%$1/;
378 49 $fmt =~ s/%O([deHIMmSUuVWwy])/%$1/;
379 49 $fmt =~ s/%(:{0,3})?(z)/$format{$2}->(length $1, @t)/ge;
380  
381 # supported by Pure Perl
382 47 $fmt =~ s/%([$formats])/$format{$1}->(@t)/ge;
383  
384 # as-is if there is some modifiers left
385 46 $fmt =~ s/%([_0\^#-]+(?:[1-9][0-9]*)?|[_0\^#-]?(?:[1-9][0-9]*))([a-zA-Z%])/%%$1$2/;
386  
387 46 return strftime_orig($fmt, @t);
388 };
389  
390 11 1;
391  
392  
393 =head1 PERFORMANCE
394  
395 The PP module is about 10 times slower than XS module.
396  
397 =head1 SEE ALSO
398  
399 L<POSIX::strftime::GNU>.
400  
401 =head1 AUTHOR
402  
403 Piotr Roszatycki <dexter@cpan.org>
404  
405 =head1 LICENSE
406  
407 Copyright (c) 2012-2014 Piotr Roszatycki <dexter@cpan.org>.
408  
409 This is free software; you can redistribute it and/or modify it under
410 the same terms as perl itself.
411  
412 ISO 8601 functions:
413  
414 Copyright (c) 1991-2001, 2003-2007, 2009-2012 Free Software Foundation, Inc.
415  
416 This program is free software: you can redistribute it and/or modify
417 it under the terms of the GNU General Public License as published by
418 the Free Software Foundation; either version 3 of the License, or
419 (at your option) any later version.
420  
421 See L<http://dev.perl.org/licenses/artistic.html>
« inc/Module/Build/My.pm ↑ Summary Build »