CGI/Util.pm

filter: Statementstmt 42.0% 117 / 278 Branchbran 44.6% 50 / 112 Conditioncond 27.7% 20 / 72 MC/DCmcdc 16.6% 6 / 36 Subroutinesub 53.8% 14 / 26 Podpod 0.0% 0 / 22 totaltotal 37.9% 207 / 546 CC 87 SCAR 30.1
CC
87
Cov
40%
_rearrange_params
31.3
_rearrange_params
31.3
escape
27.0
CRAP 20.3
« CGI.pm ↑ Summary CGI/Push.pm »
1 package CGI::Util;
2 86 require 5.008001;
3 86 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 86 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 86 our @ISA = qw(Exporter);
6 86 our @EXPORT_OK = qw(rearrange rearrange_header make_attributes unescape escape
7 expires ebcdic2ascii ascii2ebcdic);
8  
9 86 our $VERSION = '5.02';
10  
11 86 our $_EBCDIC = "\t" ne "\011";
12  
13 86 my $appease_cpants_kwalitee = q/
14 use strict;
15 use warnings;
16 #/;
17  
18 # (ord('^') == 95) for codepage 1047 as on os390, vmesa
19 86 our @A2E = (
20 0, 1, 2, 3, 55, 45, 46, 47, 22, 5, 21, 11, 12, 13, 14, 15,
21 16, 17, 18, 19, 60, 61, 50, 38, 24, 25, 63, 39, 28, 29, 30, 31,
22 64, 90,127,123, 91,108, 80,125, 77, 93, 92, 78,107, 96, 75, 97,
23 240,241,242,243,244,245,246,247,248,249,122, 94, 76,126,110,111,
24 124,193,194,195,196,197,198,199,200,201,209,210,211,212,213,214,
25 215,216,217,226,227,228,229,230,231,232,233,173,224,189, 95,109,
26 121,129,130,131,132,133,134,135,136,137,145,146,147,148,149,150,
27 151,152,153,162,163,164,165,166,167,168,169,192, 79,208,161, 7,
28 32, 33, 34, 35, 36, 37, 6, 23, 40, 41, 42, 43, 44, 9, 10, 27,
29 48, 49, 26, 51, 52, 53, 54, 8, 56, 57, 58, 59, 4, 20, 62,255,
30 65,170, 74,177,159,178,106,181,187,180,154,138,176,202,175,188,
31 144,143,234,250,190,160,182,179,157,218,155,139,183,184,185,171,
32 100,101, 98,102, 99,103,158,104,116,113,114,115,120,117,118,119,
33 172,105,237,238,235,239,236,191,128,253,254,251,252,186,174, 89,
34 68, 69, 66, 70, 67, 71,156, 72, 84, 81, 82, 83, 88, 85, 86, 87,
35 140, 73,205,206,203,207,204,225,112,221,222,219,220,141,142,223
36 );
37 86 our @E2A = (
38 0, 1, 2, 3,156, 9,134,127,151,141,142, 11, 12, 13, 14, 15,
39 16, 17, 18, 19,157, 10, 8,135, 24, 25,146,143, 28, 29, 30, 31,
40 128,129,130,131,132,133, 23, 27,136,137,138,139,140, 5, 6, 7,
41 144,145, 22,147,148,149,150, 4,152,153,154,155, 20, 21,158, 26,
42 32,160,226,228,224,225,227,229,231,241,162, 46, 60, 40, 43,124,
43 38,233,234,235,232,237,238,239,236,223, 33, 36, 42, 41, 59, 94,
44 45, 47,194,196,192,193,195,197,199,209,166, 44, 37, 95, 62, 63,
45 248,201,202,203,200,205,206,207,204, 96, 58, 35, 64, 39, 61, 34,
46 216, 97, 98, 99,100,101,102,103,104,105,171,187,240,253,254,177,
47 176,106,107,108,109,110,111,112,113,114,170,186,230,184,198,164,
48 181,126,115,116,117,118,119,120,121,122,161,191,208, 91,222,174,
49 172,163,165,183,169,167,182,188,189,190,221,168,175, 93,180,215,
50 123, 65, 66, 67, 68, 69, 70, 71, 72, 73,173,244,246,242,243,245,
51 125, 74, 75, 76, 77, 78, 79, 80, 81, 82,185,251,252,249,250,255,
52 92,247, 83, 84, 85, 86, 87, 88, 89, 90,178,212,214,210,211,213,
53 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,179,219,220,217,218,159
54 );
55  
56 86 ▶if ($_EBCDIC && ord('^') == 106) { # as in the BS2000 posix-bc coded character set
Branch: 2 branches
BranchTrueFalseTotal
if ($CGI::Util::_EBCDIC and !1) { } 0 86 86
elsif ($CGI::Util::_EBCDIC and !1) { } 0 172 172
Condition50%1/2
$CGI::Util::_EBCDIC and
!ll
860
MC/DC0%0/1
$CGI::Util::_EBCDIC and
$CGI::Util::_EBCDIC
Truth table50%1/2
A
A= $CGI::Util::_EBCDIC
Aresult
00
11
57 0 $A2E[91] = 187; $A2E[92] = 188; $A2E[94] = 106; $A2E[96] = 74;
58 0 $A2E[123] = 251; $A2E[125] = 253; $A2E[126] = 255; $A2E[159] = 95;
59 0 $A2E[162] = 176; $A2E[166] = 208; $A2E[168] = 121; $A2E[172] = 186;
60 0 $A2E[175] = 161; $A2E[217] = 224; $A2E[219] = 221; $A2E[221] = 173;
61 0 $A2E[249] = 192;
62  
63 0 $E2A[74] = 96; $E2A[95] = 159; $E2A[106] = 94; $E2A[121] = 168;
64 0 $E2A[161] = 175; $E2A[173] = 221; $E2A[176] = 162; $E2A[186] = 172;
65 0 $E2A[187] = 91; $E2A[188] = 92; $E2A[192] = 249; $E2A[208] = 166;
66 0 $E2A[221] = 219; $E2A[224] = 217; $E2A[251] = 123; $E2A[253] = 125;
67 0 $E2A[255] = 126;
68 }
69 ▶elsif ($_EBCDIC && ord('^') == 176) { # as in codepage 037 on os400
Condition50%1/2
$CGI::Util::_EBCDIC and
!ll
860
MC/DC0%0/1
$CGI::Util::_EBCDIC and
$CGI::Util::_EBCDIC
Truth table50%1/2
A
A= $CGI::Util::_EBCDIC
Aresult
00
11
70 0 $A2E[10] = 37; $A2E[91] = 186; $A2E[93] = 187; $A2E[94] = 176;
71 0 $A2E[133] = 21; $A2E[168] = 189; $A2E[172] = 95; $A2E[221] = 173;
72  
73 0 $E2A[21] = 133; $E2A[37] = 10; $E2A[95] = 172; $E2A[173] = 221;
74 0 $E2A[176] = 94; $E2A[186] = 91; $E2A[187] = 93; $E2A[189] = 168;
75 }
76  
77 # Smart rearrangement of parameters to allow named parameter
78 # calling. We do the rearrangement if:
79 # the first parameter begins with a -
80  
81 4529 ▶sub rearrange {
Subroutine rearrange: called CC=3 SCAR=14.2
Pod undocumented
82 0 ▶ my ($order,@param) = @_;
Subroutine rearrange: not called CC=3 SCAR=14.2
Pod undocumented
83 0 my ($result, $leftover) = _rearrange_params( $order, @param );
84 0 ▶ push @$result, make_attributes( $leftover, defined $CGI::Q ? $CGI::Q->{escape} : 1 )
Branch: 4 branches
BranchTrueFalseTotal
if keys %$leftover 19 4510 4529
defined $CGI::Q ? : 16 3 19
if keys %$leftover 0 0 0
defined $CGI::Q ? : 0 0 0
85 if keys %$leftover;
86 0 @$result;
87 }
88  
89 6 ▶sub rearrange_header {
Subroutine rearrange_header: called CC=2 SCAR=10.3
Pod undocumented
90 0 ▶ my ($order,@param) = @_;
Subroutine rearrange_header: not called CC=2 SCAR=10.3
Pod undocumented
91  
92 0 my ($result,$leftover) = _rearrange_params( $order, @param );
93 0 ▶ push @$result, make_attributes( $leftover, 0, 1 ) if keys %$leftover;
Branch: 2 branches
BranchTrueFalseTotal
if keys %$leftover 0 6 6
if keys %$leftover 0 0 0
94  
95 0 @$result;
96 }
97  
98 4740 ▶sub _rearrange_params {
Subroutine _rearrange_params: called CC=12 SCAR=34.4
99 0 ▶ my($order,@param) = @_;
Subroutine _rearrange_params: not called CC=12 SCAR=34.4
100 0 ▶ return [] unless @param;
Branch: 2 branches
BranchTrueFalseTotal
unless @param 81 4659 4740
unless @param 0 0 0
101  
102 0 ▶ if (ref($param[0]) eq 'HASH') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $param[0] eq 'HASH') { } 8 4651 4659
if (ref $param[0] eq 'HASH') { } 0 0 0
103 0 @param = %{$param[0]};
104 } else {
105 return \@param
106 0 ▶ unless (defined($param[0]) && substr($param[0],0,1) eq '-');
Branch: 2 branches
BranchTrueFalseTotal
unless defined $param[0] and substr($param[0], 0, 1) eq "-" 4077 574 4651
unless defined $param[0] and substr($param[0], 0, 1) eq "-" 0 0 0
Condition33%2/6
defined $param[0] and substr($param[0], 0, 1) eq "-"
!ll&&!rl&&r
04077574
defined $param[0] and substr($param[0], 0, 1) eq "-"
!ll&&!rl&&r
000
MC/DC50%1/2
defined $param[0] and substr($param[0], 0, 1) eq "-"
defined $param[0] substr($param[0], 0, 1) eq "-"
MC/DC0%0/2
defined $param[0] and substr($param[0], 0, 1) eq "-"
defined $param[0] substr($param[0], 0, 1) eq "-"
Truth table66%2/3
A and B
A= defined $param[0]B= substr($param[0], 0, 1) eq "-"
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= defined $param[0]B= substr($param[0], 0, 1) eq "-"
ABresult
0X0
100
111
107 }
108  
109 # map parameters into positional indices
110 0 my ($i,%pos);
111 0 $i = 0;
112 0 foreach (@$order) {
113 0 ▶ foreach (ref($_) eq 'ARRAY' ? @$_ : $_) { $pos{lc($_)} = $i; }
Branch: 2 branches
BranchTrueFalseTotal
ref $_ eq 'ARRAY' ? : 987 3452 4439
ref $_ eq 'ARRAY' ? : 0 0 0
114 0 $i++;
115 }
116  
117 0 my %params_as_hash = ( @param );
118  
119 0 my (@result,%leftover);
120 0 $#result = $#$order; # preextend
121  
122 0 foreach my $k (
123 # sort keys alphabetically but favour certain keys before others
124 # specifically for the case where there could be several options
125 # for a param key, but one should be preferred (see GH #155)
126 sort {
127 0 ▶ if ( $a =~ /content/i ) { return 1 }
Branch: 4 branches
BranchTrueFalseTotal
if ($a =~ /content/i) { } 22 1062 1084
elsif ($b =~ /content/i) { } 41 1021 1062
if ($a =~ /content/i) { } 0 0 0
elsif ($b =~ /content/i) { } 0 0 0
128 0 elsif ( $b =~ /content/i ) { return -1 }
129 0 else { $a cmp $b }
130 }
131 keys( %params_as_hash )
132 ) {
133 0 my $key = lc($k);
134 0 $key =~ s/^\-//;
135 0 ▶ if (exists $pos{$key}) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $pos{$key}) { } 1231 134 1365
if (exists $pos{$key}) { } 0 0 0
136 0 $result[$pos{$key}] = $params_as_hash{$k};
137 } else {
138 0 $leftover{$key} = $params_as_hash{$k};
139 }
140 }
141  
142 0 return \@result, \%leftover;
143 }
144  
145 264 ▶sub make_attributes {
Subroutine make_attributes: called CC=9 SCAR=32.8
Pod undocumented
146 0 ▶ my $attr = shift;
Subroutine make_attributes: not called CC=9 SCAR=32.8
Pod undocumented
147 0 ▶ return () unless $attr && ref($attr) && ref($attr) eq 'HASH';
Branch: 2 branches
BranchTrueFalseTotal
unless $attr and ref $attr and ref $attr eq "HASH" 0 264 264
unless $attr and ref $attr and ref $attr eq "HASH" 0 0 0
Condition16%2/12
$attr and ref $attr and ref $attr eq "HASH"
!ll&&!rl&&r
00264
$attr and ref $attr
!ll&&!rl&&r
00264
$attr and ref $attr and ref $attr eq "HASH"
!ll&&!rl&&r
000
$attr and ref $attr
!ll&&!rl&&r
000
MC/DC0%0/3
$attr and ref $attr and ref $attr eq "HASH"
$attr ref $attr ref $attr eq "HASH"
MC/DC0%0/3
$attr and ref $attr and ref $attr eq "HASH"
$attr ref $attr ref $attr eq "HASH"
Truth table25%1/4
A and B and C
A= $attrB= ref $attrC= ref $attr eq "HASH"
ABCresult
0XX0
10X0
1100
1111
Truth table0%0/4
A and B and C
A= $attrB= ref $attrC= ref $attr eq "HASH"
ABCresult
0XX0
10X0
1100
1111
148 0 ▶ my $escape = shift || 0;
Condition50%2/4
shift() || 0
l!l
25014
shift() || 0
l!l
00
MC/DC100%1/1
shift() || 0
shift()
MC/DC0%0/1
shift() || 0
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
Truth table0%0/2
A
A= shift()
Aresult
11
00
149 0 my $do_not_quote = shift;
150  
151 0 ▶ my $quote = $do_not_quote ? '' : '"';
Branch: 2 branches
BranchTrueFalseTotal
$do_not_quote ? : 0 264 264
$do_not_quote ? : 0 0 0
152  
153 0 my @attr_keys= sort keys %$attr;
154 0 my(@att);
155 0 foreach (@attr_keys) {
156 0 my($key) = $_;
157 0 $key=~s/^\-//; # get rid of initial - if present
158  
159 # old way: breaks EBCDIC!
160 # $key=~tr/A-Z_/a-z-/; # parameters are lower case, use dashes
161  
162 0 ($key="\L$key") =~ tr/_/-/; # parameters are lower case, use dashes
163  
164 0 ▶ my $value = $escape ? simple_escape($attr->{$_}) : $attr->{$_};
Branch: 2 branches
BranchTrueFalseTotal
$escape ? : 351 15 366
$escape ? : 0 0 0
165 0 ▶ push(@att,defined($attr->{$_}) ? qq/$key=$quote$value$quote/ : qq/$key/);
Branch: 2 branches
BranchTrueFalseTotal
defined $attr->{$_} ? : 363 3 366
defined $attr->{$_} ? : 0 0 0
166 }
167 0 return sort @att;
168 }
169  
170 351 ▶sub simple_escape {
Subroutine simple_escape: called CC=2 SCAR=9.2
Pod undocumented
171 0 ▶ return unless defined(my $toencode = shift);
Subroutine simple_escape: not called CC=2 SCAR=9.2
Pod undocumented
Branch: 2 branches
BranchTrueFalseTotal
unless defined(my $toencode = shift()) 3 348 351
unless defined(my $toencode = shift()) 0 0 0
172 0 $toencode =~ s{&}{&}gso;
173 0 $toencode =~ s{<}{&lt;}gso;
174 0 $toencode =~ s{>}{&gt;}gso;
175 0 $toencode =~ s{\"}{&quot;}gso;
176 # Doesn't work. Can't work. forget it.
177 # $toencode =~ s{\x8b}{&#139;}gso;
178 # $toencode =~ s{\x9b}{&#155;}gso;
179 0 $toencode;
180 }
181  
182 1 ▶sub utf8_chr {
Subroutine utf8_chr: called CC=1 SCAR=1.2
Pod undocumented
183 0 ▶ my $c = shift(@_);
Subroutine utf8_chr: not called CC=1 SCAR=1.2
Pod undocumented
184 0 my $u = chr($c);
185 0 utf8::encode($u); # drop utf8 flag
186 0 return $u;
187 }
188  
189 # unescape URL-encoded data
190 920 ▶sub unescape {
Subroutine unescape: called CC=8 SCAR=32.6
Pod undocumented
191 0 ▶ shift() if @_ > 0 and (ref($_[0]) || (defined $_[1] && $_[0] eq $CGI::DefaultClass));
Subroutine unescape: not called CC=8 SCAR=32.6
Pod undocumented
Branch: 2 branches
BranchTrueFalseTotal
if @_ > 0 and ref $_[0] || defined $_[1] && $_[0] eq $CGI::DefaultClass 2 918 920
if @_ > 0 and ref $_[0] || defined $_[1] && $_[0] eq $CGI::DefaultClass 0 0 0
Condition27%5/18
@_ > 0 and ref $_[0] || defined $_[1] && $_[0] eq $CGI::DefaultClass
!ll&&!rl&&r
09182
ref $_[0] or defined $_[1] and $_[0] eq $CGI::DefaultClass
l!l&&r!l&&!r
20918
defined $_[1] and $_[0] eq $CGI::DefaultClass
!ll&&!rl&&r
91800
@_ > 0 and ref $_[0] || defined $_[1] && $_[0] eq $CGI::DefaultClass
!ll&&!rl&&r
000
ref $_[0] or defined $_[1] and $_[0] eq $CGI::DefaultClass
l!l&&r!l&&!r
000
defined $_[1] and $_[0] eq $CGI::DefaultClass
!ll&&!rl&&r
000
MC/DC25%1/4
@_ > 0 and ref $_[0] || defined $_[1] && $_[0] eq $CGI::DefaultClass
@_ > 0 ref $_[0] defined $_[1] $_[0] eq $CGI::DefaultClass
MC/DC0%0/4
@_ > 0 and ref $_[0] || defined $_[1] && $_[0] eq $CGI::DefaultClass
@_ > 0 ref $_[0] defined $_[1] $_[0] eq $CGI::DefaultClass
Truth table40%2/5
A and B or C and D
A= @_ > 0B= ref $_[0]C= defined $_[1]D= $_[0] eq $CGI::DefaultClass
ABCDresult
0XXX0
100X0
10100
11XX1
10111
Truth table0%0/5
A and B or C and D
A= @_ > 0B= ref $_[0]C= defined $_[1]D= $_[0] eq $CGI::DefaultClass
ABCDresult
0XXX0
100X0
10100
11XX1
10111
192 0 my $todecode = shift;
193 0 ▶ return undef unless defined($todecode);
Branch: 2 branches
BranchTrueFalseTotal
unless defined $todecode 2 918 920
unless defined $todecode 0 0 0
194 0 $todecode =~ tr/+/ /; # pluses become spaces
195 0 ▶ if ($_EBCDIC) {
Branch: 2 branches
BranchTrueFalseTotal
if ($CGI::Util::_EBCDIC) { } 0 918 918
if ($CGI::Util::_EBCDIC) { } 0 0 0
196 0 $todecode =~ s/%([0-9a-fA-F]{2})/chr $A2E[hex($1)]/ge;
197 } else {
198 # handle surrogate pairs first -- dankogai. Ref: http://unicode.org/faq/utf_bom.html#utf16-2
199 0 $todecode =~ s{
200 %u([Dd][89a-bA-B][0-9a-fA-F]{2}) # hi
201 %u([Dd][c-fC-F][0-9a-fA-F]{2}) # lo
202 }{
203 0 utf8_chr(
204 0x10000
205 + (hex($1) - 0xD800) * 0x400
206 + (hex($2) - 0xDC00)
207 )
208 }gex;
209 0 $todecode =~ s/%(?:([0-9a-fA-F]{2})|u([0-9a-fA-F]{4}))/
210 0 ▶ defined($1)? chr hex($1) : utf8_chr(hex($2))/ge;
Branch: 2 branches
BranchTrueFalseTotal
defined $1 ? : 102 0 102
defined $1 ? : 0 0 0
211 }
212 0 return $todecode;
213 }
214  
215 # URL-encode data
216 #
217 # We cannot use the %u escapes, they were rejected by W3C, so the official
218 # way is %XX-escaped utf-8 encoding.
219 # Naturally, Unicode strings have to be converted to their utf-8 byte
220 # representation.
221 # Byte strings were traditionally used directly as a sequence of octets.
222 # This worked if they actually represented binary data (i.e. in CGI::Compress).
223 # This also worked if these byte strings were actually utf-8 encoded; e.g.,
224 # when the source file used utf-8 without the appropriate "use utf8;".
225 # This fails if the byte string is actually a Latin 1 encoded string, but it
226 # was always so and cannot be fixed without breaking the binary data case.
227 # -- Stepan Kasal <skasal@redhat.com>
228 #
229  
230 382 ▶sub escape {
Subroutine escape: called CC=8 SCAR=32.9
Pod undocumented
231 # If we being called in an OO-context, discard the first argument.
232 0 ▶ shift() if @_ > 1 and ( ref($_[0]) || (defined $_[1] && $_[0] eq $CGI::DefaultClass));
Subroutine escape: not called CC=8 SCAR=32.9
Pod undocumented
Branch: 2 branches
BranchTrueFalseTotal
if @_ > 1 and ref $_[0] || defined $_[1] && $_[0] eq $CGI::DefaultClass 13 369 382
if @_ > 1 and ref $_[0] || defined $_[1] && $_[0] eq $CGI::DefaultClass 0 0 0
Condition16%3/18
@_ > 1 and ref $_[0] || defined $_[1] && $_[0] eq $CGI::DefaultClass
!ll&&!rl&&r
369013
ref $_[0] or defined $_[1] and $_[0] eq $CGI::DefaultClass
l!l&&r!l&&!r
1300
defined $_[1] and $_[0] eq $CGI::DefaultClass
!ll&&!rl&&r
000
@_ > 1 and ref $_[0] || defined $_[1] && $_[0] eq $CGI::DefaultClass
!ll&&!rl&&r
000
ref $_[0] or defined $_[1] and $_[0] eq $CGI::DefaultClass
l!l&&r!l&&!r
000
defined $_[1] and $_[0] eq $CGI::DefaultClass
!ll&&!rl&&r
000
MC/DC25%1/4
@_ > 1 and ref $_[0] || defined $_[1] && $_[0] eq $CGI::DefaultClass
@_ > 1 ref $_[0] defined $_[1] $_[0] eq $CGI::DefaultClass
MC/DC0%0/4
@_ > 1 and ref $_[0] || defined $_[1] && $_[0] eq $CGI::DefaultClass
@_ > 1 ref $_[0] defined $_[1] $_[0] eq $CGI::DefaultClass
Truth table40%2/5
A and B or C and D
A= @_ > 1B= ref $_[0]C= defined $_[1]D= $_[0] eq $CGI::DefaultClass
ABCDresult
0XXX0
100X0
10100
11XX1
10111
Truth table0%0/5
A and B or C and D
A= @_ > 1B= ref $_[0]C= defined $_[1]D= $_[0] eq $CGI::DefaultClass
ABCDresult
0XXX0
100X0
10100
11XX1
10111
233 0 my $toencode = shift;
234 0 ▶ return undef unless defined($toencode);
Branch: 2 branches
BranchTrueFalseTotal
unless defined $toencode 20 362 382
unless defined $toencode 0 0 0
235 0 ▶ utf8::encode($toencode) if utf8::is_utf8($toencode);
Branch: 2 branches
BranchTrueFalseTotal
if utf8::is_utf8($toencode) 1 361 362
if utf8::is_utf8($toencode) 0 0 0
236 0 ▶ if ($_EBCDIC) {
Branch: 2 branches
BranchTrueFalseTotal
if ($CGI::Util::_EBCDIC) { } 0 362 362
if ($CGI::Util::_EBCDIC) { } 0 0 0
237 0 $toencode=~s/([^a-zA-Z0-9_.~-])/uc sprintf("%%%02x",$E2A[ord($1)])/eg;
238 } else {
239 0 $toencode=~s/([^a-zA-Z0-9_.~-])/uc sprintf("%%%02x",ord($1))/eg;
240 }
241 0 return $toencode;
242 }
243  
244 # This internal routine creates date strings suitable for use in
245 # cookies and HTTP headers. (They differ, unfortunately.)
246 # Thanks to Mark Fisher for this.
247 34 ▶sub expires {
Subroutine expires: called CC=2 SCAR=9.2
Pod undocumented
248 0 ▶ my $time = shift;
Subroutine expires: not called CC=2 SCAR=9.2
Pod undocumented
249  
250 0 my(@MON)=qw/Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec/;
251 0 my(@WDAY) = qw/Sun Mon Tue Wed Thu Fri Sat/;
252  
253 # pass through preformatted dates for the sake of expire_calc()
254 0 $time = expire_calc($time);
255 0 ▶ return $time unless $time =~ /^\d+$/;
Branch: 2 branches
BranchTrueFalseTotal
unless $time =~ /^\d+$/ 7 27 34
unless $time =~ /^\d+$/ 0 0 0
256  
257 0 my($sec,$min,$hour,$mday,$mon,$year,$wday) = gmtime($time);
258 0 $year += 1900;
259 0 return sprintf("%s, %02d %s %04d %02d:%02d:%02d GMT",
260 $WDAY[$wday],$mday,$MON[$mon],$year,$hour,$min,$sec);
261 }
262  
263 # This internal routine creates an expires time exactly some number of
264 # hours from the current time. It incorporates modifications from
265 # Mark Fisher.
266 39 ▶sub expire_calc {
Subroutine expire_calc: called CC=6 SCAR=24.1
Pod undocumented
267 0 ▶ my($time) = @_;
Subroutine expire_calc: not called CC=6 SCAR=24.1
Pod undocumented
268 0 my(%mult) = ('s'=>1,
269 'm'=>60,
270 'h'=>60*60,
271 'd'=>60*60*24,
272 'M'=>60*60*24*30,
273 'y'=>60*60*24*365);
274 # format for time can be in any of the forms...
275 # "now" -- expire immediately
276 # "+180s" -- in 180 seconds
277 # "+2m" -- in 2 minutes
278 # "+12h" -- in 12 hours
279 # "+1d" -- in 1 day
280 # "+3M" -- in 3 months
281 # "+2y" -- in 2 years
282 # "-3m" -- 3 minutes ago(!)
283 # If you don't supply one of these forms, we assume you are
284 # specifying the date yourself
285 0 my($offset);
286 0 ▶ if (!$time || (lc($time) eq 'now')) {
Branch: 6 branches
BranchTrueFalseTotal
if (not $time or lc $time eq 'now') { } 19 20 39
elsif ($time =~ /^\d+/) { } 2 18 20
elsif ($time =~ /^([+-]?(?:\d+|\d*\.\d*))([smhdMy])/) { } 12 6 18
if (not $time or lc $time eq 'now') { } 0 0 0
elsif ($time =~ /^\d+/) { } 0 0 0
elsif ($time =~ /^([+-]?(?:\d+|\d*\.\d*))([smhdMy])/) { } 0 0 0
Condition50%3/6
not $time or lc $time eq "now"
l!l&&r!l&&!r
15420
not $time or lc $time eq "now"
l!l&&r!l&&!r
000
MC/DC100%2/2
not $time or lc $time eq "now"
not $time lc $time eq "now"
MC/DC0%0/2
not $time or lc $time eq "now"
not $time lc $time eq "now"
Truth table100%3/3
not(A) or B
A= not $timeB= lc $time eq "now"
ABresult
1X1
011
000
Truth table0%0/3
not(A) or B
A= not $timeB= lc $time eq "now"
ABresult
1X1
011
000
287 0 $offset = 0;
288 } elsif ($time=~/^\d+/) {
289 0 return $time;
290 } elsif ($time=~/^([+-]?(?:\d+|\d*\.\d*))([smhdMy])/) {
291 0 ▶ $offset = ($mult{$2} || 1)*$1;
Condition25%1/4
$mult{$2} || 1
l!l
120
$mult{$2} || 1
l!l
00
MC/DC0%0/1
$mult{$2} || 1
$mult{$2}
MC/DC0%0/1
$mult{$2} || 1
$mult{$2}
Truth table50%1/2
A
A= $mult{$2}
Aresult
11
00
Truth table0%0/2
A
A= $mult{$2}
Aresult
11
00
292 } else {
293 0 return $time;
294 }
295 0 my $cur_time = time;
296 0 return ($cur_time+$offset);
297 }
298  
299 1 ▶sub ebcdic2ascii {
Subroutine ebcdic2ascii: called CC=1 SCAR=1.2
Pod undocumented
300 0 ▶ my $data = shift;
Subroutine ebcdic2ascii: not called CC=1 SCAR=1.2
Pod undocumented
301 0 $data =~ s/(.)/chr $E2A[ord($1)]/ge;
302 0 $data;
303 }
304  
305 1 ▶sub ascii2ebcdic {
Subroutine ascii2ebcdic: called CC=1 SCAR=1.2
Pod undocumented
306 0 ▶ my $data = shift;
Subroutine ascii2ebcdic: not called CC=1 SCAR=1.2
Pod undocumented
307 0 $data =~ s/(.)/chr $A2E[ord($1)]/ge;
308 0 $data;
309 }
310  
311 86 1;
312  
313 __END__
« CGI.pm ↑ Summary CGI/Push.pm »