CGI/Util.pm

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