CGI.pm

filter: Statementstmt 78.2% 1604 / 2051 Branchbran 61.4% 855 / 1392 Conditioncond 56.3% 477 / 846 MC/DCmcdc 40.7% 191 / 469 Subroutinesub 82.2% 162 / 197 Podpod 25.6% 37 / 144 totaltotal 65.2% 3326 / 5099 CC 1775 SCAR 48.4
CC
1775
Cov
68%
init
1245.7
init
1245.7
_style
215.8
CRAP 126.0
↑ Summary CGI/Util.pm »
1 package CGI;
2 84 require 5.008001;
3 84 ▶use Carp 'croak';
Subroutine BEGIN: called CC=1 SCAR=0.0
4 84 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 84 my $appease_cpants_kwalitee = q/
7 use strict;
8 use warnings;
9 #/;
10  
11 84 $CGI::VERSION='5.02';
12  
13 84 ▶use CGI::Util qw(rearrange rearrange_header make_attributes unescape escape expires ebcdic2ascii ascii2ebcdic);
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 84 $_XHTML_DTD = ['-//W3C//DTD XHTML 1.0 Transitional//EN',
16 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'];
17  
18 {
19 84 local $^W = 0;
20 84 $TAINTED = substr("$0$^X",0,0);
21 }
22  
23 84 $MOD_PERL = 0; # no mod_perl by default
24  
25 #global settings
26 84 $POST_MAX = 1024 * 1024 * 128; # 128MB, set to -1 for no limit
27 84 $MAX_PARAMS = 10_000; # param values per request, -1 for no limit
28 84 $MAX_UPLOADS = 1_000; # uploaded files per request, -1 for no limit
29 84 my $REQUEST_TOO_LARGE = "CGI.pm: 413 Request entity too large\n";
30 # params that CGI.pm sets itself to the raw request body (or XForms model),
31 # which must not be settable by the client via the query string or a form
32 # field, as an app couldn't then tell them apart from the real body
33 84 my %RESERVED_PARAM = map { $_ => 1 } qw/ POSTDATA PUTDATA PATCHDATA XForms:Model /;
34 84 $DISABLE_UPLOADS = 0;
35 84 $SANITIZE_UPLOAD_FILENAMES = 1; # set to 0 for the raw client filename
36 84 $UNLINK_TMP_FILES = 1;
37 84 $LIST_CONTEXT_WARN = 1;
38 84 $ENCODE_ENTITIES = q{&<>"'};
39 84 $ALLOW_DELETE_CONTENT = 0;
40 84 $COOKIE_CACHE = 0; # backcompat: cache was broken for years
41 84 $TRUST_X_FORWARDED_HOST = 0; # set to 1 if behind a proxy that sets it
42  
43 84 @SAVED_SYMBOLS = ();
44  
45 # >>>>> Here are some globals that you might want to adjust <<<<<<
46 1967 ▶sub initialize_globals {
Subroutine initialize_globals: called CC=2 SCAR=9.2
Pod undocumented
47 # Set this to 1 to generate XTML-compatible output
48 0 ▶ $XHTML = 1;
Subroutine initialize_globals: not called CC=2 SCAR=9.2
Pod undocumented
49  
50 # Change this to the preferred DTD to print in start_html()
51 # or use default_dtd('text of DTD to use');
52 0 $DEFAULT_DTD = [ '-//W3C//DTD HTML 4.01 Transitional//EN',
53 'http://www.w3.org/TR/html4/loose.dtd' ] ;
54  
55 # Set this to 1 to enable NOSTICKY scripts
56 # or:
57 # 1) use CGI '-nosticky';
58 # 2) $CGI::NOSTICKY = 1;
59 0 $NOSTICKY = 0;
60  
61 # Set this to 1 to enable NPH scripts
62 # or:
63 # 1) use CGI qw(-nph)
64 # 2) CGI::nph(1)
65 # 3) print header(-nph=>1)
66 0 $NPH = 0;
67  
68 # Set this to 1 to enable debugging from @ARGV
69 # Set to 2 to enable debugging from STDIN
70 0 $DEBUG = 1;
71  
72 # Set this to 1 to generate automatic tab indexes
73 0 $TABINDEX = 0;
74  
75 # Set this to 1 to cause files uploaded in multipart documents
76 # to be closed, instead of caching the file handle
77 # or:
78 # 1) use CGI qw(:close_upload_files)
79 # 2) $CGI::close_upload_files(1);
80 # Uploads with many files run out of file handles.
81 # Also, for performance, since the file is already on disk,
82 # it can just be renamed, instead of read and written.
83 0 $CLOSE_UPLOAD_FILES = 0;
84  
85 # Automatically determined -- don't change
86 0 $EBCDIC = 0;
87  
88 # Change this to 1 to suppress redundant HTTP headers
89 0 $HEADERS_ONCE = 0;
90  
91 # separate the name=value pairs by semicolons rather than ampersands
92 0 $USE_PARAM_SEMICOLONS = 1;
93  
94 # Do not include undefined params parsed from query string
95 # use CGI qw(-no_undef_params);
96 0 $NO_UNDEF_PARAMS = 0;
97  
98 # return everything as utf-8
99 0 $PARAM_UTF8 = 0;
100  
101 # make param('PUTDATA') act like file upload
102 0 $PUTDATA_UPLOAD = 0;
103  
104 # Add QUERY_STRING to POST request
105 0 $APPEND_QUERY_STRING = 0;
106  
107 # Other globals that you shouldn't worry about.
108 0 undef $Q;
109 0 $BEEN_THERE = 0;
110 0 $DTD_PUBLIC_IDENTIFIER = "";
111 0 undef @QUERY_PARAM;
112 0 undef %QUERY_PARAM;
113 0 undef %EXPORT;
114 0 undef $QUERY_CHARSET;
115 0 undef $QUERY_CGI_ERROR;
116 0 undef %QUERY_FIELDNAMES;
117 0 undef %QUERY_TMPFILES;
118  
119 # CGI::Carp buffers warnings for warningsToBrowser(), which must not be
120 # carried over into another request (and so another user's page) in a
121 # persistent environment
122 0 ▶ CGI::Carp::_reset_globals() if defined &CGI::Carp::_reset_globals;
Branch: 2 branches
BranchTrueFalseTotal
if defined &CGI::Carp::_reset_globals 7 1960 1967
if defined &CGI::Carp::_reset_globals 0 0 0
123  
124 # prevent complaints by mod_perl
125 0 1;
126 }
127  
128 # ------------------ START OF THE LIBRARY ------------
129  
130 # make mod_perlhappy
131 84 initialize_globals();
132  
133 # FIGURE OUT THE OS WE'RE RUNNING UNDER
134 # Some systems support the $^O variable. If not
135 # available then require() the Config library
136 84 ▶unless ($OS) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($OS) 84 0 84
137 84 ▶ unless ($OS = $^O) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($OS = $^O) 0 84 84
138 0 require Config;
139 0 $OS = $Config::Config{'osname'};
140 }
141 }
142 84 ▶if ($OS =~ /^MSWin/i) {
Branch: 8 branches
BranchTrueFalseTotal
if ($OS =~ /^MSWin/i) { } 0 84 84
elsif ($OS =~ /^VMS/i) { } 0 84 84
elsif ($OS =~ /^dos/i) { } 0 84 84
elsif ($OS =~ /^MacOS/i) { } 0 84 84
elsif ($OS =~ /^os2/i) { } 0 84 84
elsif ($OS =~ /^epoc/i) { } 0 84 84
elsif ($OS =~ /^cygwin/i) { } 0 84 84
elsif ($OS =~ /^NetWare/i) { } 0 84 84
143 0 $OS = 'WINDOWS';
144 } elsif ($OS =~ /^VMS/i) {
145 0 $OS = 'VMS';
146 } elsif ($OS =~ /^dos/i) {
147 0 $OS = 'DOS';
148 } elsif ($OS =~ /^MacOS/i) {
149 0 $OS = 'MACINTOSH';
150 } elsif ($OS =~ /^os2/i) {
151 0 $OS = 'OS2';
152 } elsif ($OS =~ /^epoc/i) {
153 0 $OS = 'EPOC';
154 } elsif ($OS =~ /^cygwin/i) {
155 0 $OS = 'CYGWIN';
156 } elsif ($OS =~ /^NetWare/i) {
157 0 $OS = 'NETWARE';
158 } else {
159 84 $OS = 'UNIX';
160 }
161  
162 # Some OS logic. Binary mode enabled on DOS, NT and VMS
163 84 $needs_binmode = $OS=~/^(WINDOWS|DOS|OS2|MSWin|CYGWIN|NETWARE)/;
164  
165 # This is the default class for the CGI object to use when all else fails.
166 84 ▶$DefaultClass = 'CGI' unless defined $CGI::DefaultClass;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $DefaultClass 84 0 84
167  
168 # The path separator is a slash, backslash or semicolon, depending
169 # on the platform.
170 $SL = {
171 UNIX => '/', OS2 => '\\', EPOC => '/', CYGWIN => '/', NETWARE => '/',
172 WINDOWS => '\\', DOS => '\\', MACINTOSH => ':', VMS => '/'
173 84 }->{$OS};
174  
175 # This no longer seems to be necessary
176 # Turn on NPH scripts by default when running under IIS server!
177 # $NPH++ if defined($ENV{'SERVER_SOFTWARE'}) && $ENV{'SERVER_SOFTWARE'}=~/IIS/;
178 84 ▶$IIS++ if defined($ENV{'SERVER_SOFTWARE'}) && $ENV{'SERVER_SOFTWARE'}=~/IIS/;
Branch: 1 branch
BranchTrueFalseTotal
if defined $ENV{"SERVER_SOFTWARE"} and $ENV{"SERVER_SOFTWARE"} =~ /IIS/ 0 84 84
Condition33%1/3
defined $ENV{"SERVER_SOFTWARE"} and $ENV{"SERVER_SOFTWARE"} =~ /IIS/
!ll&&!rl&&r
8400
MC/DC0%0/2
defined $ENV{"SERVER_SOFTWARE"} and $ENV{"SERVER_SOFTWARE"} =~ /IIS/
defined $ENV{"SERVER_SOFTWARE"} $ENV{"SERVER_SOFTWARE"} =~ /IIS/
Truth table33%1/3
A and B
A= defined $ENV{"SERVER_SOFTWARE"}B= $ENV{"SERVER_SOFTWARE"} =~ /IIS/
ABresult
0X0
100
111
179  
180 # Turn on special checking for ActiveState's PerlEx
181 84 ▶$PERLEX++ if defined($ENV{'GATEWAY_INTERFACE'}) && $ENV{'GATEWAY_INTERFACE'} =~ /^CGI-PerlEx/;
Branch: 1 branch
BranchTrueFalseTotal
if defined $ENV{"GATEWAY_INTERFACE"} and $ENV{"GATEWAY_INTERFACE"} =~ /^CGI-PerlEx/ 0 84 84
Condition33%1/3
defined $ENV{"GATEWAY_INTERFACE"} and $ENV{"GATEWAY_INTERFACE"} =~ /^CGI-PerlEx/
!ll&&!rl&&r
8400
MC/DC0%0/2
defined $ENV{"GATEWAY_INTERFACE"} and $ENV{"GATEWAY_INTERFACE"} =~ /^CGI-PerlEx/
defined $ENV{"GATEWAY_INTERFACE"} $ENV{"GATEWAY_INTERFACE"} =~ /^CGI-PerlEx/
Truth table33%1/3
A and B
A= defined $ENV{"GATEWAY_INTERFACE"}B= $ENV{"GATEWAY_INTERFACE"} =~ /^CGI-PerlEx/
ABresult
0X0
100
111
182  
183 # Turn on special checking for Doug MacEachern's modperl
184 # PerlEx::DBI tries to fool DBI by setting MOD_PERL
185 84 ▶if (exists $ENV{MOD_PERL} && ! $PERLEX) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ENV{"MOD_PERL"} and not $PERLEX) 0 84 84
Condition33%1/3
exists $ENV{"MOD_PERL"} and not $PERLEX
!ll&&!rl&&r
8400
MC/DC0%0/2
exists $ENV{"MOD_PERL"} and not $PERLEX
exists $ENV{"MOD_PERL"} not $PERLEX
Truth table33%1/3
A and not(B)
A= exists $ENV{"MOD_PERL"}B= not $PERLEX
ABresult
0X0
100
111
186 # mod_perl handlers may run system() on scripts using CGI.pm;
187 # Make sure so we don't get fooled by inherited $ENV{MOD_PERL}
188 0 ▶ if (exists $ENV{MOD_PERL_API_VERSION} && $ENV{MOD_PERL_API_VERSION} == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ENV{'MOD_PERL_API_VERSION'} and $ENV{'MOD_PERL_API_VERSION'} == 2) { } 0 0 0
Condition0%0/3
exists $ENV{"MOD_PERL_API_VERSION"} and $ENV{"MOD_PERL_API_VERSION"} == 2
!ll&&!rl&&r
000
MC/DC0%0/2
exists $ENV{"MOD_PERL_API_VERSION"} and $ENV{"MOD_PERL_API_VERSION"} == 2
exists $ENV{"MOD_PERL_API_VERSION"} $ENV{"MOD_PERL_API_VERSION"} == 2
Truth table0%0/3
A and B
A= exists $ENV{"MOD_PERL_API_VERSION"}B= $ENV{"MOD_PERL_API_VERSION"} == 2
ABresult
0X0
100
111
189 0 $MOD_PERL = 2;
190 0 require Apache2::Response;
191 0 require Apache2::RequestRec;
192 0 require Apache2::RequestUtil;
193 0 require Apache2::RequestIO;
194 0 require APR::Pool;
195 } else {
196 0 $MOD_PERL = 1;
197 0 require Apache;
198 }
199 }
200  
201 # Define the CRLF sequence. I can't use a simple "\r\n" because the meaning
202 # of "\n" is different on different OS's (sometimes it generates CRLF, sometimes LF
203 # and sometimes CR). The most popular VMS web server
204 # doesn't accept CRLF -- instead it wants a LR. EBCDIC machines don't
205 # use ASCII, so \015\012 means something different. I find this all
206 # really annoying.
207 84 $EBCDIC = "\t" ne "\011";
208 84 ▶if ($OS eq 'VMS') {
Branch: 2 branches
BranchTrueFalseTotal
if ($OS eq 'VMS') { } 0 84 84
elsif ($EBCDIC) { } 0 84 84
209 0 $CRLF = "\n";
210 } elsif ($EBCDIC) {
211 0 $CRLF= "\r\n";
212 } else {
213 84 $CRLF = "\015\012";
214 }
215  
216 84 ▶_set_binmode() if ($needs_binmode);
Branch: 1 branch
BranchTrueFalseTotal
if $needs_binmode 0 84 84
217  
218 1 ▶sub _set_binmode {
Subroutine _set_binmode: called CC=3 SCAR=14.2
219  
220 # rt #57524 - don't set binmode on filehandles if there are
221 # already none default layers set on them
222 0 ▶ my %default_layers = (
Subroutine _set_binmode: not called CC=3 SCAR=14.2
223 unix => 1,
224 perlio => 1,
225 stdio => 1,
226 crlf => 1,
227 );
228  
229 0 foreach my $fh (
230 \*main::STDOUT,
231 \*main::STDIN,
232 \*main::STDERR,
233 ) {
234 0 my @modes = grep { ! $default_layers{$_} }
235 PerlIO::get_layers( $fh );
236  
237 0 ▶ if ( ! @modes ) {
Branch: 2 branches
BranchTrueFalseTotal
unless (@modes) 2 1 3
unless (@modes) 0 0 0
238 0 $CGI::DefaultClass->binmode( $fh );
239 }
240 }
241 }
242  
243 84 %EXPORT_TAGS = (
244 ':html2' => [ 'h1' .. 'h6', qw/
245 p br hr ol ul li dl dt dd menu code var strong em
246 tt u i b blockquote pre img a address cite samp dfn html head
247 base body Link nextid title meta kbd start_html end_html
248 input Select option comment charset escapeHTML
249 / ],
250 ':html3' => [ qw/
251 div table caption th td TR Tr sup Sub strike applet Param nobr
252 embed basefont style span layer ilayer font frameset frame script small big Area Map
253 / ],
254 ':html4' => [ qw/
255 abbr acronym bdo col colgroup del fieldset iframe
256 ins label legend noframes noscript object optgroup Q
257 thead tbody tfoot
258 / ],
259 ':form' => [ qw/
260 textfield textarea filefield password_field hidden checkbox checkbox_group
261 submit reset defaults radio_group popup_menu button autoEscape
262 scrolling_list image_button start_form end_form
263 start_multipart_form end_multipart_form isindex tmpFileName uploadInfo URL_ENCODED MULTIPART
264 / ],
265 ':cgi' => [ qw/
266 param multi_param upload path_info path_translated request_uri url self_url script_name
267 cookie Dump raw_cookie request_method query_string Accept user_agent remote_host content_type
268 remote_addr referer server_name server_software server_port server_protocol virtual_port
269 virtual_host remote_ident auth_type http append save_parameters restore_parameters param_fetch
270 remote_user user_name header redirect import_names put Delete Delete_all url_param cgi_error env_query_string
271 / ],
272 ':netscape' => [qw/blink fontsize center/],
273 ':ssl' => [qw/https/],
274 ':cgi-lib' => [qw/ReadParse PrintHeader HtmlTop HtmlBot SplitParam Vars/],
275 ':push' => [qw/multipart_init multipart_start multipart_end multipart_final/],
276  
277 # bulk export/import
278 ':html' => [qw/:html2 :html3 :html4 :netscape/],
279 ':standard' => [qw/:html2 :html3 :html4 :form :cgi :ssl/],
280 ':all' => [qw/:html2 :html3 :html4 :netscape :form :cgi :ssl :push/]
281 );
282  
283 # to import symbols into caller
284 83 ▶sub import {
Subroutine import: called CC=5 SCAR=22.5
285 0 ▶ my $self = shift;
Subroutine import: not called CC=5 SCAR=22.5
286  
287 # This causes modules to clash.
288 0 undef %EXPORT_OK;
289 0 undef %EXPORT;
290  
291 0 $self->_setup_symbols(@_);
292 0 my ($callpack, $callfile, $callline) = caller;
293  
294 0 ▶ if ( $callpack eq 'CGI::Fast' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($callpack eq "CGI::Fast") 0 83 83
if ($callpack eq "CGI::Fast") 0 0 0
295 # fixes GH #11 (and GH #12 in CGI::Fast since
296 # sub import was added to CGI::Fast in 9537f90
297 # so we need to move up a level to export the
298 # routines to the namespace of whatever is using
299 # CGI::Fast
300 0 ($callpack, $callfile, $callline) = caller(1);
301 }
302  
303 # To allow overriding, search through the packages
304 # Till we find one in which the correct subroutine is defined.
305 0 my @packages = ($self,@{"$self\:\:ISA"});
306 0 for $sym (sort keys %EXPORT) {
307 0 my $pck;
308 0 my $def = $DefaultClass;
309 0 for $pck (@packages) {
310 0 ▶ if (defined(&{"$pck\:\:$sym"})) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined &{"${pck}::$sym";}) 2127 0 2127
if (defined &{"${pck}::$sym";}) 0 0 0
311 0 $def = $pck;
312 0 last;
313 }
314 }
315 0 *{"${callpack}::$sym"} = \&{"$def\:\:$sym"};
316 }
317 }
318  
319 2347 ▶sub expand_tags {
Subroutine expand_tags: called CC=4 SCAR=17.9
Pod undocumented
320 0 ▶ my($tag) = @_;
Subroutine expand_tags: not called CC=4 SCAR=17.9
Pod undocumented
321 0 ▶ return ("start_$1","end_$1") if $tag=~/^(?:\*|start_|end_)(.+)/;
Branch: 2 branches
BranchTrueFalseTotal
if $tag =~ /^(?:\*|start_|end_)(.+)/ 128 2219 2347
if $tag =~ /^(?:\*|start_|end_)(.+)/ 0 0 0
322 0 my(@r);
323 0 ▶ return ($tag) unless $EXPORT_TAGS{$tag};
Branch: 2 branches
BranchTrueFalseTotal
unless $EXPORT_TAGS{$tag} 2124 95 2219
unless $EXPORT_TAGS{$tag} 0 0 0
324 0 for (@{$EXPORT_TAGS{$tag}}) {
325 0 push(@r,&expand_tags($_));
326 }
327 0 return @r;
328 }
329  
330 #### Method: new
331 # The new routine. This will check the current environment
332 # for an existing query string, and initialize itself, if so.
333 ####
334 2037 ▶sub new {
Subroutine new: called CC=17 SCAR=50.6
Pod documented
335 0 ▶ my($class,@initializer) = @_;
Subroutine new: not called CC=17 SCAR=50.6
Pod documented
336 0 my $self = {};
337  
338 0 ▶ bless $self,ref $class || $class || $DefaultClass;
Condition16%2/12
ref $class || $class || $DefaultClass
l!l&&r!l&&!r
203700
ref $class or $class
l!l&&r!l&&!r
020370
ref $class || $class || $DefaultClass
l!l&&r!l&&!r
000
ref $class or $class
l!l&&r!l&&!r
000
MC/DC0%0/3
ref $class || $class || $DefaultClass
ref $class $class $DefaultClass
MC/DC0%0/3
ref $class || $class || $DefaultClass
ref $class $class $DefaultClass
Truth table25%1/4
A or B || C
A= ref $classB= $classC= $DefaultClass
ABCresult
1XX1
01X1
0011
0000
Truth table0%0/4
A or B || C
A= ref $classB= $classC= $DefaultClass
ABCresult
1XX1
01X1
0011
0000
339  
340 # always use a tempfile
341 0 $self->{'use_tempfile'} = 1;
342  
343 0 ▶ if (ref($initializer[0])
Branch: 2 branches
BranchTrueFalseTotal
if (ref $initializer[0] and UNIVERSAL::isa($initializer[0], "Apache") || UNIVERSAL::isa($initializer[0], "Apache2::RequestRec")) 0 2037 2037
if (ref $initializer[0] and UNIVERSAL::isa($initializer[0], "Apache") || UNIVERSAL::isa($initializer[0], "Apache2::RequestRec")) 0 0 0
Condition25%3/12
ref $initializer[0] and UNIVERSAL::isa($initializer[0], "Apache") || UNIVERSAL::isa($initializer[0], "Apache2::RequestRec")
!ll&&!rl&&r
2015220
UNIVERSAL::isa($initializer[0], "Apache") or UNIVERSAL::isa($initializer[0], "Apache2::RequestRec")
l!l&&r!l&&!r
0022
ref $initializer[0] and UNIVERSAL::isa($initializer[0], "Apache") || UNIVERSAL::isa($initializer[0], "Apache2::RequestRec")
!ll&&!rl&&r
000
UNIVERSAL::isa($initializer[0], "Apache") or UNIVERSAL::isa($initializer[0], "Apache2::RequestRec")
l!l&&r!l&&!r
000
MC/DC0%0/3
ref $initializer[0] and UNIVERSAL::isa($initializer[0], "Apache") || UNIVERSAL::isa($initializer[0], "Apache2::RequestRec")
ref $initializer[0] UNIVERSAL::isa($initializer[0], "Apache") UNIVERSAL::isa($initializer[0], "Apache2::RequestRec")
MC/DC0%0/3
ref $initializer[0] and UNIVERSAL::isa($initializer[0], "Apache") || UNIVERSAL::isa($initializer[0], "Apache2::RequestRec")
ref $initializer[0] UNIVERSAL::isa($initializer[0], "Apache") UNIVERSAL::isa($initializer[0], "Apache2::RequestRec")
Truth table50%2/4
A and B or C
A= ref $initializer[0]B= UNIVERSAL::isa($initializer[0], "Apache")C= UNIVERSAL::isa($initializer[0], "Apache2::RequestRec")
ABCresult
0XX0
1000
11X1
1011
Truth table0%0/4
A and B or C
A= ref $initializer[0]B= UNIVERSAL::isa($initializer[0], "Apache")C= UNIVERSAL::isa($initializer[0], "Apache2::RequestRec")
ABCresult
0XX0
1000
11X1
1011
344 && (UNIVERSAL::isa($initializer[0],'Apache')
345 ||
346 UNIVERSAL::isa($initializer[0],'Apache2::RequestRec')
347 )) {
348 0 $self->r(shift @initializer);
349 }
350 0 ▶ if (ref($initializer[0])
Branch: 2 branches
BranchTrueFalseTotal
if (ref $initializer[0] and UNIVERSAL::isa($initializer[0], "CODE")) 9 2028 2037
if (ref $initializer[0] and UNIVERSAL::isa($initializer[0], "CODE")) 0 0 0
Condition50%3/6
ref $initializer[0] and UNIVERSAL::isa($initializer[0], "CODE")
!ll&&!rl&&r
2015139
ref $initializer[0] and UNIVERSAL::isa($initializer[0], "CODE")
!ll&&!rl&&r
000
MC/DC100%2/2
ref $initializer[0] and UNIVERSAL::isa($initializer[0], "CODE")
ref $initializer[0] UNIVERSAL::isa($initializer[0], "CODE")
MC/DC0%0/2
ref $initializer[0] and UNIVERSAL::isa($initializer[0], "CODE")
ref $initializer[0] UNIVERSAL::isa($initializer[0], "CODE")
Truth table100%3/3
A and B
A= ref $initializer[0]B= UNIVERSAL::isa($initializer[0], "CODE")
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= ref $initializer[0]B= UNIVERSAL::isa($initializer[0], "CODE")
ABresult
0X0
100
111
351 && (UNIVERSAL::isa($initializer[0],'CODE'))) {
352 0 $self->upload_hook(shift @initializer, shift @initializer);
353 0 ▶ $self->{'use_tempfile'} = shift @initializer if (@initializer > 0);
Branch: 2 branches
BranchTrueFalseTotal
if @initializer > 0 0 9 9
if @initializer > 0 0 0 0
354 }
355 0 ▶ if ($MOD_PERL) {
Branch: 2 branches
BranchTrueFalseTotal
if ($MOD_PERL) 0 2037 2037
if ($MOD_PERL) 0 0 0
356 0 ▶ if ($MOD_PERL == 1) {
Branch: 2 branches
BranchTrueFalseTotal
if ($MOD_PERL == 1) { } 0 0 0
if ($MOD_PERL == 1) { } 0 0 0
357 0 ▶ $self->r(Apache->request) unless $self->r;
Branch: 2 branches
BranchTrueFalseTotal
unless $self->r 0 0 0
unless $self->r 0 0 0
358 0 my $r = $self->r;
359 0 $r->register_cleanup(\&CGI::_reset_globals);
360 0 ▶ $self->_setup_symbols(@SAVED_SYMBOLS) if @SAVED_SYMBOLS;
Branch: 2 branches
BranchTrueFalseTotal
if @SAVED_SYMBOLS 0 0 0
if @SAVED_SYMBOLS 0 0 0
361 }
362 else {
363 # XXX: once we have the new API
364 # will do a real PerlOptions -SetupEnv check
365 0 ▶ $self->r(Apache2::RequestUtil->request) unless $self->r;
Branch: 2 branches
BranchTrueFalseTotal
unless $self->r 0 0 0
unless $self->r 0 0 0
366 0 my $r = $self->r;
367 0 ▶ $r->subprocess_env unless exists $ENV{REQUEST_METHOD};
Branch: 2 branches
BranchTrueFalseTotal
unless exists $ENV{"REQUEST_METHOD"} 0 0 0
unless exists $ENV{"REQUEST_METHOD"} 0 0 0
368 0 $r->pool->cleanup_register(\&CGI::_reset_globals);
369 0 ▶ $self->_setup_symbols(@SAVED_SYMBOLS) if @SAVED_SYMBOLS;
Branch: 2 branches
BranchTrueFalseTotal
if @SAVED_SYMBOLS 0 0 0
if @SAVED_SYMBOLS 0 0 0
370 }
371 0 undef $NPH;
372 }
373 0 ▶ $self->_reset_globals if $PERLEX;
Branch: 2 branches
BranchTrueFalseTotal
if $PERLEX 0 2037 2037
if $PERLEX 0 0 0
374 0 $self->init(@initializer);
375 0 return $self;
376 }
377  
378 2 ▶sub r {
Subroutine r: called CC=2 SCAR=9.2
Pod undocumented
379 0 ▶ my $self = shift;
Subroutine r: not called CC=2 SCAR=9.2
Pod undocumented
380 0 my $r = $self->{'.r'};
381 0 ▶ $self->{'.r'} = shift if @_;
Branch: 2 branches
BranchTrueFalseTotal
if @_ 1 1 2
if @_ 0 0 0
382 0 $r;
383 }
384  
385 9 ▶sub upload_hook {
Subroutine upload_hook: called CC=3 SCAR=16.5
Pod undocumented
386 0 ▶ my $self;
Subroutine upload_hook: not called CC=3 SCAR=16.5
Pod undocumented
387 0 ▶ if (ref $_[0] eq 'CODE') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $_[0] eq 'CODE') { } 0 9 9
if (ref $_[0] eq 'CODE') { } 0 0 0
388 0 $CGI::Q = $self = $CGI::DefaultClass->new(@_);
389 } else {
390 0 $self = shift;
391 }
392 0 my ($hook,$data,$use_tempfile) = @_;
393 0 $self->{'.upload_hook'} = $hook;
394 0 $self->{'.upload_data'} = $data;
395 0 ▶ $self->{'use_tempfile'} = $use_tempfile if defined $use_tempfile;
Branch: 2 branches
BranchTrueFalseTotal
if defined $use_tempfile 0 9 9
if defined $use_tempfile 0 0 0
396 }
397  
398 #### Method: param / multi_param
399 # Returns the value(s)of a named parameter.
400 # If invoked in a list context, returns the
401 # entire list. Otherwise returns the first
402 # member of the list.
403 # If name is not provided, return a list of all
404 # the known parameters names available.
405 # If more than one argument is provided, the
406 # second and subsequent arguments are used to
407 # set the value of the parameter.
408 #
409 # note that calling param() in list context
410 # will raise a warning about potential bad
411 # things, hence the multi_param method
412 ####
413 28 ▶sub multi_param {
Subroutine multi_param: called CC=1 SCAR=1.2
Pod undocumented
414 # we don't need to set $LIST_CONTEXT_WARN to 0 here
415 # because param() will check the caller before warning
416 0 ▶ my @list_of_params = param( @_ );
Subroutine multi_param: not called CC=1 SCAR=1.2
Pod undocumented
417 0 return @list_of_params;
418 }
419  
420 14276 ▶sub param {
Subroutine param: called CC=23 SCAR=46.9
Pod undocumented
421 0 ▶ my($self,@p) = self_or_default(@_);
Subroutine param: not called CC=23 SCAR=46.9
Pod undocumented
422  
423 0 ▶ return $self->all_parameters unless @p;
Branch: 2 branches
BranchTrueFalseTotal
unless @p 6123 8153 14276
unless @p 0 0 0
424  
425 # list context can be dangerous so warn:
426 # http://blog.gerv.net/2014.10/new-class-of-vulnerability-in-perl-web-applications
427 0 ▶ if ( wantarray && $LIST_CONTEXT_WARN == 1 ) {
Branch: 2 branches
BranchTrueFalseTotal
if (wantarray and $LIST_CONTEXT_WARN == 1) 288 7865 8153
if (wantarray and $LIST_CONTEXT_WARN == 1) 0 0 0
Condition50%3/6
wantarray and $LIST_CONTEXT_WARN == 1
!ll&&!rl&&r
58182047288
wantarray and $LIST_CONTEXT_WARN == 1
!ll&&!rl&&r
000
MC/DC100%2/2
wantarray and $LIST_CONTEXT_WARN == 1
wantarray $LIST_CONTEXT_WARN == 1
MC/DC0%0/2
wantarray and $LIST_CONTEXT_WARN == 1
wantarray $LIST_CONTEXT_WARN == 1
Truth table100%3/3
A and B
A= wantarrayB= $LIST_CONTEXT_WARN == 1
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= wantarrayB= $LIST_CONTEXT_WARN == 1
ABresult
0X0
100
111
428 0 my ( $package, $filename, $line ) = caller;
429 0 ▶ if ( $package ne 'CGI' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($package ne "CGI") 1 287 288
if ($package ne "CGI") 0 0 0
430 0 $LIST_CONTEXT_WARN++; # only warn once
431 0 warn "CGI::param called in list context from $filename line $line, this can lead to vulnerabilities. "
432 . 'See the warning in "Fetching the value or values of a single named parameter"';
433 }
434 }
435  
436 0 my($name,$value,@other);
437  
438 # For compatibility between old calling style and use_named_parameters() style,
439 # we have to special case for a single parameter present.
440 0 ▶ if (@p > 1) {
Branch: 2 branches
BranchTrueFalseTotal
if (@p > 1) { } 77 8076 8153
if (@p > 1) { } 0 0 0
441 0 ($name,$value,@other) = rearrange([NAME,[DEFAULT,VALUE,VALUES]],@p);
442 0 my(@values);
443  
444 0 ▶ if (substr($p[0],0,1) eq '-') {
Branch: 2 branches
BranchTrueFalseTotal
if (substr($p[0], 0, 1) eq '-') { } 59 18 77
if (substr($p[0], 0, 1) eq '-') { } 0 0 0
445 0 ▶ @values = defined($value) ? (ref($value) && ref($value) eq 'ARRAY' ? @{$value} : $value) : ();
Branch: 4 branches
BranchTrueFalseTotal
defined $value ? : 55 4 59
ref $value && ref $value eq 'ARRAY' ? : 40 15 55
defined $value ? : 0 0 0
ref $value && ref $value eq 'ARRAY' ? : 0 0 0
Condition33%2/6
ref $value and ref $value eq "ARRAY"
!ll&&!rl&&r
15040
ref $value and ref $value eq "ARRAY"
!ll&&!rl&&r
000
MC/DC50%1/2
ref $value and ref $value eq "ARRAY"
ref $value ref $value eq "ARRAY"
MC/DC0%0/2
ref $value and ref $value eq "ARRAY"
ref $value ref $value eq "ARRAY"
Truth table66%2/3
A and B
A= ref $valueB= ref $value eq "ARRAY"
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= ref $valueB= ref $value eq "ARRAY"
ABresult
0X0
100
111
446 } else {
447 0 for ($value,@other) {
448 0 ▶ push(@values,$_) if defined($_);
Branch: 2 branches
BranchTrueFalseTotal
if defined $_ 10 8 18
if defined $_ 0 0 0
449 }
450 }
451 # If values is provided, then we set it.
452 0 ▶ if (@values or defined $value) {
Branch: 2 branches
BranchTrueFalseTotal
if (@values or defined $value) 65 12 77
if (@values or defined $value) 0 0 0
Condition33%2/6
@values or defined $value
l!l&&r!l&&!r
65012
@values or defined $value
l!l&&r!l&&!r
000
MC/DC50%1/2
@values or defined $value
@values defined $value
MC/DC0%0/2
@values or defined $value
@values defined $value
Truth table66%2/3
A or B
A= @valuesB= defined $value
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= @valuesB= defined $value
ABresult
1X1
011
000
453 0 $self->add_parameter($name);
454 0 $self->{param}{$name}=[@values];
455 }
456 } else {
457 0 $name = $p[0];
458 }
459  
460 0 ▶ return unless defined($name) && $self->{param}{$name};
Branch: 2 branches
BranchTrueFalseTotal
unless defined $name and $self->{"param"}{$name} 4152 4001 8153
unless defined $name and $self->{"param"}{$name} 0 0 0
Condition50%3/6
defined $name and $self->{"param"}{$name}
!ll&&!rl&&r
441484001
defined $name and $self->{"param"}{$name}
!ll&&!rl&&r
000
MC/DC100%2/2
defined $name and $self->{"param"}{$name}
defined $name $self->{"param"}{$name}
MC/DC0%0/2
defined $name and $self->{"param"}{$name}
defined $name $self->{"param"}{$name}
Truth table100%3/3
A and B
A= defined $nameB= $self->{"param"}{$name}
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= defined $nameB= $self->{"param"}{$name}
ABresult
0X0
100
111
461  
462 0 my @result = @{$self->{param}{$name}};
463  
464 0 ▶ if ($PARAM_UTF8 && $name ne 'PUTDATA' && $name ne 'POSTDATA' && $name ne 'PATCHDATA') {
Branch: 2 branches
BranchTrueFalseTotal
if ($PARAM_UTF8 and $name ne "PUTDATA" and $name ne "POSTDATA" and $name ne "PATCHDATA") 5 3996 4001
if ($PARAM_UTF8 and $name ne "PUTDATA" and $name ne "POSTDATA" and $name ne "PATCHDATA") 0 0 0
Condition33%6/18
$PARAM_UTF8 and $name ne "PUTDATA" and $name ne "POSTDATA" and $name ne "PATCHDATA"
!ll&&!rl&&r
399605
$PARAM_UTF8 and $name ne "PUTDATA" and $name ne "POSTDATA"
!ll&&!rl&&r
399605
$PARAM_UTF8 and $name ne "PUTDATA"
!ll&&!rl&&r
399605
$PARAM_UTF8 and $name ne "PUTDATA" and $name ne "POSTDATA" and $name ne "PATCHDATA"
!ll&&!rl&&r
000
$PARAM_UTF8 and $name ne "PUTDATA" and $name ne "POSTDATA"
!ll&&!rl&&r
000
$PARAM_UTF8 and $name ne "PUTDATA"
!ll&&!rl&&r
000
MC/DC25%1/4
$PARAM_UTF8 and $name ne "PUTDATA" and $name ne "POSTDATA" and $name ne "PATCHDATA"
$PARAM_UTF8 $name ne "PUTDATA" $name ne "POSTDATA" $name ne "PATCHDATA"
MC/DC0%0/4
$PARAM_UTF8 and $name ne "PUTDATA" and $name ne "POSTDATA" and $name ne "PATCHDATA"
$PARAM_UTF8 $name ne "PUTDATA" $name ne "POSTDATA" $name ne "PATCHDATA"
Truth table40%2/5
A and B and C and D
A= $PARAM_UTF8B= $name ne "PUTDATA"C= $name ne "POSTDATA"D= $name ne "PATCHDATA"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
Truth table0%0/5
A and B and C and D
A= $PARAM_UTF8B= $name ne "PUTDATA"C= $name ne "POSTDATA"D= $name ne "PATCHDATA"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
465 0 ▶ eval "require Encode; 1;" unless Encode->can('decode'); # bring in these functions
Branch: 2 branches
BranchTrueFalseTotal
unless "Encode"->can("decode") 0 5 5
unless "Encode"->can("decode") 0 0 0
466 0 ▶ @result = map {ref $_ ? $_ : $self->_decode_utf8($_) } @result;
Branch: 2 branches
BranchTrueFalseTotal
ref $_ ? : 0 5 5
ref $_ ? : 0 0 0
467 }
468  
469 0 ▶ return wantarray ? @result : $result[0];
Branch: 2 branches
BranchTrueFalseTotal
wantarray ? : 322 3679 4001
wantarray ? : 0 0 0
470 }
471  
472 5 ▶sub _decode_utf8 {
Subroutine _decode_utf8: called CC=2 SCAR=9.2
473 0 ▶ my ($self, $val) = @_;
Subroutine _decode_utf8: not called CC=2 SCAR=9.2
474  
475 0 ▶ if (Encode::is_utf8($val)) {
Branch: 2 branches
BranchTrueFalseTotal
if (&Encode::is_utf8($val)) { } 2 3 5
if (&Encode::is_utf8($val)) { } 0 0 0
476 0 return $val;
477 }
478 else {
479 0 return Encode::decode(utf8 => $val);
480 }
481 }
482  
483 25688 ▶sub self_or_default {
Subroutine self_or_default: called CC=9 SCAR=30.2
Pod undocumented
484 0 ▶ return @_ if defined($_[0]) && (!ref($_[0])) &&($_[0] eq 'CGI');
Subroutine self_or_default: not called CC=9 SCAR=30.2
Pod undocumented
Branch: 2 branches
BranchTrueFalseTotal
if defined $_[0] and not ref $_[0] and $_[0] eq "CGI" 1 25687 25688
if defined $_[0] and not ref $_[0] and $_[0] eq "CGI" 0 0 0
Condition50%6/12
defined $_[0] and not ref $_[0] and $_[0] eq "CGI"
!ll&&!rl&&r
255221651
defined $_[0] and not ref $_[0]
!ll&&!rl&&r
20725315166
defined $_[0] and not ref $_[0] and $_[0] eq "CGI"
!ll&&!rl&&r
000
defined $_[0] and not ref $_[0]
!ll&&!rl&&r
000
MC/DC100%3/3
defined $_[0] and not ref $_[0] and $_[0] eq "CGI"
defined $_[0] not ref $_[0] $_[0] eq "CGI"
MC/DC0%0/3
defined $_[0] and not ref $_[0] and $_[0] eq "CGI"
defined $_[0] not ref $_[0] $_[0] eq "CGI"
Truth table100%4/4
A and not(B) and C
A= defined $_[0]B= not ref $_[0]C= $_[0] eq "CGI"
ABCresult
0XX0
10X0
1100
1111
Truth table0%0/4
A and not(B) and C
A= defined $_[0]B= not ref $_[0]C= $_[0] eq "CGI"
ABCresult
0XX0
10X0
1100
1111
485 0 ▶ unless (defined($_[0]) &&
Branch: 2 branches
BranchTrueFalseTotal
unless (defined $_[0] and ref $_[0] eq "CGI" || UNIVERSAL::isa($_[0], "CGI")) 440 25247 25687
unless (defined $_[0] and ref $_[0] eq "CGI" || UNIVERSAL::isa($_[0], "CGI")) 0 0 0
Condition50%6/12
defined $_[0] and ref $_[0] eq "CGI" || UNIVERSAL::isa($_[0], "CGI")
!ll&&!rl&&r
20723325247
ref $_[0] eq "CGI" or UNIVERSAL::isa($_[0], "CGI")
l!l&&r!l&&!r
2519552233
defined $_[0] and ref $_[0] eq "CGI" || UNIVERSAL::isa($_[0], "CGI")
!ll&&!rl&&r
000
ref $_[0] eq "CGI" or UNIVERSAL::isa($_[0], "CGI")
l!l&&r!l&&!r
000
MC/DC100%3/3
defined $_[0] and ref $_[0] eq "CGI" || UNIVERSAL::isa($_[0], "CGI")
defined $_[0] ref $_[0] eq "CGI" UNIVERSAL::isa($_[0], "CGI")
MC/DC0%0/3
defined $_[0] and ref $_[0] eq "CGI" || UNIVERSAL::isa($_[0], "CGI")
defined $_[0] ref $_[0] eq "CGI" UNIVERSAL::isa($_[0], "CGI")
Truth table100%4/4
A and B or C
A= defined $_[0]B= ref $_[0] eq "CGI"C= UNIVERSAL::isa($_[0], "CGI")
ABCresult
0XX0
1000
11X1
1011
Truth table0%0/4
A and B or C
A= defined $_[0]B= ref $_[0] eq "CGI"C= UNIVERSAL::isa($_[0], "CGI")
ABCresult
0XX0
1000
11X1
1011
486 (ref($_[0]) eq 'CGI' || UNIVERSAL::isa($_[0],'CGI')) # slightly optimized for common case
487 ) {
488 0 ▶ $Q = $CGI::DefaultClass->new unless defined($Q);
Branch: 2 branches
BranchTrueFalseTotal
unless defined $Q 38 402 440
unless defined $Q 0 0 0
489 0 unshift(@_,$Q);
490 }
491 0 ▶ return wantarray ? @_ : $Q;
Branch: 2 branches
BranchTrueFalseTotal
wantarray ? : 25687 0 25687
wantarray ? : 0 0 0
492 }
493  
494 253 ▶sub self_or_CGI {
Subroutine self_or_CGI: called CC=4 SCAR=19.7
Pod undocumented
495 0 ▶ local $^W=0; # prevent a warning
Subroutine self_or_CGI: not called CC=4 SCAR=19.7
Pod undocumented
496 0 ▶ if (defined($_[0]) &&
Branch: 2 branches
BranchTrueFalseTotal
if (defined $_[0] and substr(ref $_[0], 0, 3) eq 'CGI' || UNIVERSAL::isa($_[0], 'CGI')) { } 236 17 253
if (defined $_[0] and substr(ref $_[0], 0, 3) eq 'CGI' || UNIVERSAL::isa($_[0], 'CGI')) { } 0 0 0
Condition33%4/12
defined $_[0] and substr(ref $_[0], 0, 3) eq "CGI" || UNIVERSAL::isa($_[0], "CGI")
!ll&&!rl&&r
017236
substr(ref $_[0], 0, 3) eq "CGI" or UNIVERSAL::isa($_[0], "CGI")
l!l&&r!l&&!r
236017
defined $_[0] and substr(ref $_[0], 0, 3) eq "CGI" || UNIVERSAL::isa($_[0], "CGI")
!ll&&!rl&&r
000
substr(ref $_[0], 0, 3) eq "CGI" or UNIVERSAL::isa($_[0], "CGI")
l!l&&r!l&&!r
000
MC/DC33%1/3
defined $_[0] and substr(ref $_[0], 0, 3) eq "CGI" || UNIVERSAL::isa($_[0], "CGI")
defined $_[0] substr(ref $_[0], 0, 3) eq "CGI" UNIVERSAL::isa($_[0], "CGI")
MC/DC0%0/3
defined $_[0] and substr(ref $_[0], 0, 3) eq "CGI" || UNIVERSAL::isa($_[0], "CGI")
defined $_[0] substr(ref $_[0], 0, 3) eq "CGI" UNIVERSAL::isa($_[0], "CGI")
Truth table50%2/4
A and B or C
A= defined $_[0]B= substr(ref $_[0], 0, 3) eq "CGI"C= UNIVERSAL::isa($_[0], "CGI")
ABCresult
0XX0
1000
11X1
1011
Truth table0%0/4
A and B or C
A= defined $_[0]B= substr(ref $_[0], 0, 3) eq "CGI"C= UNIVERSAL::isa($_[0], "CGI")
ABCresult
0XX0
1000
11X1
1011
497 (substr(ref($_[0]),0,3) eq 'CGI'
498 || UNIVERSAL::isa($_[0],'CGI'))) {
499 0 return @_;
500 } else {
501 0 return ($DefaultClass,@_);
502 }
503 }
504  
505 ########################################
506 # THESE METHODS ARE MORE OR LESS PRIVATE
507 # GO TO THE __DATA__ SECTION TO SEE MORE
508 # PUBLIC METHODS
509 ########################################
510  
511 # Initialize the query object from the environment.
512 # If a parameter list is found, this object will be set
513 # to a hash in which parameter names are keys
514 # and the values are stored as lists
515 # If a keyword list is found, this method creates a bogus
516 # parameter list with the single parameter 'keywords'.
517  
518 2037 ▶sub init {
Subroutine init: called CC=84 SCAR=71.3
Pod undocumented
519 0 ▶ my $self = shift;
Subroutine init: not called CC=84 SCAR=71.3
Pod undocumented
520 0 my($query_string,$meth,$content_length,$fh,@lines) = ('','','','');
521  
522 0 my $is_xforms;
523 my $too_large;
524  
525 0 my $initializer = shift; # for backward compatibility
526 0 local($/) = "\n";
527  
528 # set autoescaping on by default
529 0 $self->{'escape'} = 1;
530  
531 # if we get called more than once, we want to initialize
532 # ourselves from the original query (which may be gone
533 # if it was read from STDIN originally.)
534 0 ▶ if (@QUERY_PARAM && !defined($initializer)) {
Branch: 2 branches
BranchTrueFalseTotal
if (@QUERY_PARAM and not defined $initializer) 8 2029 2037
if (@QUERY_PARAM and not defined $initializer) 0 0 0
Condition50%3/6
@QUERY_PARAM and not defined $initializer
!ll&&!rl&&r
202548
@QUERY_PARAM and not defined $initializer
!ll&&!rl&&r
000
MC/DC100%2/2
@QUERY_PARAM and not defined $initializer
@QUERY_PARAM not defined $initializer
MC/DC0%0/2
@QUERY_PARAM and not defined $initializer
@QUERY_PARAM not defined $initializer
Truth table100%3/3
A and not(B)
A= @QUERY_PARAMB= not defined $initializer
ABresult
0X0
100
111
Truth table0%0/3
A and not(B)
A= @QUERY_PARAMB= not defined $initializer
ABresult
0X0
100
111
535 0 for my $name (@QUERY_PARAM) {
536 0 my $val = $QUERY_PARAM{$name}; # always an arrayref;
537 0 $self->param('-name'=>$name,'-value'=> $val);
538 0 ▶ if (defined $val and ref $val eq 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $val and ref $val eq "ARRAY") 21 0 21
if (defined $val and ref $val eq "ARRAY") 0 0 0
Condition16%1/6
defined $val and ref $val eq "ARRAY"
!ll&&!rl&&r
0021
defined $val and ref $val eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $val and ref $val eq "ARRAY"
defined $val ref $val eq "ARRAY"
MC/DC0%0/2
defined $val and ref $val eq "ARRAY"
defined $val ref $val eq "ARRAY"
Truth table33%1/3
A and B
A= defined $valB= ref $val eq "ARRAY"
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= defined $valB= ref $val eq "ARRAY"
ABresult
0X0
100
111
539 0 ▶ for my $fh (grep {defined($_) && ref($_) && defined(fileno($_))} @$val) {
Condition33%4/12
defined $_ && ref $_ && defined fileno $_
!ll&&!rl&&r
6020
defined $_ and ref $_
!ll&&!rl&&r
0620
defined $_ && ref $_ && defined fileno $_
!ll&&!rl&&r
000
defined $_ and ref $_
!ll&&!rl&&r
000
MC/DC33%1/3
defined $_ && ref $_ && defined fileno $_
defined $_ ref $_ defined fileno $_
MC/DC0%0/3
defined $_ && ref $_ && defined fileno $_
defined $_ ref $_ defined fileno $_
Truth table50%2/4
A and B && C
A= defined $_B= ref $_C= defined fileno $_
ABCresult
0XX0
10X0
1100
1111
Truth table0%0/4
A and B && C
A= defined $_B= ref $_C= defined fileno $_
ABCresult
0XX0
10X0
1100
1111
540 0 seek($fh,0,0); # reset the filehandle.
541 }
542  
543 }
544 }
545 0 $self->charset($QUERY_CHARSET);
546 # so an error parsing the request (e.g. a malformed or too large
547 # body) is seen by every object, not just the first
548 0 ▶ $self->cgi_error($QUERY_CGI_ERROR) if defined $QUERY_CGI_ERROR;
Branch: 2 branches
BranchTrueFalseTotal
if defined $QUERY_CGI_ERROR 1 7 8
if defined $QUERY_CGI_ERROR 0 0 0
549 0 $self->{'.fieldnames'} = {%QUERY_FIELDNAMES};
550 0 $self->{'.tmpfiles'} = {%QUERY_TMPFILES};
551 0 return;
552 }
553  
554 0 ▶ $meth=$ENV{'REQUEST_METHOD'} if defined($ENV{'REQUEST_METHOD'});
Branch: 2 branches
BranchTrueFalseTotal
if defined $ENV{"REQUEST_METHOD"} 1914 115 2029
if defined $ENV{"REQUEST_METHOD"} 0 0 0
555 0 ▶ $content_length = defined($ENV{'CONTENT_LENGTH'}) ? $ENV{'CONTENT_LENGTH'} : 0;
Branch: 2 branches
BranchTrueFalseTotal
defined $ENV{'CONTENT_LENGTH'} ? : 1823 206 2029
defined $ENV{'CONTENT_LENGTH'} ? : 0 0 0
556  
557 0 ▶ $fh = to_filehandle($initializer) if $initializer;
Branch: 2 branches
BranchTrueFalseTotal
if $initializer 24 2005 2029
if $initializer 0 0 0
558  
559 # set charset to the safe ISO-8859-1
560 0 $self->charset('ISO-8859-1');
561  
562 METHOD: {
563  
564 # avoid unreasonably large postings
565 0 ▶ if (($POST_MAX > 0) && ($content_length > $POST_MAX)) {
Branch: 2 branches
BranchTrueFalseTotal
if ($POST_MAX > 0 and $content_length > $POST_MAX) 2 2027 2029
if ($POST_MAX > 0 and $content_length > $POST_MAX) 0 0 0
Condition50%3/6
$POST_MAX > 0 and $content_length > $POST_MAX
!ll&&!rl&&r
120262
$POST_MAX > 0 and $content_length > $POST_MAX
!ll&&!rl&&r
000
MC/DC100%2/2
$POST_MAX > 0 and $content_length > $POST_MAX
$POST_MAX > 0 $content_length > $POST_MAX
MC/DC0%0/2
$POST_MAX > 0 and $content_length > $POST_MAX
$POST_MAX > 0 $content_length > $POST_MAX
Truth table100%3/3
A and B
A= $POST_MAX > 0B= $content_length > $POST_MAX
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $POST_MAX > 0B= $content_length > $POST_MAX
ABresult
0X0
100
111
566 #discard the post, unread
567 0 $self->cgi_error("413 Request entity too large");
568 0 $too_large = 1;
569 0 last METHOD;
570 }
571  
572 # Process multipart postings, but only if the initializer is
573 # not defined.
574 0 ▶ if ($meth eq 'POST'
Branch: 2 branches
BranchTrueFalseTotal
if ($meth eq "POST" and defined $ENV{"CONTENT_TYPE"} and $ENV{"CONTENT_TYPE"} =~ m[^multipart/form-data] and not defined $initializer) 1758 269 2027
if ($meth eq "POST" and defined $ENV{"CONTENT_TYPE"} and $ENV{"CONTENT_TYPE"} =~ m[^multipart/form-data] and not defined $initializer) 0 0 0
Condition50%9/18
$meth eq "POST" and defined $ENV{"CONTENT_TYPE"} and $ENV{"CONTENT_TYPE"} =~ m[^multipart/form-data] and not defined $initializer
!ll&&!rl&&r
26811758
$meth eq "POST" and defined $ENV{"CONTENT_TYPE"} and $ENV{"CONTENT_TYPE"} =~ m[^multipart/form-data]
!ll&&!rl&&r
228401759
$meth eq "POST" and defined $ENV{"CONTENT_TYPE"}
!ll&&!rl&&r
22171799
$meth eq "POST" and defined $ENV{"CONTENT_TYPE"} and $ENV{"CONTENT_TYPE"} =~ m[^multipart/form-data] and not defined $initializer
!ll&&!rl&&r
000
$meth eq "POST" and defined $ENV{"CONTENT_TYPE"} and $ENV{"CONTENT_TYPE"} =~ m[^multipart/form-data]
!ll&&!rl&&r
000
$meth eq "POST" and defined $ENV{"CONTENT_TYPE"}
!ll&&!rl&&r
000
MC/DC100%4/4
$meth eq "POST" and defined $ENV{"CONTENT_TYPE"} and $ENV{"CONTENT_TYPE"} =~ m[^multipart/form-data] and not defined $initializer
$meth eq "POST" defined $ENV{"CONTENT_TYPE"} $ENV{"CONTENT_TYPE"} =~ m[^multipart/form-data] not defined $initializer
MC/DC0%0/4
$meth eq "POST" and defined $ENV{"CONTENT_TYPE"} and $ENV{"CONTENT_TYPE"} =~ m[^multipart/form-data] and not defined $initializer
$meth eq "POST" defined $ENV{"CONTENT_TYPE"} $ENV{"CONTENT_TYPE"} =~ m[^multipart/form-data] not defined $initializer
Truth table100%5/5
A and B and C and not(D)
A= $meth eq "POST"B= defined $ENV{"CONTENT_TYPE"}C= $ENV{"CONTENT_TYPE"} =~ m[^multipart/form-data]D= not defined $initializer
ABCDresult
0XXX0
10XX0
110X0
11100
11111
Truth table0%0/5
A and B and C and not(D)
A= $meth eq "POST"B= defined $ENV{"CONTENT_TYPE"}C= $ENV{"CONTENT_TYPE"} =~ m[^multipart/form-data]D= not defined $initializer
ABCDresult
0XXX0
10XX0
110X0
11100
11111
575 && defined($ENV{'CONTENT_TYPE'})
576 && $ENV{'CONTENT_TYPE'}=~m|^multipart/form-data|
577 && !defined($initializer)
578 ) {
579 0 my($boundary) = $ENV{'CONTENT_TYPE'} =~ /boundary=\"?([^\";,]+)\"?/;
580 0 ▶ unless ( $self->_within_request_limits(
Branch: 2 branches
BranchTrueFalseTotal
unless ($self->_within_request_limits(sub { $self->read_multipart($boundary, $content_length); } )) 5 1738 1743
unless ($self->_within_request_limits(sub { $self->read_multipart($boundary, $content_length); } )) 0 0 0
581 1758 ▶ sub { $self->read_multipart($boundary,$content_length) }
Subroutine __ANON__: called CC=1 SCAR=0.0
582 ) ) {
583 0 $too_large = 1;
584 0 last METHOD;
585 }
586 0 ▶ if ($APPEND_QUERY_STRING) {
Branch: 2 branches
BranchTrueFalseTotal
if ($APPEND_QUERY_STRING) 0 1738 1738
if ($APPEND_QUERY_STRING) 0 0 0
587 # Some people want to have their cake and eat it too!
588 # Set $APPEND_QUERY_STRING = 1 to have the contents of the query string
589 # APPENDED to the POST data.
590 0 ▶ $query_string .= (length($query_string) ? '&' : '') . $ENV{'QUERY_STRING'} if defined $ENV{'QUERY_STRING'};
Branch: 4 branches
BranchTrueFalseTotal
if defined $ENV{"QUERY_STRING"} 0 0 0
length $query_string ? : 0 0 0
if defined $ENV{"QUERY_STRING"} 0 0 0
length $query_string ? : 0 0 0
591 }
592 0 last METHOD;
593 }
594  
595 # Process XForms postings. We know that we have XForms in the
596 # following cases:
597 # method eq 'POST' && content-type eq 'application/xml'
598 # method eq 'POST' && content-type =~ /multipart\/related.+start=/
599 # There are more cases, actually, but for now, we don't support other
600 # methods for XForm posts.
601 # In a XForm POST, the QUERY_STRING is parsed normally.
602 # If the content-type is 'application/xml', we just set the param
603 # XForms:Model (referring to the xml syntax) param containing the
604 # unparsed XML data.
605 # In the case of multipart/related we set XForms:Model as above, but
606 # the other parts are available as uploads with the Content-ID as the
607 # the key.
608 # See the URL below for XForms specs on this issue.
609 # http://www.w3.org/TR/2006/REC-xforms-20060314/slice11.html#submit-options
610 0 ▶ if ($meth eq 'POST' && defined($ENV{'CONTENT_TYPE'})) {
Branch: 2 branches
BranchTrueFalseTotal
if ($meth eq "POST" and defined $ENV{"CONTENT_TYPE"}) 41 228 269
if ($meth eq "POST" and defined $ENV{"CONTENT_TYPE"}) 0 0 0
Condition50%3/6
$meth eq "POST" and defined $ENV{"CONTENT_TYPE"}
!ll&&!rl&&r
221741
$meth eq "POST" and defined $ENV{"CONTENT_TYPE"}
!ll&&!rl&&r
000
MC/DC100%2/2
$meth eq "POST" and defined $ENV{"CONTENT_TYPE"}
$meth eq "POST" defined $ENV{"CONTENT_TYPE"}
MC/DC0%0/2
$meth eq "POST" and defined $ENV{"CONTENT_TYPE"}
$meth eq "POST" defined $ENV{"CONTENT_TYPE"}
Truth table100%3/3
A and B
A= $meth eq "POST"B= defined $ENV{"CONTENT_TYPE"}
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $meth eq "POST"B= defined $ENV{"CONTENT_TYPE"}
ABresult
0X0
100
111
611 0 ▶ if ($ENV{'CONTENT_TYPE'} eq 'application/xml') {
Branch: 4 branches
BranchTrueFalseTotal
if ($ENV{'CONTENT_TYPE'} eq 'application/xml') { } 2 39 41
elsif ($ENV{'CONTENT_TYPE'} =~ m[^multipart/related\b] and my($boundary) = $ENV{'CONTENT_TYPE'} =~ /[;\s]boundary=\"?([^\";,]+)\"?/ and my($start) = $ENV{'CONTENT_TYPE'} =~ /[;\s]start=\"?\<?([^\"\>]+)\>?\"?/) { } 17 43 60
if ($ENV{'CONTENT_TYPE'} eq 'application/xml') { } 0 0 0
elsif ($ENV{'CONTENT_TYPE'} =~ m[^multipart/related\b] and my($boundary) = $ENV{'CONTENT_TYPE'} =~ /[;\s]boundary=\"?([^\";,]+)\"?/ and my($start) = $ENV{'CONTENT_TYPE'} =~ /[;\s]start=\"?\<?([^\"\>]+)\>?\"?/) { } 0 0 0
612 0 my($param) = 'XForms:Model';
613 0 my($value) = '';
614 0 $self->add_parameter($param);
615 0 ▶ $self->read_from_client(\$value,$content_length,0)
Branch: 2 branches
BranchTrueFalseTotal
if $content_length > 0 2 0 2
if $content_length > 0 0 0 0
616 if $content_length > 0;
617 0 push (@{$self->{param}{$param}},$value);
618 0 $is_xforms = 1;
619 ▶ } elsif ($ENV{'CONTENT_TYPE'} =~ m|^multipart/related\b|
Condition50%6/12
$ENV{"CONTENT_TYPE"} =~ m[^multipart/related\b] and my($boundary) = $ENV{"CONTENT_TYPE"} =~ /[;\s]boundary=\"?([^\";,]+)\"?/ and my($start) = $ENV{"CONTENT_TYPE"} =~ /[;\s]start=\"?\<?([^\"\>]+)\>?\"?/
!ll&&!rl&&r
21117
$ENV{"CONTENT_TYPE"} =~ m[^multipart/related\b] and my($boundary) = $ENV{"CONTENT_TYPE"} =~ /[;\s]boundary=\"?([^\";,]+)\"?/
!ll&&!rl&&r
20118
$ENV{"CONTENT_TYPE"} =~ m[^multipart/related\b] and my($boundary) = $ENV{"CONTENT_TYPE"} =~ /[;\s]boundary=\"?([^\";,]+)\"?/ and my($start) = $ENV{"CONTENT_TYPE"} =~ /[;\s]start=\"?\<?([^\"\>]+)\>?\"?/
!ll&&!rl&&r
000
$ENV{"CONTENT_TYPE"} =~ m[^multipart/related\b] and my($boundary) = $ENV{"CONTENT_TYPE"} =~ /[;\s]boundary=\"?([^\";,]+)\"?/
!ll&&!rl&&r
000
MC/DC100%3/3
$ENV{"CONTENT_TYPE"} =~ m[^multipart/related\b] and my($boundary) = $ENV{"CONTENT_TYPE"} =~ /[;\s]boundary=\"?([^\";,]+)\"?/ and my($start) = $ENV{"CONTENT_TYPE"} =~ /[;\s]start=\"?\<?([^\"\>]+)\>?\"?/
$ENV{"CONTENT_TYPE"} =~ m[^multipart/related\b] my($boundary) = $ENV{"CONTENT_TYPE"} =~ /[;\s]boundary=\"?([^\";,]+)\"?/ my($start) = $ENV{"CONTENT_TYPE"} =~ /[;\s]start=\"?\<?([^\"\>]+)\>?\"?/
MC/DC0%0/3
$ENV{"CONTENT_TYPE"} =~ m[^multipart/related\b] and my($boundary) = $ENV{"CONTENT_TYPE"} =~ /[;\s]boundary=\"?([^\";,]+)\"?/ and my($start) = $ENV{"CONTENT_TYPE"} =~ /[;\s]start=\"?\<?([^\"\>]+)\>?\"?/
$ENV{"CONTENT_TYPE"} =~ m[^multipart/related\b] my($boundary) = $ENV{"CONTENT_TYPE"} =~ /[;\s]boundary=\"?([^\";,]+)\"?/ my($start) = $ENV{"CONTENT_TYPE"} =~ /[;\s]start=\"?\<?([^\"\>]+)\>?\"?/
Truth table100%4/4
A and B and C
A= $ENV{"CONTENT_TYPE"} =~ m[^multipart/related\b]B= my($boundary) = $ENV{"CONTENT_TYPE"} =~ /[;\s]boundary=\"?([^\";,]+)\"?/C= my($start) = $ENV{"CONTENT_TYPE"} =~ /[;\s]start=\"?\<?([^\"\>]+)\>?\"?/
ABCresult
0XX0
10X0
1100
1111
Truth table0%0/4
A and B and C
A= $ENV{"CONTENT_TYPE"} =~ m[^multipart/related\b]B= my($boundary) = $ENV{"CONTENT_TYPE"} =~ /[;\s]boundary=\"?([^\";,]+)\"?/C= my($start) = $ENV{"CONTENT_TYPE"} =~ /[;\s]start=\"?\<?([^\"\>]+)\>?\"?/
ABCresult
0XX0
10X0
1100
1111
620 # separate (linear) matches for each parameter - a single
621 # pattern with .+ between them backtracks in cubic time on
622 # a crafted Content-Type, and parameters can be in any order
623 and my ($boundary) = $ENV{'CONTENT_TYPE'} =~ /[;\s]boundary=\"?([^\";,]+)\"?/
624 and my ($start) = $ENV{'CONTENT_TYPE'} =~ /[;\s]start=\"?\<?([^\"\>]+)\>?\"?/
625 ) {
626 0 my($param) = 'XForms:Model';
627 0 $self->add_parameter($param);
628 0 my($value);
629 0 ▶ unless ( $self->_within_request_limits(
Branch: 2 branches
BranchTrueFalseTotal
unless ($self->_within_request_limits(sub { $value = $self->read_multipart_related($start, $boundary, $content_length, 0); } )) 3 13 16
unless ($self->_within_request_limits(sub { $value = $self->read_multipart_related($start, $boundary, $content_length, 0); } )) 0 0 0
630 17 ▶ sub { $value = $self->read_multipart_related($start,$boundary,$content_length,0) }
Subroutine __ANON__: called CC=1 SCAR=0.0
631 ) ) {
632 0 $too_large = 1;
633 0 last METHOD;
634 }
635 0 push (@{$self->{param}{$param}},$value);
636 0 $query_string = $self->_get_query_string_from_env;
637 0 $is_xforms = 1;
638 }
639 }
640  
641  
642 # If initializer is defined, then read parameters
643 # from it.
644 0 ▶ if (!$is_xforms && defined($initializer)) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $is_xforms and defined $initializer) 36 229 265
if (not $is_xforms and defined $initializer) 0 0 0
Condition50%3/6
not $is_xforms and defined $initializer
!ll&&!rl&&r
1521436
not $is_xforms and defined $initializer
!ll&&!rl&&r
000
MC/DC100%2/2
not $is_xforms and defined $initializer
not $is_xforms defined $initializer
MC/DC0%0/2
not $is_xforms and defined $initializer
not $is_xforms defined $initializer
Truth table100%3/3
not(A) and B
A= not $is_xformsB= defined $initializer
ABresult
0X0
100
111
Truth table0%0/3
not(A) and B
A= not $is_xformsB= defined $initializer
ABresult
0X0
100
111
645 0 ▶ if (UNIVERSAL::isa($initializer,'CGI')) {
Branch: 2 branches
BranchTrueFalseTotal
if (UNIVERSAL::isa($initializer, "CGI")) 0 36 36
if (UNIVERSAL::isa($initializer, "CGI")) 0 0 0
646 0 $query_string = $initializer->query_string;
647 0 last METHOD;
648 }
649 0 ▶ if (ref($initializer) && ref($initializer) eq 'HASH') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $initializer and ref $initializer eq "HASH") 9 27 36
if (ref $initializer and ref $initializer eq "HASH") 0 0 0
Condition50%3/6
ref $initializer and ref $initializer eq "HASH"
!ll&&!rl&&r
2349
ref $initializer and ref $initializer eq "HASH"
!ll&&!rl&&r
000
MC/DC100%2/2
ref $initializer and ref $initializer eq "HASH"
ref $initializer ref $initializer eq "HASH"
MC/DC0%0/2
ref $initializer and ref $initializer eq "HASH"
ref $initializer ref $initializer eq "HASH"
Truth table100%3/3
A and B
A= ref $initializerB= ref $initializer eq "HASH"
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= ref $initializerB= ref $initializer eq "HASH"
ABresult
0X0
100
111
650 0 for (sort keys %$initializer) {
651 0 $self->param('-name'=>$_,'-value'=>$initializer->{$_});
652 }
653 0 last METHOD;
654 }
655  
656 0 ▶ if (defined($fh) && ($fh ne '')) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $fh and $fh ne "") 4 23 27
if (defined $fh and $fh ne "") 0 0 0
Condition50%3/6
defined $fh and $fh ne ""
!ll&&!rl&&r
11124
defined $fh and $fh ne ""
!ll&&!rl&&r
000
MC/DC100%2/2
defined $fh and $fh ne ""
defined $fh $fh ne ""
MC/DC0%0/2
defined $fh and $fh ne ""
defined $fh $fh ne ""
Truth table100%3/3
A and B
A= defined $fhB= $fh ne ""
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= defined $fhB= $fh ne ""
ABresult
0X0
100
111
657 0 ▶ while (my $line = <$fh>) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined(my $line = readline $fh)) 9 3 12
if (defined(my $line = readline $fh)) 0 0 0
658 0 chomp $line;
659 0 ▶ last if $line =~ /^=$/;
Branch: 2 branches
BranchTrueFalseTotal
if $line =~ /^=$/ 1 8 9
if $line =~ /^=$/ 0 0 0
660 0 push(@lines,$line);
661 }
662 # massage back into standard format
663 0 ▶ if ("@lines" =~ /=/) {
Branch: 2 branches
BranchTrueFalseTotal
if (join($", @lines) =~ /=/) { } 4 0 4
if (join($", @lines) =~ /=/) { } 0 0 0
664 0 $query_string=join("&",@lines);
665 } else {
666 0 $query_string=join("+",@lines);
667 }
668 0 last METHOD;
669 }
670  
671 # last chance -- treat it as a string
672 0 ▶ $initializer = $$initializer if ref($initializer) eq 'SCALAR';
Branch: 2 branches
BranchTrueFalseTotal
if ref $initializer eq "SCALAR" 0 23 23
if ref $initializer eq "SCALAR" 0 0 0
673 0 $query_string = $initializer;
674  
675 0 last METHOD;
676 }
677  
678 # If method is GET, HEAD or DELETE, fetch the query from
679 # the environment.
680 0 ▶ if ($is_xforms || $meth=~/^(GET|HEAD|DELETE)$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($is_xforms or $meth =~ /^(GET|HEAD|DELETE)$/) 75 154 229
if ($is_xforms or $meth =~ /^(GET|HEAD|DELETE)$/) 0 0 0
Condition50%3/6
$is_xforms or $meth =~ /^(GET|HEAD|DELETE)$/
l!l&&r!l&&!r
1560154
$is_xforms or $meth =~ /^(GET|HEAD|DELETE)$/
l!l&&r!l&&!r
000
MC/DC100%2/2
$is_xforms or $meth =~ /^(GET|HEAD|DELETE)$/
$is_xforms $meth =~ /^(GET|HEAD|DELETE)$/
MC/DC0%0/2
$is_xforms or $meth =~ /^(GET|HEAD|DELETE)$/
$is_xforms $meth =~ /^(GET|HEAD|DELETE)$/
Truth table100%3/3
A or B
A= $is_xformsB= $meth =~ /^(GET|HEAD|DELETE)$/
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= $is_xformsB= $meth =~ /^(GET|HEAD|DELETE)$/
ABresult
1X1
011
000
681 0 $query_string = $self->_get_query_string_from_env;
682 0 ▶ $self->param($meth . 'DATA', $self->param('XForms:Model'))
Branch: 2 branches
BranchTrueFalseTotal
if $is_xforms 15 60 75
if $is_xforms 0 0 0
683 if $is_xforms;
684 0 last METHOD;
685 }
686  
687 0 ▶ if ($meth eq 'POST' || $meth eq 'PUT' || $meth eq 'PATCH') {
Branch: 2 branches
BranchTrueFalseTotal
if ($meth eq "POST" or $meth eq "PUT" or $meth eq "PATCH") 49 105 154
if ($meth eq "POST" or $meth eq "PUT" or $meth eq "PATCH") 0 0 0
Condition50%6/12
$meth eq "POST" or $meth eq "PUT" or $meth eq "PATCH"
l!l&&r!l&&!r
418105
$meth eq "POST" or $meth eq "PUT"
l!l&&r!l&&!r
2714113
$meth eq "POST" or $meth eq "PUT" or $meth eq "PATCH"
l!l&&r!l&&!r
000
$meth eq "POST" or $meth eq "PUT"
l!l&&r!l&&!r
000
MC/DC100%3/3
$meth eq "POST" or $meth eq "PUT" or $meth eq "PATCH"
$meth eq "POST" $meth eq "PUT" $meth eq "PATCH"
MC/DC0%0/3
$meth eq "POST" or $meth eq "PUT" or $meth eq "PATCH"
$meth eq "POST" $meth eq "PUT" $meth eq "PATCH"
Truth table100%4/4
A or B or C
A= $meth eq "POST"B= $meth eq "PUT"C= $meth eq "PATCH"
ABCresult
1XX1
01X1
0011
0000
Truth table0%0/4
A or B or C
A= $meth eq "POST"B= $meth eq "PUT"C= $meth eq "PATCH"
ABCresult
1XX1
01X1
0011
0000
688 0 ▶ if ( $content_length > 0 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($content_length > 0) 48 1 49
if ($content_length > 0) 0 0 0
689 0 ▶ if ( ( $PUTDATA_UPLOAD || $self->{'.upload_hook'} ) && !$is_xforms && ($meth eq 'POST' || $meth eq 'PUT' || $meth eq 'PATCH')
Branch: 2 branches
BranchTrueFalseTotal
if ($PUTDATA_UPLOAD || $self->{'.upload_hook'} and not $is_xforms and $meth eq 'POST' || $meth eq 'PUT' || $meth eq 'PATCH' and defined $ENV{'CONTENT_TYPE'} and not $ENV{'CONTENT_TYPE'} =~ m[^application/x-www-form-urlencoded] and not $ENV{'CONTENT_TYPE'} =~ m[^multipart/form-data]) { } 22 26 48
if ($PUTDATA_UPLOAD || $self->{'.upload_hook'} and not $is_xforms and $meth eq 'POST' || $meth eq 'PUT' || $meth eq 'PATCH' and defined $ENV{'CONTENT_TYPE'} and not $ENV{'CONTENT_TYPE'} =~ m[^application/x-www-form-urlencoded] and not $ENV{'CONTENT_TYPE'} =~ m[^multipart/form-data]) { } 0 0 0
Condition37%18/48
$PUTDATA_UPLOAD || $self->{".upload_hook"} and not $is_xforms and $meth eq "POST" || $meth eq "PUT" || $meth eq "PATCH" and defined $ENV{"CONTENT_TYPE"} and not $ENV{"CONTENT_TYPE"} =~ m[^application/x-www-form-urlencoded] and not $ENV{"CONTENT_TYPE"} =~ m[^multipart/form-data]
!ll&&!rl&&r
26022
$PUTDATA_UPLOAD || $self->{".upload_hook"} and not $is_xforms and $meth eq "POST" || $meth eq "PUT" || $meth eq "PATCH" and defined $ENV{"CONTENT_TYPE"} and not $ENV{"CONTENT_TYPE"} =~ m[^application/x-www-form-urlencoded]
!ll&&!rl&&r
26022
$PUTDATA_UPLOAD || $self->{".upload_hook"} and not $is_xforms and $meth eq "POST" || $meth eq "PUT" || $meth eq "PATCH" and defined $ENV{"CONTENT_TYPE"}
!ll&&!rl&&r
26022
$PUTDATA_UPLOAD || $self->{".upload_hook"} and not $is_xforms and $meth eq "POST" || $meth eq "PUT" || $meth eq "PATCH"
!ll&&!rl&&r
26022
$PUTDATA_UPLOAD || $self->{".upload_hook"} and not $is_xforms
!ll&&!rl&&r
26022
$PUTDATA_UPLOAD or $self->{".upload_hook"}
l!l&&r!l&&!r
16626
$meth eq "POST" or $meth eq "PUT" or $meth eq "PATCH"
l!l&&r!l&&!r
1660
$meth eq "POST" or $meth eq "PUT"
l!l&&r!l&&!r
6106
$PUTDATA_UPLOAD || $self->{".upload_hook"} and not $is_xforms and $meth eq "POST" || $meth eq "PUT" || $meth eq "PATCH" and defined $ENV{"CONTENT_TYPE"} and not $ENV{"CONTENT_TYPE"} =~ m[^application/x-www-form-urlencoded] and not $ENV{"CONTENT_TYPE"} =~ m[^multipart/form-data]
!ll&&!rl&&r
000
$PUTDATA_UPLOAD || $self->{".upload_hook"} and not $is_xforms and $meth eq "POST" || $meth eq "PUT" || $meth eq "PATCH" and defined $ENV{"CONTENT_TYPE"} and not $ENV{"CONTENT_TYPE"} =~ m[^application/x-www-form-urlencoded]
!ll&&!rl&&r
000
$PUTDATA_UPLOAD || $self->{".upload_hook"} and not $is_xforms and $meth eq "POST" || $meth eq "PUT" || $meth eq "PATCH" and defined $ENV{"CONTENT_TYPE"}
!ll&&!rl&&r
000
$PUTDATA_UPLOAD || $self->{".upload_hook"} and not $is_xforms and $meth eq "POST" || $meth eq "PUT" || $meth eq "PATCH"
!ll&&!rl&&r
000
$PUTDATA_UPLOAD || $self->{".upload_hook"} and not $is_xforms
!ll&&!rl&&r
000
$PUTDATA_UPLOAD or $self->{".upload_hook"}
l!l&&r!l&&!r
000
$meth eq "POST" or $meth eq "PUT" or $meth eq "PATCH"
l!l&&r!l&&!r
000
$meth eq "POST" or $meth eq "PUT"
l!l&&r!l&&!r
000
MC/DC22%2/9
$PUTDATA_UPLOAD || $self->{".upload_hook"} and not $is_xforms and $meth eq "POST" || $meth eq "PUT" || $meth eq "PATCH" and defined $ENV{"CONTENT_TYPE"} and not $ENV{"CONTENT_TYPE"} =~ m[^application/x-www-form-urlencoded] and not $ENV{"CONTENT_TYPE"} =~ m[^multipart/form-data]
$PUTDATA_UPLOAD $self->{".upload_hook"} not $is_xforms $meth eq "POST" $meth eq "PUT" $meth eq "PATCH" defined $ENV{"CONTENT_TYPE"} not $ENV{"CONTENT_TYPE"} =~ m[^application/x-www-form-urlencoded] not $ENV{"CONTENT_TYPE"} =~ m[^multipart/form-data]
MC/DC0%0/9
$PUTDATA_UPLOAD || $self->{".upload_hook"} and not $is_xforms and $meth eq "POST" || $meth eq "PUT" || $meth eq "PATCH" and defined $ENV{"CONTENT_TYPE"} and not $ENV{"CONTENT_TYPE"} =~ m[^application/x-www-form-urlencoded] and not $ENV{"CONTENT_TYPE"} =~ m[^multipart/form-data]
$PUTDATA_UPLOAD $self->{".upload_hook"} not $is_xforms $meth eq "POST" $meth eq "PUT" $meth eq "PATCH" defined $ENV{"CONTENT_TYPE"} not $ENV{"CONTENT_TYPE"} =~ m[^application/x-www-form-urlencoded] not $ENV{"CONTENT_TYPE"} =~ m[^multipart/form-data]
Truth table24%7/29
A or B and not(C) and D or E or F and G and not(H) and not(I)
A= $PUTDATA_UPLOADB= $self->{".upload_hook"}C= not $is_xformsD= $meth eq "POST"E= $meth eq "PUT"F= $meth eq "PATCH"G= defined $ENV{"CONTENT_TYPE"}H= not $ENV{"CONTENT_TYPE"} =~ m[^application/x-www-form-urlencoded]I= not $ENV{"CONTENT_TYPE"} =~ m[^multipart/form-data]
ABCDEFGHIresult
00XXXXXXX0
1X0XXXXXX0
010XXXXXX0
1X1000XXX0
011000XXX0
1X11XX0XX0
1X101X0XX0
1X10010XX0
0111XX0XX0
01101X0XX0
0110010XX0
1X11XX10X0
1X101X10X0
1X100110X0
0111XX10X0
01101X10X0
01100110X0
1X11XX1100
1X101X1100
1X10011100
0111XX1100
01101X1100
0110011100
1X11XX1111
1X101X1111
1X10011111
0111XX1111
01101X1111
0110011111
Truth table0%0/29
A or B and not(C) and D or E or F and G and not(H) and not(I)
A= $PUTDATA_UPLOADB= $self->{".upload_hook"}C= not $is_xformsD= $meth eq "POST"E= $meth eq "PUT"F= $meth eq "PATCH"G= defined $ENV{"CONTENT_TYPE"}H= not $ENV{"CONTENT_TYPE"} =~ m[^application/x-www-form-urlencoded]I= not $ENV{"CONTENT_TYPE"} =~ m[^multipart/form-data]
ABCDEFGHIresult
00XXXXXXX0
1X0XXXXXX0
010XXXXXX0
1X1000XXX0
011000XXX0
1X11XX0XX0
1X101X0XX0
1X10010XX0
0111XX0XX0
01101X0XX0
0110010XX0
1X11XX10X0
1X101X10X0
1X100110X0
0111XX10X0
01101X10X0
01100110X0
1X11XX1100
1X101X1100
1X10011100
0111XX1100
01101X1100
0110011100
1X11XX1111
1X101X1111
1X10011111
0111XX1111
01101X1111
0110011111
690 && defined($ENV{'CONTENT_TYPE'})
691 && $ENV{'CONTENT_TYPE'} !~ m|^application/x-www-form-urlencoded|
692 && $ENV{'CONTENT_TYPE'} !~ m|^multipart/form-data| ){
693 0 my $postOrPut = $meth . 'DATA' ; # POSTDATA/PUTDATA
694 0 $self->read_postdata_putdata( $postOrPut, $content_length, $ENV{'CONTENT_TYPE'} );
695 0 $meth = ''; # to skip xform testing
696 0 undef $query_string ;
697 } else {
698 0 $self->read_from_client(\$query_string,$content_length,0);
699 }
700 }
701 0 ▶ if ($APPEND_QUERY_STRING) {
Branch: 2 branches
BranchTrueFalseTotal
if ($APPEND_QUERY_STRING) 3 38 41
if ($APPEND_QUERY_STRING) 0 0 0
702 # Some people want to have their cake and eat it too!
703 # Set $APPEND_QUERY_STRING = 1 to have the contents of the query string
704 # APPENDED to the POST data.
705 0 ▶ $query_string .= (length($query_string) ? '&' : '') . $ENV{'QUERY_STRING'} if defined $ENV{'QUERY_STRING'};
Branch: 4 branches
BranchTrueFalseTotal
if defined $ENV{"QUERY_STRING"} 3 0 3
length $query_string ? : 3 0 3
if defined $ENV{"QUERY_STRING"} 0 0 0
length $query_string ? : 0 0 0
706 }
707 0 last METHOD;
708 }
709  
710 # If there is no request at all (no REQUEST_METHOD, and not running
711 # under a web server), assume we're being debugged offline.
712 # Check the command line and then the standard input for data.
713 # We use the shellwords package in order to behave the way that
714 # UN*X programmers expect. This must not happen for a request with
715 # some other method (e.g. OPTIONS, or "post"), which a client can
716 # send, as the process' own command line would become the params.
717 0 ▶ if ($DEBUG
Branch: 2 branches
BranchTrueFalseTotal
if ($DEBUG and not defined $ENV{"REQUEST_METHOD"} and not defined $ENV{"GATEWAY_INTERFACE"} and not exists $ENV{"FCGI_ROLE"} and not $MOD_PERL) 79 26 105
if ($DEBUG and not defined $ENV{"REQUEST_METHOD"} and not defined $ENV{"GATEWAY_INTERFACE"} and not exists $ENV{"FCGI_ROLE"} and not $MOD_PERL) 0 0 0
Condition45%11/24
$DEBUG and not defined $ENV{"REQUEST_METHOD"} and not defined $ENV{"GATEWAY_INTERFACE"} and not exists $ENV{"FCGI_ROLE"} and not $MOD_PERL
!ll&&!rl&&r
26079
$DEBUG and not defined $ENV{"REQUEST_METHOD"} and not defined $ENV{"GATEWAY_INTERFACE"} and not exists $ENV{"FCGI_ROLE"}
!ll&&!rl&&r
25179
$DEBUG and not defined $ENV{"REQUEST_METHOD"} and not defined $ENV{"GATEWAY_INTERFACE"}
!ll&&!rl&&r
24180
$DEBUG and not defined $ENV{"REQUEST_METHOD"}
!ll&&!rl&&r
32181
$DEBUG and not defined $ENV{"REQUEST_METHOD"} and not defined $ENV{"GATEWAY_INTERFACE"} and not exists $ENV{"FCGI_ROLE"} and not $MOD_PERL
!ll&&!rl&&r
000
$DEBUG and not defined $ENV{"REQUEST_METHOD"} and not defined $ENV{"GATEWAY_INTERFACE"} and not exists $ENV{"FCGI_ROLE"}
!ll&&!rl&&r
000
$DEBUG and not defined $ENV{"REQUEST_METHOD"} and not defined $ENV{"GATEWAY_INTERFACE"}
!ll&&!rl&&r
000
$DEBUG and not defined $ENV{"REQUEST_METHOD"}
!ll&&!rl&&r
000
MC/DC80%4/5
$DEBUG and not defined $ENV{"REQUEST_METHOD"} and not defined $ENV{"GATEWAY_INTERFACE"} and not exists $ENV{"FCGI_ROLE"} and not $MOD_PERL
$DEBUG not defined $ENV{"REQUEST_METHOD"} not defined $ENV{"GATEWAY_INTERFACE"} not exists $ENV{"FCGI_ROLE"} not $MOD_PERL
MC/DC0%0/5
$DEBUG and not defined $ENV{"REQUEST_METHOD"} and not defined $ENV{"GATEWAY_INTERFACE"} and not exists $ENV{"FCGI_ROLE"} and not $MOD_PERL
$DEBUG not defined $ENV{"REQUEST_METHOD"} not defined $ENV{"GATEWAY_INTERFACE"} not exists $ENV{"FCGI_ROLE"} not $MOD_PERL
Truth table83%5/6
A and not(B) and not(C) and not(D) and not(E)
A= $DEBUGB= not defined $ENV{"REQUEST_METHOD"}C= not defined $ENV{"GATEWAY_INTERFACE"}D= not exists $ENV{"FCGI_ROLE"}E= not $MOD_PERL
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
Truth table0%0/6
A and not(B) and not(C) and not(D) and not(E)
A= $DEBUGB= not defined $ENV{"REQUEST_METHOD"}C= not defined $ENV{"GATEWAY_INTERFACE"}D= not exists $ENV{"FCGI_ROLE"}E= not $MOD_PERL
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
718 && !defined $ENV{'REQUEST_METHOD'}
719 && !defined $ENV{'GATEWAY_INTERFACE'}
720 && !exists $ENV{'FCGI_ROLE'}
721 && !$MOD_PERL)
722 {
723 0 my $cmdline_ret = read_from_cmdline();
724 0 $query_string = $cmdline_ret->{'query_string'};
725 0 ▶ if (defined($cmdline_ret->{'subpath'}))
Branch: 2 branches
BranchTrueFalseTotal
if (defined $cmdline_ret->{"subpath"}) 1 78 79
if (defined $cmdline_ret->{"subpath"}) 0 0 0
726 {
727 0 $self->path_info($cmdline_ret->{'subpath'});
728 }
729 }
730 }
731  
732 # YL: Begin Change for XML handler 10/19/2001
733 0 ▶ if (!$is_xforms && !$too_large && ($meth eq 'POST' || $meth eq 'PUT' || $meth eq 'PATCH')
Branch: 2 branches
BranchTrueFalseTotal
if (not $is_xforms || $too_large and $meth eq "POST" || $meth eq "PUT" || $meth eq "PATCH" and defined $ENV{"CONTENT_TYPE"} and not $ENV{"CONTENT_TYPE"} =~ m[^application/x-www-form-urlencoded] and not $ENV{"CONTENT_TYPE"} =~ m[^multipart/form-data]) 10 1995 2005
if (not $is_xforms || $too_large and $meth eq "POST" || $meth eq "PUT" || $meth eq "PATCH" and defined $ENV{"CONTENT_TYPE"} and not $ENV{"CONTENT_TYPE"} =~ m[^application/x-www-form-urlencoded] and not $ENV{"CONTENT_TYPE"} =~ m[^multipart/form-data]) 0 0 0
Condition50%21/42
not $is_xforms || $too_large and $meth eq "POST" || $meth eq "PUT" || $meth eq "PATCH" and defined $ENV{"CONTENT_TYPE"} and not $ENV{"CONTENT_TYPE"} =~ m[^application/x-www-form-urlencoded] and not $ENV{"CONTENT_TYPE"} =~ m[^multipart/form-data]
!ll&&!rl&&r
256173910
not $is_xforms || $too_large and $meth eq "POST" || $meth eq "PUT" || $meth eq "PATCH" and defined $ENV{"CONTENT_TYPE"} and not $ENV{"CONTENT_TYPE"} =~ m[^application/x-www-form-urlencoded]
!ll&&!rl&&r
24791749
not $is_xforms || $too_large and $meth eq "POST" || $meth eq "PUT" || $meth eq "PATCH" and defined $ENV{"CONTENT_TYPE"}
!ll&&!rl&&r
23891758
not $is_xforms || $too_large and $meth eq "POST" || $meth eq "PUT" || $meth eq "PATCH"
!ll&&!rl&&r
252131767
$is_xforms || $too_large
l!l&&r!l&&!r
15101980
$meth eq "POST" or $meth eq "PUT" or $meth eq "PATCH"
l!l&&r!l&&!r
17652213
$meth eq "POST" or $meth eq "PUT"
l!l&&r!l&&!r
17614215
not $is_xforms || $too_large and $meth eq "POST" || $meth eq "PUT" || $meth eq "PATCH" and defined $ENV{"CONTENT_TYPE"} and not $ENV{"CONTENT_TYPE"} =~ m[^application/x-www-form-urlencoded] and not $ENV{"CONTENT_TYPE"} =~ m[^multipart/form-data]
!ll&&!rl&&r
000
not $is_xforms || $too_large and $meth eq "POST" || $meth eq "PUT" || $meth eq "PATCH" and defined $ENV{"CONTENT_TYPE"} and not $ENV{"CONTENT_TYPE"} =~ m[^application/x-www-form-urlencoded]
!ll&&!rl&&r
000
not $is_xforms || $too_large and $meth eq "POST" || $meth eq "PUT" || $meth eq "PATCH" and defined $ENV{"CONTENT_TYPE"}
!ll&&!rl&&r
000
not $is_xforms || $too_large and $meth eq "POST" || $meth eq "PUT" || $meth eq "PATCH"
!ll&&!rl&&r
000
$is_xforms || $too_large
l!l&&r!l&&!r
000
$meth eq "POST" or $meth eq "PUT" or $meth eq "PATCH"
l!l&&r!l&&!r
000
$meth eq "POST" or $meth eq "PUT"
l!l&&r!l&&!r
000
MC/DC100%8/8
not $is_xforms || $too_large and $meth eq "POST" || $meth eq "PUT" || $meth eq "PATCH" and defined $ENV{"CONTENT_TYPE"} and not $ENV{"CONTENT_TYPE"} =~ m[^application/x-www-form-urlencoded] and not $ENV{"CONTENT_TYPE"} =~ m[^multipart/form-data]
$is_xforms $too_large $meth eq "POST" $meth eq "PUT" $meth eq "PATCH" defined $ENV{"CONTENT_TYPE"} not $ENV{"CONTENT_TYPE"} =~ m[^application/x-www-form-urlencoded] not $ENV{"CONTENT_TYPE"} =~ m[^multipart/form-data]
MC/DC0%0/8
not $is_xforms || $too_large and $meth eq "POST" || $meth eq "PUT" || $meth eq "PATCH" and defined $ENV{"CONTENT_TYPE"} and not $ENV{"CONTENT_TYPE"} =~ m[^application/x-www-form-urlencoded] and not $ENV{"CONTENT_TYPE"} =~ m[^multipart/form-data]
$is_xforms $too_large $meth eq "POST" $meth eq "PUT" $meth eq "PATCH" defined $ENV{"CONTENT_TYPE"} not $ENV{"CONTENT_TYPE"} =~ m[^application/x-www-form-urlencoded] not $ENV{"CONTENT_TYPE"} =~ m[^multipart/form-data]
Truth table66%10/15
not(A || B) and C or D or E and F and not(G) and not(H)
A= $is_xformsB= $too_largeC= $meth eq "POST"D= $meth eq "PUT"E= $meth eq "PATCH"F= defined $ENV{"CONTENT_TYPE"}G= not $ENV{"CONTENT_TYPE"} =~ m[^application/x-www-form-urlencoded]H= not $ENV{"CONTENT_TYPE"} =~ m[^multipart/form-data]
ABCDEFGHresult
1XXXXXXX0
01XXXXXX0
00000XXX0
001XX0XX0
0001X0XX0
000010XX0
001XX10X0
0001X10X0
0000110X0
001XX1100
0001X1100
000011100
001XX1111
0001X1111
000011111
Truth table0%0/15
not(A || B) and C or D or E and F and not(G) and not(H)
A= $is_xformsB= $too_largeC= $meth eq "POST"D= $meth eq "PUT"E= $meth eq "PATCH"F= defined $ENV{"CONTENT_TYPE"}G= not $ENV{"CONTENT_TYPE"} =~ m[^application/x-www-form-urlencoded]H= not $ENV{"CONTENT_TYPE"} =~ m[^multipart/form-data]
ABCDEFGHresult
1XXXXXXX0
01XXXXXX0
00000XXX0
001XX0XX0
0001X0XX0
000010XX0
001XX10X0
0001X10X0
0000110X0
001XX1100
0001X1100
000011100
001XX1111
0001X1111
000011111
734 && defined($ENV{'CONTENT_TYPE'})
735 && $ENV{'CONTENT_TYPE'} !~ m|^application/x-www-form-urlencoded|
736 && $ENV{'CONTENT_TYPE'} !~ m|^multipart/form-data| ) {
737 0 my($param) = $meth . 'DATA' ;
738 0 $self->add_parameter($param) ;
739 0 push (@{$self->{param}{$param}},$query_string);
740 0 undef $query_string ;
741 }
742 # YL: End Change for XML handler 10/19/2001
743  
744 # We now have the query string in hand. We do slightly
745 # different things for keyword lists and parameter lists.
746 0 ▶ if (defined $query_string && length $query_string) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $query_string and length $query_string) 71 1934 2005
if (defined $query_string and length $query_string) 0 0 0
Condition50%3/6
defined $query_string and length $query_string
!ll&&!rl&&r
24191071
defined $query_string and length $query_string
!ll&&!rl&&r
000
MC/DC100%2/2
defined $query_string and length $query_string
defined $query_string length $query_string
MC/DC0%0/2
defined $query_string and length $query_string
defined $query_string length $query_string
Truth table100%3/3
A and B
A= defined $query_stringB= length $query_string
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= defined $query_stringB= length $query_string
ABresult
0X0
100
111
747 0 ▶ if ($query_string =~ /[&=;]/) {
Branch: 4 branches
BranchTrueFalseTotal
if ($query_string =~ /[&=;]/) { } 64 7 71
elsif (not defined $initializer and $self->_too_many_params($query_string =~ tr/+// + 1)) { } 1 6 7
if ($query_string =~ /[&=;]/) { } 0 0 0
elsif (not defined $initializer and $self->_too_many_params($query_string =~ tr/+// + 1)) { } 0 0 0
748 # client sent params can't use the reserved names, an app's own
749 # initializer (e.g. restoring saved state) can
750 0 $self->parse_params($query_string,!defined($initializer));
751 ▶ } elsif ( !defined($initializer)
Condition33%2/6
not defined $initializer and $self->_too_many_params($query_string =~ tr/+// + 1)
!ll&&!rl&&r
061
not defined $initializer and $self->_too_many_params($query_string =~ tr/+// + 1)
!ll&&!rl&&r
000
MC/DC50%1/2
not defined $initializer and $self->_too_many_params($query_string =~ tr/+// + 1)
not defined $initializer $self->_too_many_params($query_string =~ tr/+// + 1)
MC/DC0%0/2
not defined $initializer and $self->_too_many_params($query_string =~ tr/+// + 1)
not defined $initializer $self->_too_many_params($query_string =~ tr/+// + 1)
Truth table66%2/3
not(A) and B
A= not defined $initializerB= $self->_too_many_params($query_string =~ tr/+// + 1)
ABresult
0X0
100
111
Truth table0%0/3
not(A) and B
A= not defined $initializerB= $self->_too_many_params($query_string =~ tr/+// + 1)
ABresult
0X0
100
111
752 && $self->_too_many_params( ( $query_string =~ tr/+// ) + 1 ) ) {
753 0 $self->_request_too_large;
754 } else {
755 0 $self->add_parameter('keywords');
756 0 $self->{param}{'keywords'} = [$self->parse_keywordlist($query_string)];
757 }
758 }
759  
760 # Special case. Erase everything if there is a field named
761 # .defaults.
762 0 ▶ if ($self->param('.defaults')) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->param(".defaults")) 0 2005 2005
if ($self->param(".defaults")) 0 0 0
763 0 $self->delete_all();
764 }
765  
766 # hash containing our defined fieldnames
767 0 $self->{'.fieldnames'} = {};
768 0 for ($self->param('.cgifields')) {
769 0 $self->{'.fieldnames'}->{$_}++;
770 }
771
772 # Clear out our default submission button flag if present
773 0 $self->delete('.submit');
774 0 $self->delete('.cgifields');
775  
776 0 ▶ $self->save_request unless defined $initializer;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $initializer 1969 36 2005
unless defined $initializer 0 0 0
777 }
778  
779 # Run a multipart reader, enforcing $POST_MAX, $MAX_PARAMS and $MAX_UPLOADS
780 # while reading. These can't all be checked up front (e.g. without a
781 # CONTENT_LENGTH, with chunked transfer encoding), so the readers die with
782 # $REQUEST_TOO_LARGE once a limit is passed. Returns false if one was.
783 1775 ▶sub _within_request_limits {
Subroutine _within_request_limits: called CC=3 SCAR=11.0
784 1775 my ( $self,$reader ) = @_;
785 1775 ▶ return 1 if eval { $reader->(); 1 };
Branch: 1 branch
BranchTrueFalseTotal
if eval { do { &$reader(); 1 } } 1751 24 1775
786 24 ▶ die $@ unless $@ eq $REQUEST_TOO_LARGE;
Branch: 1 branch
BranchTrueFalseTotal
unless $@ eq $REQUEST_TOO_LARGE 16 8 24
787 8 $self->_request_too_large;
788 8 return 0;
789 }
790  
791 # discard anything parsed so far, the same as when $POST_MAX is exceeded up
792 # front, and set the error
793 13 ▶sub _request_too_large {
Subroutine _request_too_large: called CC=1 SCAR=0.0
794 13 my ( $self ) = @_;
795 13 $self->{param} = {};
796 13 $self->{'.parameters'} = [];
797 13 $self->{'.tmpfiles'} = {};
798 13 $self->cgi_error("413 Request entity too large");
799 13 return;
800 }
801  
802 # true if $count values would exceed $MAX_PARAMS, counting those already
803 # parsed from the request
804 56 ▶sub _too_many_params {
Subroutine _too_many_params: called CC=4 SCAR=13.9
805 56 my ( $self,$count ) = @_;
806 56 ▶ return 0 unless $MAX_PARAMS > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $MAX_PARAMS > 0 1 55 56
807 55 ▶ $count += @$_ for values %{ $self->{param} || {} };
Condition100%2/2
$self->{'param'} || {}
l!l
847
MC/DC100%1/1
$self->{'param'} || {}
$self->{'param'}
Truth table100%2/2
A
A= $self->{'param'}
Aresult
11
00
808 55 return $count > $MAX_PARAMS;
809 }
810  
811 88 ▶sub _get_query_string_from_env {
Subroutine _get_query_string_from_env: called CC=12 SCAR=30.7
812 88 my $self = shift;
813 88 my $query_string = '';
814  
815 88 ▶ if ( $MOD_PERL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($MOD_PERL) 0 88 88
816 0 $query_string = $self->r->args;
817 0 ▶ if ( ! $query_string && $MOD_PERL == 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $query_string and $MOD_PERL == 2) 0 0 0
Condition0%0/3
not $query_string and $MOD_PERL == 2
!ll&&!rl&&r
000
MC/DC0%0/2
not $query_string and $MOD_PERL == 2
not $query_string $MOD_PERL == 2
Truth table0%0/3
not(A) and B
A= not $query_stringB= $MOD_PERL == 2
ABresult
0X0
100
111
818 # possibly a redirect, inspect prev request
819 # (->prev only supported under mod_perl2)
820 0 ▶ if ( my $prev = $self->r->prev ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $prev = $self->r->prev) 0 0 0
821 0 $query_string = $prev->args;
822 }
823 }
824 }
825  
826 $query_string ||= $ENV{'QUERY_STRING'}
827 88 ▶ if defined $ENV{'QUERY_STRING'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $ENV{"QUERY_STRING"} 73 15 88
Condition66%2/3
$query_string ||= $ENV{"QUERY_STRING"}
l!l&&r!l&&!r
03538
MC/DC50%1/2
$query_string ||= $ENV{"QUERY_STRING"}
$query_string $ENV{"QUERY_STRING"}
Truth table66%2/3
A ||= B
A= $query_stringB= $ENV{"QUERY_STRING"}
ABresult
1X1
011
000
828  
829 88 ▶ if ( ! $query_string ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($query_string) 53 35 88
830 # try to get from REDIRECT_ env variables, support
831 # 5 levels of redirect and no more (RT #36312)
832 53 REDIRECT: foreach my $r ( 1 .. 5 ) {
833 245 my $key = join( '',( 'REDIRECT_' x $r ) );
834 $query_string ||= $ENV{"${key}QUERY_STRING"}
835 245 ▶ if defined $ENV{"${key}QUERY_STRING"};
Branch: 1 branch
BranchTrueFalseTotal
if defined $ENV{"${key}QUERY_STRING"} 10 235 245
Condition33%1/3
$query_string ||= $ENV{"${key}QUERY_STRING"}
l!l&&r!l&&!r
0100
MC/DC0%0/2
$query_string ||= $ENV{"${key}QUERY_STRING"}
$query_string $ENV{"${key}QUERY_STRING"}
Truth table33%1/3
A ||= B
A= $query_stringB= $ENV{"${key}QUERY_STRING"}
ABresult
1X1
011
000
836 245 ▶ last REDIRECT if $query_string;
Branch: 1 branch
BranchTrueFalseTotal
if $query_string 10 235 245
837 }
838 }
839  
840 88 return $query_string;
841 }
842  
843 # FUNCTIONS TO OVERRIDE:
844 # Turn a string into a filehandle
845 25 ▶sub to_filehandle {
Subroutine to_filehandle: called CC=8 SCAR=21.2
Pod undocumented
846 25 my $thingy = shift;
847 25 ▶ return undef unless $thingy;
Branch: 1 branch
BranchTrueFalseTotal
unless $thingy 0 25 25
848 25 ▶ return $thingy if UNIVERSAL::isa($thingy,'GLOB');
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::isa($thingy, "GLOB") 5 20 25
849 20 ▶ return $thingy if UNIVERSAL::isa($thingy,'FileHandle');
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::isa($thingy, "FileHandle") 0 20 20
850 20 ▶ if (!ref($thingy)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $thingy) 11 9 20
851 11 my $caller = 1;
852 11 ▶ while (my $package = caller($caller++)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $package = caller $caller++) 22 11 33
853 22 ▶ my($tmp) = $thingy=~/[\':]/ ? $thingy : "$package\:\:$thingy";
Branch: 1 branch
BranchTrueFalseTotal
$thingy =~ /[\':]/ ? : 0 22 22
854 22 ▶ return $tmp if defined(fileno($tmp));
Branch: 1 branch
BranchTrueFalseTotal
if defined fileno $tmp 0 22 22
855 }
856 }
857 20 return undef;
858 }
859  
860 # send output to the browser
861 0 ▶sub put {
Subroutine put: not called CC=1 SCAR=6.9
Pod undocumented
862 0 my($self,@p) = self_or_default(@_);
863 0 $self->print(@p);
864 }
865  
866 # print to standard output (for overriding in mod_perl)
867 0 ▶sub print {
Subroutine print: not called CC=1 SCAR=6.9
Pod undocumented
868 0 shift;
869 0 CORE::print(@_);
870 }
871  
872 # get/set last cgi_error
873 49 ▶sub cgi_error {
Subroutine cgi_error: called CC=2 SCAR=6.9
Pod undocumented
874 49 my ($self,$err) = self_or_default(@_);
875 49 ▶ $self->{'.cgi_error'} = $err if defined $err;
Branch: 1 branch
BranchTrueFalseTotal
if defined $err 17 32 49
876 49 return $self->{'.cgi_error'};
877 }
878  
879 1962 ▶sub save_request {
Subroutine save_request: called CC=5 SCAR=16.1
Pod undocumented
880 1962 my($self) = @_;
881 # We're going to play with the package globals now so that if we get called
882 # again, we initialize ourselves in exactly the same way. This allows
883 # us to have several of these objects.
884 1962 @QUERY_PARAM = $self->param; # save list of parameters
885 1962 for (@QUERY_PARAM) {
886 3761 ▶ next unless defined $_;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_ 0 3761 3761
887 # a copy, so that later changes to this object's params (append,
888 # param_fetch, etc) don't change those of objects created later
889 3761 ▶ $QUERY_PARAM{$_}=[ @{ $self->{param}{$_} || [] } ];
Condition100%2/2
$self->{'param'}{$_} || []
l!l
37574
MC/DC100%1/1
$self->{'param'}{$_} || []
$self->{'param'}{$_}
Truth table100%2/2
A
A= $self->{'param'}{$_}
Aresult
11
00
890 }
891 1962 $QUERY_CHARSET = $self->charset;
892 1962 $QUERY_CGI_ERROR = $self->{'.cgi_error'};
893 1962 %QUERY_FIELDNAMES = %{$self->{'.fieldnames'}};
894 1962 ▶ %QUERY_TMPFILES = %{ $self->{'.tmpfiles'} || {} };
Condition100%2/2
$self->{'.tmpfiles'} || {}
l!l
1211841
MC/DC100%1/1
$self->{'.tmpfiles'} || {}
$self->{'.tmpfiles'}
Truth table100%2/2
A
A= $self->{'.tmpfiles'}
Aresult
11
00
895 }
896  
897 64 ▶sub parse_params {
Subroutine parse_params: called CC=10 SCAR=23.3
Pod undocumented
898 64 my($self,$tosplit,$from_request) = @_;
899 # count (cheaply) before splitting, so a huge number of params doesn't
900 # cost the time and memory to split and decode them all first
901 64 ▶ return $self->_request_too_large
Branch: 1 branch
BranchTrueFalseTotal
if $from_request and $self->_too_many_params($tosplit =~ tr/&;// + 1) 4 60 64
Condition100%3/3
$from_request and $self->_too_many_params($tosplit =~ tr/&;// + 1)
!ll&&!rl&&r
15454
MC/DC100%2/2
$from_request and $self->_too_many_params($tosplit =~ tr/&;// + 1)
$from_request $self->_too_many_params($tosplit =~ tr/&;// + 1)
Truth table100%3/3
A and B
A= $from_requestB= $self->_too_many_params($tosplit =~ tr/&;// + 1)
ABresult
0X0
100
111
902 if $from_request && $self->_too_many_params( ( $tosplit =~ tr/&;// ) + 1 );
903 60 my(@pairs) = split(/[&;]/,$tosplit);
904 60 my($param,$value);
905 60 for (@pairs) {
906 211 ($param,$value) = split('=',$_,2);
907 211 ▶ next unless defined $param;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $param 0 211 211
908 211 ▶ next if $NO_UNDEF_PARAMS and not defined $value;
Branch: 1 branch
BranchTrueFalseTotal
if $NO_UNDEF_PARAMS and not defined $value 0 211 211
Condition33%1/3
$NO_UNDEF_PARAMS and not defined $value
!ll&&!rl&&r
21100
MC/DC0%0/2
$NO_UNDEF_PARAMS and not defined $value
$NO_UNDEF_PARAMS not defined $value
Truth table33%1/3
A and not(B)
A= $NO_UNDEF_PARAMSB= not defined $value
ABresult
0X0
100
111
909 211 ▶ $value = '' unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 211 211
910 211 $param = unescape($param);
911 211 $value = unescape($value);
912 211 ▶ next if $from_request && $RESERVED_PARAM{$param};
Branch: 1 branch
BranchTrueFalseTotal
if $from_request and $RESERVED_PARAM{$param} 16 195 211
Condition100%3/3
$from_request and $RESERVED_PARAM{$param}
!ll&&!rl&&r
4714816
MC/DC100%2/2
$from_request and $RESERVED_PARAM{$param}
$from_request $RESERVED_PARAM{$param}
Truth table100%3/3
A and B
A= $from_requestB= $RESERVED_PARAM{$param}
ABresult
0X0
100
111
913 195 $self->add_parameter($param);
914 195 push (@{$self->{param}{$param}},$value);
915 }
916 }
917  
918 3930 ▶sub add_parameter {
Subroutine add_parameter: called CC=3 SCAR=11.0
Pod undocumented
919 3930 my($self,$param)=@_;
920 3930 ▶ return unless defined $param;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $param 0 3930 3930
921 3886 push (@{$self->{'.parameters'}},$param)
922 3930 ▶ unless defined($self->{param}{$param});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"param"}{$param} 3886 44 3930
923 }
924  
925 6123 ▶sub all_parameters {
Subroutine all_parameters: called CC=4 SCAR=13.9
Pod undocumented
926 6123 my $self = shift;
927 6123 ▶ return () unless defined($self) && $self->{'.parameters'};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self and $self->{".parameters"} 150 5973 6123
Condition66%2/3
defined $self and $self->{".parameters"}
!ll&&!rl&&r
01505973
MC/DC50%1/2
defined $self and $self->{".parameters"}
defined $self $self->{".parameters"}
Truth table66%2/3
A and B
A= defined $selfB= $self->{".parameters"}
ABresult
0X0
100
111
928 5973 ▶ return () unless @{$self->{'.parameters'}};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$self->{".parameters"};} 369 5604 5973
929 5604 return @{$self->{'.parameters'}};
930 }
931  
932 # put a filehandle into binary mode (DOS)
933 1770 ▶sub binmode {
Subroutine binmode: called CC=4 SCAR=14.2
Pod undocumented
934 1770 ▶ return unless defined($_[1]) && ref ($_[1]) && defined fileno($_[1]);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[1] and ref $_[1] and defined fileno $_[1] 1768 2 1770
Condition66%4/6
defined $_[1] and ref $_[1] and defined fileno $_[1]
!ll&&!rl&&r
176802
defined $_[1] and ref $_[1]
!ll&&!rl&&r
176802
MC/DC33%1/3
defined $_[1] and ref $_[1] and defined fileno $_[1]
defined $_[1] ref $_[1] defined fileno $_[1]
Truth table50%2/4
A and B and C
A= defined $_[1]B= ref $_[1]C= defined fileno $_[1]
ABCresult
0XX0
10X0
1100
1111
935 2 CORE::binmode($_[1]);
936 }
937  
938 # back compatibility html tag generation functions - noop
939 # since this is now the default having removed AUTOLOAD
940 1 ▶sub compile { 1; }
Subroutine compile: called CC=1 SCAR=0.0
Pod undocumented
941  
942 85 ▶sub _all_html_tags {
Subroutine _all_html_tags: called CC=1 SCAR=0.0
943 85 return qw/
944 a abbr acronym address applet Area
945 b base basefont bdo big blink blockquote body br
946 caption center cite code col colgroup
947 dd del dfn div dl dt
948 em embed
949 fieldset font fontsize frame frameset
950 h1 h2 h3 h4 h5 h6 head hr html
951 i iframe ilayer img input ins
952 kbd
953 label layer legend li Link
954 Map menu meta
955 nextid nobr noframes noscript
956 object ol option
957 p Param pre
958 Q
959 samp script Select small span
960 strike strong style Sub sup
961 table tbody td tfoot th thead title Tr TR tt
962 u ul
963 var
964 /
965 }
966  
967 84 foreach my $tag ( _all_html_tags() ) {
968 441 ▶ *$tag = sub { return _tag_func($tag,@_); };
Subroutine __ANON__: called CC=1 SCAR=0.0
969  
970 # start_html and end_html already exist as custom functions
971 7728 ▶ next if ($tag eq 'html');
Branch: 1 branch
BranchTrueFalseTotal
if $tag eq "html" 84 7644 7728
972  
973 7644 foreach my $start_end ( qw/ start end / ) {
974 15288 my $start_end_function = "${start_end}_${tag}";
975 320 ▶ *$start_end_function = sub { return _tag_func($start_end_function,@_); };
Subroutine __ANON__: called CC=1 SCAR=0.0
976 }
977 }
978  
979 761 ▶sub _tag_func {
Subroutine _tag_func: called CC=10 SCAR=23.1
980 761 my $tagname = shift;
981 761 my ($q,$a,@rest) = self_or_default(@_);
982  
983 761 my($attr) = '';
984  
985 761 ▶ if (ref($a) && ref($a) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $a and ref $a eq 'HASH') { } 245 516 761
Condition66%2/3
ref $a and ref $a eq "HASH"
!ll&&!rl&&r
5160245
MC/DC50%1/2
ref $a and ref $a eq "HASH"
ref $a ref $a eq "HASH"
Truth table66%2/3
A and B
A= ref $aB= ref $a eq "HASH"
ABresult
0X0
100
111
986 245 my(@attr) = make_attributes($a,$q->{'escape'});
987 245 ▶ $attr = " @attr" if @attr;
Branch: 1 branch
BranchTrueFalseTotal
if @attr 245 0 245
988 } else {
989 516 ▶ unshift @rest,$a if defined $a;
Branch: 1 branch
BranchTrueFalseTotal
if defined $a 286 230 516
990 }
991  
992 761 $tagname = lc( $tagname );
993  
994 761 ▶ if ($tagname=~/start_(\w+)/i) {
Branch: 2 branches
BranchTrueFalseTotal
if ($tagname =~ /start_(\w+)/i) { } 183 578 761
elsif ($tagname =~ /end_(\w+)/i) { } 137 441 578
995 183 return "<$1$attr>";
996 } elsif ($tagname=~/end_(\w+)/i) {
997 137 return "</$1>";
998 } else {
999 441 ▶ return $XHTML ? "<$tagname$attr />" : "<$tagname$attr>" unless @rest;
Branch: 2 branches
BranchTrueFalseTotal
unless @rest 188 253 441
$XHTML ? : 188 0 188
1000 253 my($tag,$untag) = ("<$tagname$attr>","</$tagname>");
1001 255 ▶ my @result = map { "$tag$_$untag" }
Branch: 1 branch
BranchTrueFalseTotal
ref $rest[0] eq 'ARRAY' ? : 2 251 253
1002 253 (ref($rest[0]) eq 'ARRAY') ? @{$rest[0]} : "@rest";
1003 253 return "@result";
1004 }
1005 }
1006  
1007 29 ▶sub _selected {
Subroutine _selected: called CC=3 SCAR=11.0
1008 29 my $self = shift;
1009 29 my $value = shift;
1010 29 ▶ return '' unless $value;
Branch: 1 branch
BranchTrueFalseTotal
unless $value 19 10 29
1011 10 ▶ return $XHTML ? qq(selected="selected" ) : qq(selected );
Branch: 1 branch
BranchTrueFalseTotal
$XHTML ? : 10 0 10
1012 }
1013  
1014 42 ▶sub _checked {
Subroutine _checked: called CC=3 SCAR=11.0
1015 42 my $self = shift;
1016 42 my $value = shift;
1017 42 ▶ return '' unless $value;
Branch: 1 branch
BranchTrueFalseTotal
unless $value 20 22 42
1018 22 ▶ return $XHTML ? qq(checked="checked" ) : qq(checked );
Branch: 1 branch
BranchTrueFalseTotal
$XHTML ? : 21 1 22
1019 }
1020  
1021 24 ▶sub _reset_globals { initialize_globals(); }
Subroutine _reset_globals: called CC=1 SCAR=0.0
1022  
1023 84 ▶sub _setup_symbols {
Subroutine _setup_symbols: called CC=18 SCAR=31.1
1024 84 my $self = shift;
1025  
1026 # to avoid reexporting unwanted variables
1027 84 undef %EXPORT;
1028  
1029 84 for (@_) {
1030  
1031 95 ▶ if ( /^[:-]any$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^[:-]any$/) 0 95 95
1032 0 warn "CGI -any pragma has been REMOVED. You should audit your code for any use "
1033 . "of none supported / incorrectly spelled tags and remove them"
1034 ;
1035 0 next;
1036 }
1037 95 ▶ $HEADERS_ONCE++, next if /^[:-]unique_headers$/;
Branch: 1 branch
BranchTrueFalseTotal
if /^[:-]unique_headers$/ 0 95 95
1038 95 ▶ $NPH++, next if /^[:-]nph$/;
Branch: 1 branch
BranchTrueFalseTotal
if /^[:-]nph$/ 0 95 95
1039 95 ▶ $NOSTICKY++, next if /^[:-]nosticky$/;
Branch: 1 branch
BranchTrueFalseTotal
if /^[:-]nosticky$/ 0 95 95
1040 95 ▶ $DEBUG=0, next if /^[:-]no_?[Dd]ebug$/;
Branch: 1 branch
BranchTrueFalseTotal
if /^[:-]no_?[Dd]ebug$/ 4 91 95
1041 91 ▶ $DEBUG=2, next if /^[:-][Dd]ebug$/;
Branch: 1 branch
BranchTrueFalseTotal
if /^[:-][Dd]ebug$/ 0 91 91
1042 91 ▶ $USE_PARAM_SEMICOLONS++, next if /^[:-]newstyle_urls$/;
Branch: 1 branch
BranchTrueFalseTotal
if /^[:-]newstyle_urls$/ 0 91 91
1043 91 ▶ $PUTDATA_UPLOAD++, next if /^[:-](?:putdata_upload|postdata_upload|patchdata_upload)$/;
Branch: 1 branch
BranchTrueFalseTotal
if /^[:-](?:putdata_upload|postdata_upload|patchdata_upload)$/ 3 88 91
1044 88 ▶ $PARAM_UTF8++, next if /^[:-]utf8$/;
Branch: 1 branch
BranchTrueFalseTotal
if /^[:-]utf8$/ 0 88 88
1045 88 ▶ $XHTML++, next if /^[:-]xhtml$/;
Branch: 1 branch
BranchTrueFalseTotal
if /^[:-]xhtml$/ 0 88 88
1046 88 ▶ $XHTML=0, next if /^[:-]no_?xhtml$/;
Branch: 1 branch
BranchTrueFalseTotal
if /^[:-]no_?xhtml$/ 1 87 88
1047 87 ▶ $USE_PARAM_SEMICOLONS=0, next if /^[:-]oldstyle_urls$/;
Branch: 1 branch
BranchTrueFalseTotal
if /^[:-]oldstyle_urls$/ 0 87 87
1048 87 ▶ $TABINDEX++, next if /^[:-]tabindex$/;
Branch: 1 branch
BranchTrueFalseTotal
if /^[:-]tabindex$/ 1 86 87
1049 86 ▶ $CLOSE_UPLOAD_FILES++, next if /^[:-]close_upload_files$/;
Branch: 1 branch
BranchTrueFalseTotal
if /^[:-]close_upload_files$/ 0 86 86
1050 86 ▶ $NO_UNDEF_PARAMS++, next if /^[:-]no_undef_params$/;
Branch: 1 branch
BranchTrueFalseTotal
if /^[:-]no_undef_params$/ 0 86 86
1051
1052 86 for (&expand_tags($_)) {
1053 2380 tr/a-zA-Z0-9_//cd; # don't allow weird function names
1054 2380 $EXPORT{$_}++;
1055 }
1056 }
1057 84 @SAVED_SYMBOLS = @_;
1058 }
1059  
1060 4154 ▶sub charset {
Subroutine charset: called CC=2 SCAR=6.9
Pod undocumented
1061 4154 my ($self,$charset) = self_or_default(@_);
1062 4154 ▶ $self->{'.charset'} = $charset if defined $charset;
Branch: 1 branch
BranchTrueFalseTotal
if defined $charset 2074 2080 4154
1063 4154 $self->{'.charset'};
1064 }
1065  
1066 13 ▶sub element_id {
Subroutine element_id: called CC=2 SCAR=7.1
Pod undocumented
1067 13 my ($self,$new_value) = self_or_default(@_);
1068 13 ▶ $self->{'.elid'} = $new_value if defined $new_value;
Branch: 1 branch
BranchTrueFalseTotal
if defined $new_value 13 0 13
1069 13 sprintf('%010d',$self->{'.elid'}++);
1070 }
1071  
1072 100 ▶sub element_tab {
Subroutine element_tab: called CC=5 SCAR=16.1
Pod undocumented
1073 100 my ($self,$new_value) = self_or_default(@_);
1074 100 ▶ $self->{'.etab'} ||= 1;
Condition100%2/2
$self->{".etab"} ||= 1
l!l
8020
MC/DC100%1/1
$self->{".etab"} ||= 1
$self->{".etab"}
Truth table100%2/2
A
A= $self->{".etab"}
Aresult
11
00
1075 100 ▶ $self->{'.etab'} = $new_value if defined $new_value;
Branch: 1 branch
BranchTrueFalseTotal
if defined $new_value 13 87 100
1076 100 my $tab = $self->{'.etab'}++;
1077 100 ▶ return '' unless $TABINDEX or defined $new_value;
Branch: 1 branch
BranchTrueFalseTotal
unless $TABINDEX or defined $new_value 60 40 100
Condition100%3/3
$TABINDEX or defined $new_value
l!l&&r!l&&!r
271360
MC/DC100%2/2
$TABINDEX or defined $new_value
$TABINDEX defined $new_value
Truth table100%3/3
A or B
A= $TABINDEXB= defined $new_value
ABresult
1X1
011
000
1078 40 return qq(tabindex="$tab" );
1079 }
1080  
1081 #####
1082 # subroutine: read_postdata_putdata
1083 #
1084 # Unless file uploads are disabled
1085 # Reads BODY of POST/PUT request and stuffs it into tempfile
1086 # accessible as param POSTDATA/PUTDATA
1087 #
1088 # Also respects upload_hook
1089 #
1090 # based on subroutine read_multipart_related
1091 #####
1092 22 ▶sub read_postdata_putdata {
Subroutine read_postdata_putdata: called CC=20 SCAR=30.9
Pod undocumented
1093 22 my ( $self, $postOrPut, $content_length, $content_type ) = @_;
1094 22 my %header = (
1095 "Content-Type" => $content_type,
1096 );
1097 22 my $param = $postOrPut;
1098 # add this parameter to our list
1099 22 $self->add_parameter($param);
1100
1101
1102 UPLOADS: {
1103  
1104 # If we get here, then we are dealing with a potentially large
1105 # uploaded form. Save the data to a temporary file, then open
1106 # the file for reading.
1107  
1108 # skip the file if uploads disabled
1109 22 ▶ if ($DISABLE_UPLOADS) {
Branch: 1 branch
BranchTrueFalseTotal
if ($DISABLE_UPLOADS) 8 14 22
1110
1111 8 my $buf;
1112 8 my $unit = $CGI::MultipartBuffer::INITIAL_FILLUNIT;
1113 8 my $len = $content_length;
1114 8 my $ZERO_LOOP_COUNTER = 0;
1115 8 ▶ while ( $len > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len > 0) 14025 4 14029
1116 14025 ▶ my $read = $self->read_from_client( \$buf, $len < $unit ? $len : $unit, 0 );
Branch: 1 branch
BranchTrueFalseTotal
$len < $unit ? : 8010 6015 14025
1117 # a body shorter than CONTENT_LENGTH returns 0 (EOF) or undef
1118 # (error) forever, so guard against spinning as below
1119 14025 ▶ if ( ! $read ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($read) 14004 21 14025
1120 14004 ▶ die "CGI.pm: Server closed socket during read_postdata_putdata (client aborted?).\n" if $ZERO_LOOP_COUNTER++ >= $CGI::MultipartBuffer::SPIN_LOOP_MAX;
Branch: 1 branch
BranchTrueFalseTotal
if $ZERO_LOOP_COUNTER++ >= $CGI::MultipartBuffer::SPIN_LOOP_MAX 4 14000 14004
1121 14000 next;
1122 }
1123 21 $ZERO_LOOP_COUNTER = 0;
1124 21 $len -= $read;
1125 }
1126 4 last UPLOADS;
1127 }
1128  
1129 # SHOULD PROBABLY SKIP THIS IF NOT $self->{'use_tempfile'}
1130 # BUT THE REST OF CGI.PM DOESN'T, SO WHATEVER
1131 my $tmp_dir = $CGI::OS eq 'WINDOWS'
1132 14 ▶ ? ( $ENV{TEMP} || $ENV{TMP} || ( $ENV{WINDIR} ? ( $ENV{WINDIR} . $SL . 'TEMP' ) : undef ) )
Branch: 2 branches
BranchTrueFalseTotal
$OS eq 'WINDOWS' ? : 0 14 14
$ENV{'WINDIR'} ? : 0 0 0
Condition0%0/6
$ENV{"TEMP"} or $ENV{"TMP"} or $ENV{"WINDIR"} ? $ENV{"WINDIR"} . $SL . 'TEMP' : undef
l!l&&r!l&&!r
000
$ENV{"TEMP"} or $ENV{"TMP"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$ENV{"TEMP"} or $ENV{"TMP"} or $ENV{"WINDIR"} ? $ENV{"WINDIR"} . $SL . 'TEMP' : undef
$ENV{"TEMP"} $ENV{"TMP"} $ENV{"WINDIR"} ? $ENV{"WINDIR"} . $SL . 'TEMP' : undef
Truth table0%0/4
A or B or C
A= $ENV{"TEMP"}B= $ENV{"TMP"}C= $ENV{"WINDIR"} ? $ENV{"WINDIR"} . $SL . 'TEMP' : undef
ABCresult
1XX1
01X1
0011
0000
1133 : undef; # File::Temp defaults to TMPDIR
1134  
1135 14 require CGI::File::Temp;
1136 14 my $filehandle = CGI::File::Temp->new(
1137 UNLINK => $UNLINK_TMP_FILES,
1138 DIR => $tmp_dir,
1139 );
1140 14 $filehandle->_mp_filename( $postOrPut );
1141  
1142 14 ▶ $CGI::DefaultClass->binmode($filehandle)
Branch: 1 branch
BranchTrueFalseTotal
if $needs_binmode and defined fileno $filehandle 0 14 14
Condition33%1/3
$needs_binmode and defined fileno $filehandle
!ll&&!rl&&r
1400
MC/DC0%0/2
$needs_binmode and defined fileno $filehandle
$needs_binmode defined fileno $filehandle
Truth table33%1/3
A and B
A= $needs_binmodeB= defined fileno $filehandle
ABresult
0X0
100
111
1143 if $CGI::needs_binmode
1144 && defined fileno($filehandle);
1145  
1146 14 my ($data);
1147 14 local ($\) = '';
1148 14 my $totalbytes;
1149 14 my $unit = $CGI::MultipartBuffer::INITIAL_FILLUNIT;
1150 14 my $len = $content_length;
1151 14 my $ZERO_LOOP_COUNTER =0;
1152  
1153 14 ▶ while( $len > 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ($len > 0) 14031 10 14041
1154 {
1155
1156 # read in chunks (never past CONTENT_LENGTH) rather than slurping
1157 # the whole body into memory at once
1158 14031 ▶ my $bytesRead = $self->read_from_client( \$data, $len < $unit ? $len : $unit, 0 );
Branch: 1 branch
BranchTrueFalseTotal
$len < $unit ? : 8016 6015 14031
1159 14031 $len -= $bytesRead ;
1160  
1161 # An apparent bug in the Apache server causes the read()
1162 # to return zero bytes repeatedly without blocking if the
1163 # remote user aborts during a file transfer. I don't know how
1164 # they manage this, but the workaround is to abort if we get
1165 # more than SPIN_LOOP_MAX consecutive zero reads.
1166 14031 ▶ if ($bytesRead <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bytesRead <= 0) { } 14004 27 14031
1167 14004 ▶ die "CGI.pm: Server closed socket during read_postdata_putdata (client aborted?).\n" if $ZERO_LOOP_COUNTER++ >= $CGI::MultipartBuffer::SPIN_LOOP_MAX;
Branch: 1 branch
BranchTrueFalseTotal
if $ZERO_LOOP_COUNTER++ >= $CGI::MultipartBuffer::SPIN_LOOP_MAX 4 14000 14004
1168 } else {
1169 27 $ZERO_LOOP_COUNTER = 0;
1170 }
1171
1172 14027 ▶ if ( defined $self->{'.upload_hook'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{".upload_hook"}) 18 14009 14027
1173 18 $totalbytes += length($data);
1174 18 &{ $self->{'.upload_hook'} }( $param, $data, $totalbytes,
1175 18 $self->{'.upload_data'} );
1176 }
1177 14027 ▶ print $filehandle $data if ( $self->{'use_tempfile'} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"use_tempfile"} 14027 0 14027
1178 14027 undef $data;
1179 }
1180  
1181 # back up to beginning of file
1182 10 seek( $filehandle, 0, 0 );
1183  
1184 ## Close the filehandle if requested this allows a multipart MIME
1185 ## upload to contain many files, and we won't die due to too many
1186 ## open file handles. The user can access the files using the hash
1187 ## below.
1188 10 ▶ close $filehandle if $CLOSE_UPLOAD_FILES;
Branch: 1 branch
BranchTrueFalseTotal
if $CLOSE_UPLOAD_FILES 0 10 10
1189 10 ▶ $CGI::DefaultClass->binmode($filehandle) if $CGI::needs_binmode;
Branch: 1 branch
BranchTrueFalseTotal
if $needs_binmode 0 10 10
1190  
1191 # Save some information about the uploaded file where we can get
1192 # at it later.
1193 # Use the typeglob + filename as the key, as this is guaranteed to be
1194 # unique for each filehandle. Don't use the file descriptor as
1195 # this will be re-used for each filehandle if the
1196 # close_upload_files feature is used.
1197 10 $self->{'.tmpfiles'}->{$filehandle->filename . $filehandle} = {
1198 hndl => $filehandle,
1199 name => $filehandle->filename,
1200 info => {%header},
1201 };
1202 10 push( @{ $self->{param}{$param} }, $filehandle );
1203 }
1204 14 return;
1205 }
1206  
1207 3 ▶sub URL_ENCODED { 'application/x-www-form-urlencoded'; }
Subroutine URL_ENCODED: called CC=1 SCAR=0.0
Pod undocumented
1208  
1209 28 ▶sub MULTIPART { 'multipart/form-data'; }
Subroutine MULTIPART: called CC=1 SCAR=0.0
Pod undocumented
1210  
1211 6 ▶sub SERVER_PUSH { 'multipart/x-mixed-replace;boundary="' . shift() . '"'; }
Subroutine SERVER_PUSH: called CC=1 SCAR=0.0
Pod undocumented
1212  
1213 # Create a new multipart buffer
1214 1768 ▶sub new_MultipartBuffer {
Subroutine new_MultipartBuffer: called CC=1 SCAR=0.0
Pod undocumented
1215 1768 my($self,$boundary,$length) = @_;
1216 1768 return CGI::MultipartBuffer->new($self,$boundary,$length);
1217 }
1218  
1219 # Read data from a file handle
1220 19131 ▶sub read_from_client {
Subroutine read_from_client: called CC=2 SCAR=7.1
Pod undocumented
1221 19131 my($self, $buff, $len, $offset) = @_;
1222 19131 local $^W=0; # prevent a warning
1223 19131 ▶ return $MOD_PERL
Branch: 1 branch
BranchTrueFalseTotal
$MOD_PERL ? : 0 19131 19131
1224 ? $self->r->read($$buff, $len, $offset)
1225 : read(\*STDIN, $$buff, $len, $offset);
1226 }
1227  
1228 #### Method: delete
1229 # Deletes the named parameter entirely.
1230 ####
1231 4015 ▶sub delete {
Subroutine delete: called CC=3 SCAR=11.0
Pod undocumented
1232 4015 my($self,@p) = self_or_default(@_);
1233 4015 my(@names) = rearrange([NAME],@p);
1234 4015 ▶ my @to_delete = ref($names[0]) eq 'ARRAY' ? @$names[0] : @names;
Branch: 1 branch
BranchTrueFalseTotal
ref $names[0] eq 'ARRAY' ? : 0 4015 4015
1235 4015 my %to_delete;
1236 4015 for my $name (@to_delete)
1237 {
1238 4015 CORE::delete $self->{param}{$name};
1239 4015 CORE::delete $self->{'.fieldnames'}->{$name};
1240 4015 $to_delete{$name}++;
1241 }
1242 4015 @{$self->{'.parameters'}}=grep { !exists($to_delete{$_}) } $self->param();
1243 4015 return;
1244 }
1245  
1246 #### Method: import_names
1247 # Import all parameters into the given namespace.
1248 # Assumes namespace 'Q' if not specified
1249 ####
1250 3 ▶sub import_names {
Subroutine import_names: called CC=9 SCAR=22.1
Pod undocumented
1251 3 my($self,$namespace,$delete) = self_or_default(@_);
1252 3 ▶ $namespace = 'Q' unless defined($namespace);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $namespace 0 3 3
1253 3 ▶ die "Can't import names into \"main\"\n" if \%{"${namespace}::"} == \%::;
Branch: 1 branch
BranchTrueFalseTotal
if \%{"${namespace}::";} == \%main::main:: 1 2 3
1254 2 ▶ if ($delete || $MOD_PERL || exists $ENV{'FCGI_ROLE'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($delete or $MOD_PERL or exists $ENV{"FCGI_ROLE"}) 2 0 2
Condition66%4/6
$delete or $MOD_PERL or exists $ENV{"FCGI_ROLE"}
l!l&&r!l&&!r
110
$delete or $MOD_PERL
l!l&&r!l&&!r
101
MC/DC0%0/3
$delete or $MOD_PERL or exists $ENV{"FCGI_ROLE"}
$delete $MOD_PERL exists $ENV{"FCGI_ROLE"}
Truth table50%2/4
A or B or C
A= $deleteB= $MOD_PERLC= exists $ENV{"FCGI_ROLE"}
ABCresult
1XX1
01X1
0011
0000
1255 # can anyone find an easier way to do this?
1256 2 for (sort keys %{"${namespace}::"}) {
1257 # nested packages (e.g. Config:: for Q::Config) are not imported
1258 # names, and undefining their hash would wipe the whole package
1259 12 ▶ next if /::\z/;
Branch: 1 branch
BranchTrueFalseTotal
if /::\z/ 2 10 12
1260 10 local *symbol = "${namespace}::${_}";
1261 10 undef $symbol;
1262 10 undef @symbol;
1263 10 undef %symbol;
1264 }
1265 }
1266 2 my($param,@value,$var);
1267 2 for $param ($self->param) {
1268 # protect against silly names
1269 8 ($var = $param)=~tr/a-zA-Z0-9_/_/c;
1270 8 $var =~ s/^(?=\d)/_/;
1271 8 local *symbol = "${namespace}::$var";
1272 8 @value = $self->param($param);
1273 8 @symbol = @value;
1274 8 $symbol = $value[0];
1275 }
1276 }
1277  
1278 #### Method: keywords
1279 # Keywords acts a bit differently. Calling it in a list context
1280 # returns the list of keywords.
1281 # Calling it in a scalar context gives you the size of the list.
1282 ####
1283 3 ▶sub keywords {
Subroutine keywords: called CC=3 SCAR=11.3
Pod documented
1284 3 my($self,@values) = self_or_default(@_);
1285 # If values is provided, then we set it.
1286 3 ▶ $self->{param}{'keywords'}=[@values] if @values;
Branch: 1 branch
BranchTrueFalseTotal
if @values 0 3 3
1287 3 ▶ my(@result) = defined($self->{param}{'keywords'}) ? @{$self->{param}{'keywords'}} : ();
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'param'}{'keywords'} ? : 3 0 3
1288 3 @result;
1289 }
1290  
1291 # These are some tie() interfaces for compatibility
1292 # with Steve Brenner's cgi-lib.pl routines
1293 4 ▶sub Vars {
Subroutine Vars: called CC=2 SCAR=7.0
Pod undocumented
1294 4 my $q = shift;
1295 4 my %in;
1296 4 tie(%in,CGI,$q);
1297 4 ▶ return %in if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 0 4 4
1298 4 return \%in;
1299 }
1300  
1301 # These are some tie() interfaces for compatibility
1302 # with Steve Brenner's cgi-lib.pl routines
1303 1 ▶sub ReadParse {
Subroutine ReadParse: called CC=2 SCAR=8.1
Pod undocumented
1304 1 local(*in);
1305 1 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 1 0 1
1306 1 *in = $_[0];
1307 } else {
1308 0 my $pkg = caller();
1309 0 *in=*{"${pkg}::in"};
1310 }
1311 1 tie(%in,CGI);
1312 1 return scalar(keys %in);
1313 }
1314  
1315 1 ▶sub PrintHeader {
Subroutine PrintHeader: called CC=1 SCAR=0.0
Pod undocumented
1316 1 my($self) = self_or_default(@_);
1317 1 return $self->header();
1318 }
1319  
1320 1 ▶sub HtmlTop {
Subroutine HtmlTop: called CC=1 SCAR=0.0
Pod undocumented
1321 1 my($self,@p) = self_or_default(@_);
1322 1 return $self->start_html(@p);
1323 }
1324  
1325 1 ▶sub HtmlBot {
Subroutine HtmlBot: called CC=1 SCAR=0.0
Pod undocumented
1326 1 my($self,@p) = self_or_default(@_);
1327 1 return $self->end_html(@p);
1328 }
1329  
1330 1 ▶sub SplitParam {
Subroutine SplitParam: called CC=2 SCAR=7.1
Pod undocumented
1331 1 my ($param) = @_;
1332 1 my (@params) = split ("\0", $param);
1333 1 ▶ return (wantarray ? @params : $params[0]);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 0 1
1334 }
1335  
1336 1 ▶sub MethGet {
Subroutine MethGet: called CC=1 SCAR=0.0
Pod undocumented
1337 1 return request_method() eq 'GET';
1338 }
1339  
1340 0 ▶sub MethPatch {
Subroutine MethPatch: not called CC=1 SCAR=6.9
Pod undocumented
1341 0 return request_method() eq 'PATCH';
1342 }
1343  
1344 1 ▶sub MethPost {
Subroutine MethPost: called CC=1 SCAR=0.0
Pod undocumented
1345 1 return request_method() eq 'POST';
1346 }
1347  
1348 1 ▶sub MethPut {
Subroutine MethPut: called CC=1 SCAR=0.0
Pod undocumented
1349 1 return request_method() eq 'PUT';
1350 }
1351  
1352 5 ▶sub TIEHASH {
Subroutine TIEHASH: called CC=4 SCAR=14.3
1353 5 my $class = shift;
1354 5 my $arg = $_[0];
1355 5 ▶ if (ref($arg) && UNIVERSAL::isa($arg,'CGI')) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $arg and UNIVERSAL::isa($arg, "CGI")) 4 1 5
Condition66%2/3
ref $arg and UNIVERSAL::isa($arg, "CGI")
!ll&&!rl&&r
104
MC/DC50%1/2
ref $arg and UNIVERSAL::isa($arg, "CGI")
ref $arg UNIVERSAL::isa($arg, "CGI")
Truth table66%2/3
A and B
A= ref $argB= UNIVERSAL::isa($arg, "CGI")
ABresult
0X0
100
111
1356 4 return $arg;
1357 }
1358 1 ▶ return $Q ||= $class->new(@_);
Condition33%1/3
$Q ||= $class->new(@_)
l!l&&r!l&&!r
010
MC/DC0%0/2
$Q ||= $class->new(@_)
$Q $class->new(@_)
Truth table33%1/3
A ||= B
A= $QB= $class->new(@_)
ABresult
1X1
011
000
1359 }
1360  
1361 19 ▶sub STORE {
Subroutine STORE: called CC=3 SCAR=11.0
1362 19 my $self = shift;
1363 19 my $tag = shift;
1364 19 my $vals = shift;
1365 19 ▶ my @vals = defined($vals) && index($vals,"\0")!=-1 ? split("\0",$vals) : $vals;
Branch: 1 branch
BranchTrueFalseTotal
defined $vals && index($vals, "\000") != -1 ? : 1 18 19
Condition66%2/3
defined $vals and index($vals, "\0") != -1
!ll&&!rl&&r
0181
MC/DC50%1/2
defined $vals and index($vals, "\0") != -1
defined $vals index($vals, "\0") != -1
Truth table66%2/3
A and B
A= defined $valsB= index($vals, "\0") != -1
ABresult
0X0
100
111
1366 19 $self->param(-name=>$tag,-value=>\@vals);
1367 }
1368  
1369 37 ▶sub FETCH {
Subroutine FETCH: called CC=3 SCAR=11.1
1370 37 ▶ return $_[0] if $_[1] eq 'CGI';
Branch: 1 branch
BranchTrueFalseTotal
if $_[1] eq "CGI" 0 37 37
1371 37 ▶ return undef unless defined $_[0]->param($_[1]);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0]->param($_[1]) 15 22 37
1372 22 return join("\0",$_[0]->param($_[1]));
1373 }
1374  
1375 2 ▶sub FIRSTKEY {
Subroutine FIRSTKEY: called CC=1 SCAR=0.0
1376 2 $_[0]->{'.iterator'}=0;
1377 2 $_[0]->{'.parameters'}->[$_[0]->{'.iterator'}++];
1378 }
1379  
1380 3 ▶sub NEXTKEY {
Subroutine NEXTKEY: called CC=1 SCAR=0.0
1381 3 $_[0]->{'.parameters'}->[$_[0]->{'.iterator'}++];
1382 }
1383  
1384 2 ▶sub EXISTS {
Subroutine EXISTS: called CC=1 SCAR=0.0
1385 2 exists $_[0]->{param}{$_[1]};
1386 }
1387  
1388 1 ▶sub DELETE {
Subroutine DELETE: called CC=1 SCAR=0.0
1389 1 my ($self, $param) = @_;
1390 1 my $value = $self->FETCH($param);
1391 1 $self->delete($param);
1392 1 return $value;
1393 }
1394  
1395 2 ▶sub CLEAR {
Subroutine CLEAR: called CC=1 SCAR=0.0
1396 2 %{$_[0]}=();
1397 }
1398 ####
1399  
1400 ####
1401 # Append a new value to an existing query
1402 ####
1403 1 ▶sub append {
Subroutine append: called CC=4 SCAR=14.2
Pod undocumented
1404 1 my($self,@p) = self_or_default(@_);
1405 1 my($name,$value) = rearrange([NAME,[VALUE,VALUES]],@p);
1406 1 ▶ my(@values) = defined($value) ? (ref($value) ? @{$value} : $value) : ();
Branch: 2 branches
BranchTrueFalseTotal
defined $value ? : 1 0 1
ref $value ? : 1 0 1
1407 1 ▶ if (@values) {
Branch: 1 branch
BranchTrueFalseTotal
if (@values) 1 0 1
1408 1 $self->add_parameter($name);
1409 1 push(@{$self->{param}{$name}},@values);
1410 }
1411 1 return $self->param($name);
1412 }
1413  
1414 #### Method: delete_all
1415 # Delete all parameters
1416 ####
1417 0 ▶sub delete_all {
Subroutine delete_all: not called CC=1 SCAR=6.9
Pod undocumented
1418 0 my($self) = self_or_default(@_);
1419 0 my @param = $self->param();
1420 0 $self->delete(@param);
1421 }
1422  
1423 2 ▶sub Delete {
Subroutine Delete: called CC=1 SCAR=0.0
Pod undocumented
1424 2 my($self,@p) = self_or_default(@_);
1425 2 $self->delete(@p);
1426 }
1427  
1428 0 ▶sub Delete_all {
Subroutine Delete_all: not called CC=1 SCAR=6.9
Pod undocumented
1429 0 my($self,@p) = self_or_default(@_);
1430 0 $self->delete_all(@p);
1431 }
1432  
1433 #### Method: autoescape
1434 # If you want to turn off the autoescaping features,
1435 # call this method with undef as the argument
1436 14 ▶sub autoEscape {
Subroutine autoEscape: called CC=1 SCAR=0.0
Pod undocumented
1437 14 my($self,$escape) = self_or_default(@_);
1438 14 my $d = $self->{'escape'};
1439 14 $self->{'escape'} = $escape;
1440 14 $d;
1441 }
1442  
1443 #### Method: version
1444 # Return the current version
1445 ####
1446 1 ▶sub version {
Subroutine version: called CC=1 SCAR=0.0
Pod undocumented
1447 1 return $VERSION;
1448 }
1449  
1450 #### Method: url_param
1451 # Return a parameter in the QUERY_STRING, regardless of
1452 # whether this was a POST or a GET
1453 ####
1454 25 ▶sub url_param {
Subroutine url_param: called CC=10 SCAR=23.0
Pod undocumented
1455 25 my ($self,@p) = self_or_default(@_);
1456 25 my $name = shift(@p);
1457 25 ▶ return undef unless exists($ENV{QUERY_STRING});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $ENV{"QUERY_STRING"} 0 25 25
1458 25 ▶ unless (exists($self->{'.url_param'})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{".url_param"}) 19 6 25
1459 19 $self->{'.url_param'}={}; # empty hash
1460 19 ▶ if ($ENV{QUERY_STRING} =~ /=/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{'QUERY_STRING'} =~ /=/) { } 17 2 19
1461 17 my(@pairs) = split(/[&;]/,$ENV{QUERY_STRING});
1462 17 my($param,$value);
1463 17 for (@pairs) {
1464 47 ($param,$value) = split('=',$_,2);
1465 47 ▶ next if ! defined($param);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $param 10 37 47
1466 37 $param = unescape($param);
1467 37 $value = unescape($value);
1468 37 push(@{$self->{'.url_param'}->{$param}},$value);
1469 }
1470 } else {
1471 2 my @keywords = $self->parse_keywordlist($ENV{QUERY_STRING});
1472 2 ▶ $self->{'.url_param'}{'keywords'} = \@keywords if @keywords;
Branch: 1 branch
BranchTrueFalseTotal
if @keywords 1 1 2
1473 }
1474 }
1475 # hash keys are never tainted
1476 25 ▶ return map { $_ . $TAINTED } keys %{$self->{'.url_param'}} unless defined($name);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 6 19 25
1477 19 ▶ return () unless $self->{'.url_param'}->{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{".url_param"}{$name} 0 19 19
1478 1 return wantarray ? @{$self->{'.url_param'}->{$name}}
1479 19 ▶ : $self->{'.url_param'}->{$name}->[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 18 19
1480 }
1481  
1482 #### Method: Dump
1483 # Returns a string in which all the known parameter/value
1484 # pairs are represented as nested lists, mainly for the purposes
1485 # of debugging.
1486 ####
1487 3 ▶sub Dump {
Subroutine Dump: called CC=4 SCAR=13.9
Pod undocumented
1488 3 my($self) = self_or_default(@_);
1489 3 my($param,$value,@result);
1490 3 ▶ return '<ul></ul>' unless $self->param;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->param 1 2 3
1491 2 push(@result,"<ul>");
1492 2 for $param ($self->param) {
1493 2 my($name)=$self->_maybe_escapeHTML($param);
1494 2 push(@result,"<li><strong>$name</strong></li>");
1495 2 push(@result,"<ul>");
1496 2 for $value ($self->param($param)) {
1497 2 $value = $self->_maybe_escapeHTML($value);
1498 2 $value =~ s/\n/<br \/>\n/g;
1499 2 push(@result,"<li>$value</li>");
1500 }
1501 2 push(@result,"</ul>");
1502 }
1503 2 push(@result,"</ul>");
1504 2 return join("\n",@result);
1505 }
1506  
1507 #### Method as_string
1508 #
1509 # synonym for "dump"
1510 ####
1511 1 ▶sub as_string {
Subroutine as_string: called CC=1 SCAR=0.0
Pod undocumented
1512 1 &Dump(@_);
1513 }
1514  
1515 #### Method: save
1516 # Write values out to a filehandle in such a way that they can
1517 # be reinitialized by the filehandle form of the new() method
1518 ####
1519 1 ▶sub save {
Subroutine save: called CC=6 SCAR=17.9
Pod undocumented
1520 1 my($self,$filehandle) = self_or_default(@_);
1521 1 $filehandle = to_filehandle($filehandle);
1522 1 my($param);
1523 1 local($,) = ''; # set print field separator back to a sane value
1524 1 local($\) = ''; # set output line separator to a sane value
1525 1 for $param ($self->param) {
1526 3 my($escaped_param) = escape($param);
1527 3 my($value);
1528 3 for $value ($self->param($param)) {
1529 4 ▶ print $filehandle "$escaped_param=",escape("$value"),"\n"
Branch: 1 branch
BranchTrueFalseTotal
if length $escaped_param or length $value 3 1 4
Condition100%3/3
length $escaped_param or length $value
l!l&&r!l&&!r
211
MC/DC100%2/2
length $escaped_param or length $value
length $escaped_param length $value
Truth table100%3/3
A or B
A= length $escaped_paramB= length $value
ABresult
1X1
011
000
1530 if length($escaped_param) or length($value);
1531 }
1532 }
1533 1 for (sort keys %{$self->{'.fieldnames'}}) {
1534 0 print $filehandle ".cgifields=",escape("$_"),"\n";
1535 }
1536 1 print $filehandle "=\n"; # end of record
1537 }
1538  
1539 #### Method: save_parameters
1540 # An alias for save() that is a better name for exportation.
1541 # Only intended to be used with the function (non-OO) interface.
1542 ####
1543 0 ▶sub save_parameters {
Subroutine save_parameters: not called CC=1 SCAR=6.9
Pod undocumented
1544 0 my $fh = shift;
1545 0 return save(to_filehandle($fh));
1546 }
1547  
1548 #### Method: restore_parameters
1549 # A way to restore CGI parameters from an initializer.
1550 # Only intended to be used with the function (non-OO) interface.
1551 ####
1552 0 ▶sub restore_parameters {
Subroutine restore_parameters: not called CC=1 SCAR=6.9
Pod undocumented
1553 0 $Q = $CGI::DefaultClass->new(@_);
1554 }
1555  
1556 #### Method: multipart_init
1557 # Return a Content-Type: style header for server-push
1558 # This has to be NPH on most web servers, and it is advisable to set $| = 1
1559 #
1560 # Many thanks to Ed Jordan <ed@fidalgo.net> for this
1561 # contribution, updated by Andrew Benham (adsb@bigfoot.com)
1562 ####
1563 6 ▶sub multipart_init {
Subroutine multipart_init: called CC=3 SCAR=11.0
Pod documented
1564 6 my($self,@p) = self_or_default(@_);
1565 6 my($boundary,$charset,@other) = rearrange_header([BOUNDARY,CHARSET],@p);
1566 6 ▶ if (!$boundary) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($boundary) 4 2 6
1567 4 $boundary = '------- =_';
1568 4 my @chrs = ('0'..'9', 'A'..'Z', 'a'..'z');
1569 4 for (1..17) {
1570 68 $boundary .= $chrs[rand(scalar @chrs)];
1571 }
1572 }
1573  
1574 6 $self->{'separator'} = "$CRLF--$boundary$CRLF";
1575 6 $self->{'final_separator'} = "$CRLF--$boundary--$CRLF";
1576 6 $type = SERVER_PUSH($boundary);
1577 return $self->header(
1578 -nph => 0,
1579 -type => $type,
1580 -charset => $charset,
1581 0 (map { split "=", $_, 2 } @other),
1582 ) . "WARNING: YOUR BROWSER DOESN'T SUPPORT THIS SERVER-PUSH TECHNOLOGY." . $self->multipart_end;
1583 }
1584  
1585 #### Method: multipart_start
1586 # Return a Content-Type: style header for server-push, start of section
1587 #
1588 # Many thanks to Ed Jordan <ed@fidalgo.net> for this
1589 # contribution, updated by Andrew Benham (adsb@bigfoot.com)
1590 ####
1591 18 ▶sub multipart_start {
Subroutine multipart_start: called CC=3 SCAR=11.0
Pod documented
1592 18 my(@header);
1593 18 my($self,@p) = self_or_default(@_);
1594 18 my($type,$charset,@other) = _header_params([TYPE,CHARSET],@p);
1595 18 ▶ $type = $type || 'text/html';
Condition100%2/2
$type || 'text/html'
l!l
414
MC/DC100%1/1
$type || 'text/html'
$type
Truth table100%2/2
A
A= $type
Aresult
11
00
1596  
1597 18 _check_header_values($type,$charset,@other);
1598  
1599 15 ▶ if ($charset) {
Branch: 1 branch
BranchTrueFalseTotal
if ($charset) { } 2 13 15
1600 2 push(@header,"Content-Type: $type; charset=$charset");
1601 } else {
1602 13 push(@header,"Content-Type: $type");
1603 }
1604 15 push(@header,@other);
1605 15 my $header = join($CRLF,@header)."${CRLF}${CRLF}";
1606 15 return $header;
1607 }
1608  
1609 # Like rearrange(), but for HTTP headers. rearrange() was designed for HTML
1610 # attributes so it HTML escapes any extra named parameters (when autoEscape
1611 # is on), which used to be unescaped again by the callers - but that also
1612 # decoded entities in values that had never been escaped, turning e.g. an
1613 # app validated header value or redirect URL of "/&#47evil" into "//evil".
1614 # Instead the extra parameters are taken as given and returned, after the
1615 # positional ones, as "Name: value" header lines.
1616 168 ▶sub _header_params {
Subroutine _header_params: called CC=7 SCAR=22.3
1617 168 my ( $order,@param ) = @_;
1618 168 my ( $result,$leftover ) = CGI::Util::_rearrange_params( $order,@param );
1619 168 my @named = @{$result}[ 0 .. $#$order ];
1620 168 my @lines;
1621  
1622 # extra positional parameters, which may be given as name=value
1623 168 for my $line ( @{$result}[ scalar( @$order ) .. $#$result ] ) {
1624 0 ▶ next unless defined $line;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $line 0 0 0
1625 # Don't use \s because of perl bug 21951
1626 0 ▶ if ( my ( $name,$value ) = $line =~ /([^ \r\n\t=]+)=\"?(.+?)\"?$/s ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = $line =~ /([^ \r\n\t=]+)=\"?(.+?)\"?$/s) 0 0 0
1627 0 $line = ucfirst( lc( $name ) ) . ": $value";
1628 }
1629 0 push( @lines,$line );
1630 }
1631  
1632 # extra named parameters, -x_foo => 'bar' becomes "X-foo: bar"
1633 168 ▶ for my $name ( sort keys %{ $leftover || {} } ) {
Condition100%2/2
$leftover || {}
l!l
15612
MC/DC100%1/1
$leftover || {}
$leftover
Truth table100%2/2
A
A= $leftover
Aresult
11
00
1634 92 ▶ next unless defined $leftover->{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $leftover->{$name} 0 92 92
1635 92 ( my $header = lc( $name ) ) =~ tr/_/-/;
1636 92 push( @lines,ucfirst( $header ) . ": $leftover->{$name}" );
1637 }
1638  
1639 168 return ( @named,@lines );
1640 }
1641  
1642 # CR escaping for header values, per RFC 822. Values are modified in
1643 # place (via @_ aliasing) to unfold continuation lines, and we die if
1644 # any other newline remains as that would allow header injection.
1645 172 ▶sub _check_header_values {
Subroutine _check_header_values: called CC=5 SCAR=16.1
1646 172 for my $header (@_) {
1647 1321 ▶ next unless defined $header;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $header 995 326 1321
1648 # From RFC 822:
1649 # Unfolding is accomplished by regarding CRLF immediately
1650 # followed by a LWSP-char as equivalent to the LWSP-char.
1651 326 $header =~ s/$CRLF(\s)/$1/g;
1652  
1653 # All other uses of newlines are invalid input.
1654 326 ▶ if ($header =~ m/$CRLF|\015|\012/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($header =~ /$CRLF|\015|\012/) 18 308 326
1655 # shorten very long values in the diagnostic
1656 18 ▶ $header = substr($header,0,72).'...' if (length $header > 72);
Branch: 1 branch
BranchTrueFalseTotal
if length $header > 72 0 18 18
1657 18 die "Invalid header value contains a newline not followed by whitespace: $header";
1658 }
1659 }
1660 }
1661  
1662 #### Method: multipart_end
1663 # Return a MIME boundary separator for server-push, end of section
1664 #
1665 # Many thanks to Ed Jordan <ed@fidalgo.net> for this
1666 # contribution
1667 ####
1668 6 ▶sub multipart_end {
Subroutine multipart_end: called CC=1 SCAR=0.0
Pod documented
1669 6 my($self,@p) = self_or_default(@_);
1670 6 return $self->{'separator'};
1671 }
1672  
1673 #### Method: multipart_final
1674 # Return a MIME boundary separator for server-push, end of all sections
1675 #
1676 # Contributed by Andrew Benham (adsb@bigfoot.com)
1677 ####
1678 0 ▶sub multipart_final {
Subroutine multipart_final: not called CC=1 SCAR=6.9
Pod documented
1679 0 my($self,@p) = self_or_default(@_);
1680 0 return $self->{'final_separator'} . "WARNING: YOUR BROWSER DOESN'T SUPPORT THIS SERVER-PUSH TECHNOLOGY." . $CRLF;
1681 }
1682  
1683 #### Method: header
1684 # Return a Content-Type: style header
1685 #
1686 ####
1687 150 ▶sub header {
Subroutine header: called CC=32 SCAR=35.1
Pod documented
1688 150 my($self,@p) = self_or_default(@_);
1689 150 my(@header);
1690  
1691 150 ▶ return "" if $self->{'.header_printed'}++ and $HEADERS_ONCE;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{".header_printed"}++ and $HEADERS_ONCE 0 150 150
Condition66%2/3
$self->{".header_printed"}++ and $HEADERS_ONCE
!ll&&!rl&&r
61890
MC/DC0%0/2
$self->{".header_printed"}++ and $HEADERS_ONCE
$self->{".header_printed"}++ $HEADERS_ONCE
Truth table66%2/3
A and B
A= $self->{".header_printed"}++B= $HEADERS_ONCE
ABresult
0X0
100
111
1692  
1693 150 my($type,$status,$cookie,$target,$expires,$nph,$charset,$attachment,$p3p,@other) =
1694 _header_params([['TYPE','CONTENT_TYPE','CONTENT-TYPE'],
1695 'STATUS',['COOKIE','COOKIES','SET-COOKIE'],'TARGET',
1696 'EXPIRES','NPH','CHARSET',
1697 'ATTACHMENT','P3P'],@p);
1698  
1699 # Since $cookie and $p3p may be array references,
1700 # we must stringify them before CR escaping is done.
1701 150 my @cookie;
1702 150 ▶ for (ref($cookie) eq 'ARRAY' ? @{$cookie} : $cookie) {
Branch: 1 branch
BranchTrueFalseTotal
ref $cookie eq 'ARRAY' ? : 6 144 150
1703 155 ▶ my $cs = UNIVERSAL::isa($_,'CGI::Cookie') ? $_->as_string : $_;
Branch: 1 branch
BranchTrueFalseTotal
UNIVERSAL::isa($_, 'CGI::Cookie') ? : 11 144 155
1704 155 ▶ push(@cookie,$cs) if defined $cs and $cs ne '';
Branch: 1 branch
BranchTrueFalseTotal
if defined $cs and $cs ne "" 15 140 155
Condition100%3/3
defined $cs and $cs ne ""
!ll&&!rl&&r
139115
MC/DC100%2/2
defined $cs and $cs ne ""
defined $cs $cs ne ""
Truth table100%3/3
A and B
A= defined $csB= $cs ne ""
ABresult
0X0
100
111
1705 }
1706 150 ▶ $p3p = join ' ',@$p3p if ref($p3p) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $p3p eq "ARRAY" 2 148 150
1707  
1708 150 _check_header_values($type,$status,@cookie,$target,$expires,$nph,$charset,$attachment,$p3p,@other);
1709  
1710 136 ▶ $nph ||= $NPH;
Condition66%2/3
$nph ||= $NPH
l!l&&r!l&&!r
50131
MC/DC50%1/2
$nph ||= $NPH
$nph $NPH
Truth table66%2/3
A ||= B
A= $nphB= $NPH
ABresult
1X1
011
000
1711  
1712 136 ▶ $type ||= 'text/html' unless defined($type);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type 47 89 136
Condition50%1/2
$type ||= "text/html"
l!l
047
MC/DC0%0/1
$type ||= "text/html"
$type
Truth table50%1/2
A
A= $type
Aresult
11
00
1713  
1714 # sets if $charset is given, gets if not
1715 136 $charset = $self->charset( $charset );
1716  
1717 136 ▶ $type .= "; charset=$charset"
Branch: 1 branch
BranchTrueFalseTotal
if $type ne "" and not $type =~ /\bcharset\b/ and defined $charset and $charset ne "" 74 62 136
Condition100%9/9
$type ne "" and not $type =~ /\bcharset\b/ and defined $charset and $charset ne ""
!ll&&!rl&&r
56674
$type ne "" and not $type =~ /\bcharset\b/ and defined $charset
!ll&&!rl&&r
54280
$type ne "" and not $type =~ /\bcharset\b/
!ll&&!rl&&r
312382
MC/DC100%4/4
$type ne "" and not $type =~ /\bcharset\b/ and defined $charset and $charset ne ""
$type ne "" not $type =~ /\bcharset\b/ defined $charset $charset ne ""
Truth table100%5/5
A and not(B) and C and D
A= $type ne ""B= not $type =~ /\bcharset\b/C= defined $charsetD= $charset ne ""
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1718 if $type ne ''
1719 and $type !~ /\bcharset\b/
1720 and defined $charset
1721 and $charset ne '';
1722  
1723 # Maybe future compatibility. Maybe not.
1724 136 ▶ my $protocol = $ENV{SERVER_PROTOCOL} || 'HTTP/1.0';
Condition100%2/2
$ENV{'SERVER_PROTOCOL'} || 'HTTP/1.0'
l!l
7129
MC/DC100%1/1
$ENV{'SERVER_PROTOCOL'} || 'HTTP/1.0'
$ENV{'SERVER_PROTOCOL'}
Truth table100%2/2
A
A= $ENV{'SERVER_PROTOCOL'}
Aresult
11
00
1725 136 ▶ push(@header,$protocol . ' ' . ($status || '200 OK')) if $nph;
Branch: 1 branch
BranchTrueFalseTotal
if $nph 5 131 136
Condition100%2/2
$status || '200 OK'
l!l
32
MC/DC100%1/1
$status || '200 OK'
$status
Truth table100%2/2
A
A= $status
Aresult
11
00
1726 136 ▶ push(@header,"Server: " . &server_software()) if $nph;
Branch: 1 branch
BranchTrueFalseTotal
if $nph 5 131 136
1727  
1728 136 ▶ push(@header,"Status: $status") if $status;
Branch: 1 branch
BranchTrueFalseTotal
if $status 35 101 136
1729 136 ▶ push(@header,"Window-Target: $target") if $target;
Branch: 1 branch
BranchTrueFalseTotal
if $target 1 135 136
1730 136 ▶ push(@header,"P3P: policyref=\"/w3c/p3p.xml\", CP=\"$p3p\"") if $p3p;
Branch: 1 branch
BranchTrueFalseTotal
if $p3p 2 134 136
1731 # push all the cookies -- there may be several
1732 136 push(@header,map {"Set-Cookie: $_"} @cookie);
1733 # if the user indicates an expiration time, then we need
1734 # both an Expires and a Date header (so that the browser is
1735 # uses OUR clock)
1736 136 ▶ push(@header,"Expires: " . expires($expires))
Branch: 1 branch
BranchTrueFalseTotal
if $expires 0 136 136
1737 if $expires;
1738 136 ▶ push(@header,"Date: " . expires(0)) if $expires || $cookie || $nph;
Branch: 1 branch
BranchTrueFalseTotal
if $expires or $cookie or $nph 14 122 136
Condition83%5/6
$expires or $cookie or $nph
l!l&&r!l&&!r
95122
$expires or $cookie
l!l&&r!l&&!r
08128
MC/DC66%2/3
$expires or $cookie or $nph
$expires $cookie $nph
Truth table75%3/4
A or B or C
A= $expiresB= $cookieC= $nph
ABCresult
1XX1
01X1
0011
0000
1739 136 ▶ push(@header,"Pragma: no-cache") if $self->cache();
Branch: 1 branch
BranchTrueFalseTotal
if $self->cache 0 136 136
1740 136 ▶ if ($attachment) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attachment) 11 125 136
1741 # the filename is a quoted-string (RFC 9110 5.6.4), so a " or \ in it
1742 # must be escaped - an unescaped " would end it, allowing other
1743 # parameters to be injected (e.g. 'x.html"; filename*=...')
1744 11 (my $filename = $attachment) =~ s/(["\\])/\\$1/g;
1745 11 push(@header,"Content-Disposition: attachment; filename=\"$filename\"");
1746 }
1747 136 push(@header,map {ucfirst $_} @other);
1748 136 ▶ push(@header,"Content-Type: $type") if $type ne '';
Branch: 1 branch
BranchTrueFalseTotal
if $type ne "" 105 31 136
1749 136 my $header = join($CRLF,@header)."${CRLF}${CRLF}";
1750 136 ▶ if (($MOD_PERL >= 1) && !$nph) {
Branch: 1 branch
BranchTrueFalseTotal
if ($MOD_PERL >= 1 and not $nph) 0 136 136
Condition33%1/3
$MOD_PERL >= 1 and not $nph
!ll&&!rl&&r
13600
MC/DC0%0/2
$MOD_PERL >= 1 and not $nph
$MOD_PERL >= 1 not $nph
Truth table33%1/3
A and not(B)
A= $MOD_PERL >= 1B= not $nph
ABresult
0X0
100
111
1751 0 $self->r->send_cgi_header($header);
1752 0 return '';
1753 }
1754 136 return $header;
1755 }
1756  
1757 #### Method: cache
1758 # Control whether header() will produce the no-cache
1759 # Pragma directive.
1760 ####
1761 136 ▶sub cache {
Subroutine cache: called CC=3 SCAR=12.0
Pod undocumented
1762 136 my($self,$new_value) = self_or_default(@_);
1763 136 ▶ $new_value = '' unless $new_value;
Branch: 1 branch
BranchTrueFalseTotal
unless $new_value 136 0 136
1764 136 ▶ if ($new_value ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($new_value ne "") 0 136 136
1765 0 $self->{'cache'} = $new_value;
1766 }
1767 136 return $self->{'cache'};
1768 }
1769  
1770 #### Method: redirect
1771 # Return a Location: style header
1772 #
1773 ####
1774 37 ▶sub redirect {
Subroutine redirect: called CC=7 SCAR=19.7
Pod undocumented
1775 37 my($self,@p) = self_or_default(@_);
1776 # values are passed on to header() as given - they used to be HTML
1777 # unescaped, which decoded entities in the (possibly app validated)
1778 # Location, e.g. turning "/&#47evil.example/" into "//evil.example/"
1779 37 my ($result,$leftover) = CGI::Util::_rearrange_params(
1780 [[LOCATION,URI,URL],TARGET,STATUS,['COOKIE','COOKIES','SET-COOKIE'],NPH],@p
1781 );
1782 37 my($url,$target,$status,$cookie,$nph,@other) = @$result;
1783 37 ▶ $status = '302 Found' unless defined $status;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $status 35 2 37
1784 37 ▶ $url ||= $self->self_url;
Condition66%2/3
$url ||= $self->self_url
l!l&&r!l&&!r
3430
MC/DC0%0/2
$url ||= $self->self_url
$url $self->self_url
Truth table66%2/3
A ||= B
A= $urlB= $self->self_url
ABresult
1X1
011
000
1785 37 my(@o);
1786 # extra positional parameters, given as name=value
1787 0 for (@other) { tr/\"//d; push(@o,split("=",$_,2)); }
1788 # extra named parameters
1789 37 ▶ push(@o,map { ("-$_" => $leftover->{$_}) } sort keys %{ $leftover || {} });
Condition100%2/2
$leftover || {}
l!l
2413
MC/DC100%1/1
$leftover || {}
$leftover
Truth table100%2/2
A
A= $leftover
Aresult
11
00
1790 37 unshift(@o,
1791 '-Status' => $status,
1792 '-Location'=> $url,
1793 '-nph' => $nph);
1794 37 ▶ unshift(@o,'-Target'=>$target) if $target;
Branch: 1 branch
BranchTrueFalseTotal
if $target 0 37 37
1795 37 unshift(@o,'-Type'=>'');
1796 37 ▶ unshift(@o,'-Cookie'=>$cookie) if $cookie;
Branch: 1 branch
BranchTrueFalseTotal
if $cookie 2 35 37
1797 37 return $self->header(@o);
1798 }
1799  
1800 #### Method: start_html
1801 # Canned HTML header
1802 #
1803 # Parameters:
1804 # $title -> (optional) The title for this HTML document (-title)
1805 # $author -> (optional) e-mail address of the author (-author)
1806 # $base -> (optional) if set to true, will enter the BASE address of this document
1807 # for resolving relative references (-base)
1808 # $xbase -> (optional) alternative base at some remote location (-xbase)
1809 # $target -> (optional) target window to load all links into (-target)
1810 # $script -> (option) Javascript code (-script)
1811 # $no_script -> (option) Javascript <noscript> tag (-noscript)
1812 # $meta -> (optional) Meta information tags
1813 # $head -> (optional) any other elements you'd like to incorporate into the <head> tag
1814 # (a scalar or array ref)
1815 # $style -> (optional) reference to an external style sheet
1816 # @other -> (optional) any other named parameters you'd like to incorporate into
1817 # the <body> tag.
1818 ####
1819 13 ▶sub start_html {
Subroutine start_html: called CC=49 SCAR=47.8
Pod undocumented
1820 13 my($self,@p) = &self_or_default(@_);
1821 13 my($title,$author,$base,$xbase,$script,$noscript,
1822 $target,$meta,$head,$style,$dtd,$lang,$encoding,$declare_xml,@other) =
1823 rearrange([TITLE,AUTHOR,BASE,XBASE,SCRIPT,NOSCRIPT,TARGET,
1824 META,HEAD,STYLE,DTD,LANG,ENCODING,DECLARE_XML],@p);
1825  
1826 13 $self->element_id(0);
1827 13 $self->element_tab(0);
1828  
1829 13 ▶ $encoding = lc($self->charset) unless defined $encoding;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $encoding 13 0 13
1830  
1831 # Need to sort out the DTD before it's okay to call escapeHTML().
1832 13 my(@result,$xml_dtd);
1833 13 ▶ if ($dtd) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dtd) { } 5 8 13
1834 5 ▶ if (defined(ref($dtd)) and (ref($dtd) eq 'ARRAY')) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined ref $dtd and ref $dtd eq 'ARRAY') { } 0 5 5
Condition33%1/3
defined ref $dtd and ref $dtd eq "ARRAY"
!ll&&!rl&&r
050
MC/DC0%0/2
defined ref $dtd and ref $dtd eq "ARRAY"
defined ref $dtd ref $dtd eq "ARRAY"
Truth table33%1/3
A and B
A= defined ref $dtdB= ref $dtd eq "ARRAY"
ABresult
0X0
100
111
1835 0 ▶ $dtd = $DEFAULT_DTD unless $dtd->[0] =~ m|^-//|;
Branch: 1 branch
BranchTrueFalseTotal
unless $dtd->[0] =~ m[^-//] 0 0 0
1836 } else {
1837 5 ▶ $dtd = $DEFAULT_DTD unless $dtd =~ m|^-//|;
Branch: 1 branch
BranchTrueFalseTotal
unless $dtd =~ m[^-//] 0 5 5
1838 }
1839 } else {
1840 8 ▶ $dtd = $XHTML ? $_XHTML_DTD : $DEFAULT_DTD;
Branch: 1 branch
BranchTrueFalseTotal
$XHTML ? : 8 0 8
1841 }
1842  
1843 13 ▶ $xml_dtd++ if ref($dtd) eq 'ARRAY' && $dtd->[0] =~ /\bXHTML\b/i;
Branch: 1 branch
BranchTrueFalseTotal
if ref $dtd eq "ARRAY" and $dtd->[0] =~ /\bXHTML\b/i 8 5 13
Condition66%2/3
ref $dtd eq "ARRAY" and $dtd->[0] =~ /\bXHTML\b/i
!ll&&!rl&&r
508
MC/DC50%1/2
ref $dtd eq "ARRAY" and $dtd->[0] =~ /\bXHTML\b/i
ref $dtd eq "ARRAY" $dtd->[0] =~ /\bXHTML\b/i
Truth table66%2/3
A and B
A= ref $dtd eq "ARRAY"B= $dtd->[0] =~ /\bXHTML\b/i
ABresult
0X0
100
111
1844 13 ▶ $xml_dtd++ if ref($dtd) eq '' && $dtd =~ /\bXHTML\b/i;
Branch: 1 branch
BranchTrueFalseTotal
if ref $dtd eq "" and $dtd =~ /\bXHTML\b/i 0 13 13
Condition66%2/3
ref $dtd eq "" and $dtd =~ /\bXHTML\b/i
!ll&&!rl&&r
850
MC/DC0%0/2
ref $dtd eq "" and $dtd =~ /\bXHTML\b/i
ref $dtd eq "" $dtd =~ /\bXHTML\b/i
Truth table66%2/3
A and B
A= ref $dtd eq ""B= $dtd =~ /\bXHTML\b/i
ABresult
0X0
100
111
1845 13 ▶ push @result,qq(<?xml version="1.0" encoding="$encoding"?>) if $xml_dtd && $declare_xml;
Branch: 1 branch
BranchTrueFalseTotal
if $xml_dtd and $declare_xml 0 13 13
Condition66%2/3
$xml_dtd and $declare_xml
!ll&&!rl&&r
580
MC/DC0%0/2
$xml_dtd and $declare_xml
$xml_dtd $declare_xml
Truth table66%2/3
A and B
A= $xml_dtdB= $declare_xml
ABresult
0X0
100
111
1846  
1847 13 ▶ if (ref($dtd) && ref($dtd) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $dtd and ref $dtd eq 'ARRAY') { } 8 5 13
Condition66%2/3
ref $dtd and ref $dtd eq "ARRAY"
!ll&&!rl&&r
508
MC/DC50%1/2
ref $dtd and ref $dtd eq "ARRAY"
ref $dtd ref $dtd eq "ARRAY"
Truth table66%2/3
A and B
A= ref $dtdB= ref $dtd eq "ARRAY"
ABresult
0X0
100
111
1848 8 push(@result,qq(<!DOCTYPE html\n\tPUBLIC "$dtd->[0]"\n\t "$dtd->[1]">));
1849 8 $DTD_PUBLIC_IDENTIFIER = $dtd->[0];
1850 } else {
1851 5 push(@result,qq(<!DOCTYPE html\n\tPUBLIC "$dtd">));
1852 5 $DTD_PUBLIC_IDENTIFIER = $dtd;
1853 }
1854  
1855 # Now that we know whether we're using the HTML 3.2 DTD or not, it's okay to
1856 # call escapeHTML(). Strangely enough, the title needs to be escaped as
1857 # HTML while the author needs to be escaped as a URL.
1858 13 ▶ $title = $self->_maybe_escapeHTML($title || 'Untitled Document');
Condition100%2/2
$title || 'Untitled Document'
l!l
211
MC/DC100%1/1
$title || 'Untitled Document'
$title
Truth table100%2/2
A
A= $title
Aresult
11
00
1859 13 $author = $self->escape($author);
1860  
1861 13 ▶ if ($DTD_PUBLIC_IDENTIFIER =~ /[^X]HTML (2\.0|3\.2|4\.01?)/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($DTD_PUBLIC_IDENTIFIER =~ /[^X]HTML (2\.0|3\.2|4\.01?)/i) { } 4 9 13
1862 4 ▶ $lang = "" unless defined $lang;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $lang 0 4 4
1863 4 $XHTML = 0;
1864 }
1865 else {
1866 9 ▶ $lang = 'en-US' unless defined $lang;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $lang 8 1 9
1867 }
1868  
1869 13 ▶ my $lang_bits = $lang ne '' ? qq( lang="$lang" xml:lang="$lang") : '';
Branch: 1 branch
BranchTrueFalseTotal
$lang ne '' ? : 13 0 13
1870 13 ▶ my $meta_bits = qq(<meta http-equiv="Content-Type" content="text/html; charset=$encoding" />)
Branch: 1 branch
BranchTrueFalseTotal
if $XHTML and $encoding and not $declare_xml 7 6 13
Condition83%5/6
$XHTML and $encoding and not $declare_xml
!ll&&!rl&&r
607
$XHTML and $encoding
!ll&&!rl&&r
427
MC/DC66%2/3
$XHTML and $encoding and not $declare_xml
$XHTML $encoding not $declare_xml
Truth table75%3/4
A and B and not(C)
A= $XHTMLB= $encodingC= not $declare_xml
ABCresult
0XX0
10X0
1100
1111
1871 if $XHTML && $encoding && !$declare_xml;
1872  
1873 13 ▶ push(@result,$XHTML ? qq(<html xmlns="http://www.w3.org/1999/xhtml"$lang_bits>\n<head>\n<title>$title</title>)
Branch: 2 branches
BranchTrueFalseTotal
$XHTML ? : 9 4 13
$lang ? : 4 0 4
1874 : ($lang ? qq(<html lang="$lang">) : "<html>")
1875 . "<head><title>$title</title>");
1876 13 ▶ if (defined $author) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $author) 0 13 13
1877 0 ▶ push(@result,$XHTML ? "<link rev=\"made\" href=\"mailto:$author\" />"
Branch: 1 branch
BranchTrueFalseTotal
$XHTML ? : 0 0 0
1878 : "<link rev=\"made\" href=\"mailto:$author\">");
1879 }
1880  
1881 13 ▶ if ($base || $xbase || $target) {
Branch: 1 branch
BranchTrueFalseTotal
if ($base or $xbase or $target) 1 12 13
Condition66%4/6
$base or $xbase or $target
l!l&&r!l&&!r
1012
$base or $xbase
l!l&&r!l&&!r
1012
MC/DC33%1/3
$base or $xbase or $target
$base $xbase $target
Truth table50%2/4
A or B or C
A= $baseB= $xbaseC= $target
ABCresult
1XX1
01X1
0011
0000
1882 1 ▶ my $href = $xbase || $self->url('-path'=>1);
Condition33%1/3
$xbase || $self->url('-path', 1)
l!l&&r!l&&!r
010
MC/DC0%0/2
$xbase || $self->url('-path', 1)
$xbase $self->url('-path', 1)
Truth table33%1/3
A || B
A= $xbaseB= $self->url('-path', 1)
ABresult
1X1
011
000
1883 1 ▶ my $t = $target ? qq/ target="$target"/ : '';
Branch: 1 branch
BranchTrueFalseTotal
$target ? : 0 1 1
1884 1 ▶ push(@result,$XHTML ? qq(<base href="$href"$t />) : qq(<base href="$href"$t>));
Branch: 1 branch
BranchTrueFalseTotal
$XHTML ? : 1 0 1
1885 }
1886  
1887 13 ▶ if ($meta && ref($meta) && (ref($meta) eq 'HASH')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($meta and ref $meta and ref $meta eq "HASH") 2 11 13
Condition66%4/6
$meta and ref $meta and ref $meta eq "HASH"
!ll&&!rl&&r
1102
$meta and ref $meta
!ll&&!rl&&r
1102
MC/DC33%1/3
$meta and ref $meta and ref $meta eq "HASH"
$meta ref $meta ref $meta eq "HASH"
Truth table50%2/4
A and B and C
A= $metaB= ref $metaC= ref $meta eq "HASH"
ABCresult
0XX0
10X0
1100
1111
1888 2 ▶ for (sort keys %$meta) { push(@result,$XHTML ? qq(<meta name="$_" content="$meta->{$_}" />)
Branch: 1 branch
BranchTrueFalseTotal
$XHTML ? : 11 0 11
1889 : qq(<meta name="$_" content="$meta->{$_}">)); }
1890 }
1891  
1892 13 my $meta_bits_set = 0;
1893 13 ▶ if( $head ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($head) 0 13 13
1894 0 ▶ if( ref $head ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $head) { } 0 0 0
1895 0 push @result, @$head;
1896 0 ▶ $meta_bits_set = 1 if grep { /http-equiv=["']Content-Type/i }@$head;
Branch: 1 branch
BranchTrueFalseTotal
if grep {/http-equiv=["']Content-Type/i;} @$head 0 0 0
1897 }
1898 else {
1899 0 push @result, $head;
1900 0 ▶ $meta_bits_set = 1 if $head =~ /http-equiv=["']Content-Type/i;
Branch: 1 branch
BranchTrueFalseTotal
if $head =~ /http-equiv=["']Content-Type/i 0 0 0
1901 }
1902 }
1903  
1904 # handle the infrequently-used -style and -script parameters
1905 13 ▶ push(@result,$self->_style($style)) if defined $style;
Branch: 1 branch
BranchTrueFalseTotal
if defined $style 0 13 13
1906 13 ▶ push(@result,$self->_script($script)) if defined $script;
Branch: 1 branch
BranchTrueFalseTotal
if defined $script 1 12 13
1907 13 ▶ push(@result,$meta_bits) if defined $meta_bits and !$meta_bits_set;
Branch: 1 branch
BranchTrueFalseTotal
if defined $meta_bits and not $meta_bits_set 7 6 13
Condition66%2/3
defined $meta_bits and not $meta_bits_set
!ll&&!rl&&r
607
MC/DC50%1/2
defined $meta_bits and not $meta_bits_set
defined $meta_bits not $meta_bits_set
Truth table66%2/3
A and not(B)
A= defined $meta_bitsB= not $meta_bits_set
ABresult
0X0
100
111
1908  
1909 # handle -noscript parameter
1910 13 ▶ push(@result,<<END) if $noscript;
Branch: 1 branch
BranchTrueFalseTotal
if $noscript 0 13 13
1911 <noscript>
1912 $noscript
1913 </noscript>
1914 END
1915 ;
1916 13 ▶ my($other) = @other ? " @other" : '';
Branch: 1 branch
BranchTrueFalseTotal
@other ? : 0 13 13
1917 13 push(@result,"</head>\n<body$other>\n");
1918 13 return join("\n",@result);
1919 }
1920  
1921 ### Method: _style
1922 # internal method for generating a CSS style section
1923 ####
1924 1 ▶sub _style {
Subroutine _style: called CC=23 SCAR=53.7
1925 1 my ($self,$style) = @_;
1926 1 my (@result);
1927  
1928 1 my $type = 'text/css';
1929 1 my $rel = 'stylesheet';
1930  
1931  
1932 1 ▶ my $cdata_start = $XHTML ? "\n<!--/* <![CDATA[ */" : "\n<!-- ";
Branch: 1 branch
BranchTrueFalseTotal
$XHTML ? : 1 0 1
1933 1 ▶ my $cdata_end = $XHTML ? "\n/* ]]> */-->\n" : " -->\n";
Branch: 1 branch
BranchTrueFalseTotal
$XHTML ? : 1 0 1
1934  
1935 1 ▶ my @s = ref($style) eq 'ARRAY' ? @$style : $style;
Branch: 1 branch
BranchTrueFalseTotal
ref $style eq 'ARRAY' ? : 0 1 1
1936 1 my $other = '';
1937  
1938 1 for my $s (@s) {
1939 1 ▶ if (ref($s)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $s) { } 0 1 1
1940 0 ▶ my($src,$code,$verbatim,$stype,$alternate,$foo,@other) =
Branch: 1 branch
BranchTrueFalseTotal
ref $s eq 'ARRAY' ? : 0 0 0
1941 rearrange([qw(SRC CODE VERBATIM TYPE ALTERNATE FOO)],
1942 ('-foo'=>'bar',
1943 ref($s) eq 'ARRAY' ? @$s : %$s));
1944 0 ▶ my $type = defined $stype ? $stype : 'text/css';
Branch: 1 branch
BranchTrueFalseTotal
defined $stype ? : 0 0 0
1945 0 ▶ my $rel = $alternate ? 'alternate stylesheet' : 'stylesheet';
Branch: 1 branch
BranchTrueFalseTotal
$alternate ? : 0 0 0
1946 0 ▶ $other = "@other" if @other;
Branch: 1 branch
BranchTrueFalseTotal
if @other 0 0 0
1947  
1948 0 ▶ if (ref($src) eq "ARRAY") # Check to see if the $src variable is an array reference
Branch: 1 branch
BranchTrueFalseTotal
if (ref $src eq 'ARRAY') { } 0 0 0
1949 { # If it is, push a LINK tag for each one
1950 0 for $src (@$src)
1951 {
1952 0 ▶ push(@result,$XHTML ? qq(<link rel="$rel" type="$type" href="$src" $other/>)
Branch: 2 branches
BranchTrueFalseTotal
if $src 0 0 0
$XHTML ? : 0 0 0
1953 : qq(<link rel="$rel" type="$type" href="$src"$other>)) if $src;
1954 }
1955 }
1956 else
1957 { # Otherwise, push the single -src, if it exists.
1958 0 ▶ push(@result,$XHTML ? qq(<link rel="$rel" type="$type" href="$src" $other/>)
Branch: 2 branches
BranchTrueFalseTotal
if $src 0 0 0
$XHTML ? : 0 0 0
1959 : qq(<link rel="$rel" type="$type" href="$src"$other>)
1960 ) if $src;
1961 }
1962 0 ▶ if ($verbatim) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verbatim) 0 0 0
1963 0 ▶ my @v = ref($verbatim) eq 'ARRAY' ? @$verbatim : $verbatim;
Branch: 1 branch
BranchTrueFalseTotal
ref $verbatim eq 'ARRAY' ? : 0 0 0
1964 0 push(@result, "<style type=\"text/css\">\n$_\n</style>") for @v;
1965 }
1966 0 ▶ if ($code) {
Branch: 1 branch
BranchTrueFalseTotal
if ($code) 0 0 0
1967 0 ▶ my @c = ref($code) eq 'ARRAY' ? @$code : $code;
Branch: 1 branch
BranchTrueFalseTotal
ref $code eq 'ARRAY' ? : 0 0 0
1968 0 push(@result,style({'type'=>$type},"$cdata_start\n$_\n$cdata_end")) for @c;
1969 }
1970  
1971 } else {
1972 1 my $src = $s;
1973 1 ▶ push(@result,$XHTML ? qq(<link rel="$rel" type="$type" href="$src" $other/>)
Branch: 1 branch
BranchTrueFalseTotal
$XHTML ? : 1 0 1
1974 : qq(<link rel="$rel" type="$type" href="$src"$other>));
1975 }
1976 }
1977 1 @result;
1978 }
1979  
1980 1 ▶sub _script {
Subroutine _script: called CC=15 SCAR=32.3
1981 1 my ($self,$script) = @_;
1982 1 my (@result);
1983  
1984 1 ▶ my (@scripts) = ref($script) eq 'ARRAY' ? @$script : ($script);
Branch: 1 branch
BranchTrueFalseTotal
ref $script eq 'ARRAY' ? : 1 0 1
1985 1 for $script (@scripts) {
1986 1 my($src,$code,$language,$charset);
1987 1 ▶ if (ref($script)) { # script is a hash
Branch: 1 branch
BranchTrueFalseTotal
if (ref $script) { } 1 0 1
1988 1 ▶ ($src,$code,$type,$charset) =
Branch: 1 branch
BranchTrueFalseTotal
ref $script eq 'ARRAY' ? : 0 1 1
1989 rearrange(['SRC','CODE',['LANGUAGE','TYPE'],'CHARSET'],
1990 '-foo'=>'bar', # a trick to allow the '-' to be omitted
1991 ref($script) eq 'ARRAY' ? @$script : %$script);
1992 1 ▶ $type ||= 'text/javascript';
Condition50%1/2
$type ||= "text/javascript"
l!l
01
MC/DC0%0/1
$type ||= "text/javascript"
$type
Truth table50%1/2
A
A= $type
Aresult
11
00
1993 1 ▶ unless ($type =~ m!\w+/\w+!) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($type =~ m[\w+/\w+]) 0 1 1
1994 0 $type =~ s/[\d.]+$//;
1995 0 $type = "text/$type";
1996 }
1997 } else {
1998 0 ($src,$code,$type,$charset) = ('',$script, 'text/javascript', '');
1999 }
2000  
2001 1 my $comment = '//'; # javascript by default
2002 1 ▶ $comment = '#' if $type=~/perl|tcl/i;
Branch: 1 branch
BranchTrueFalseTotal
if $type =~ /perl|tcl/i 0 1 1
2003 1 ▶ $comment = "'" if $type=~/vbscript/i;
Branch: 1 branch
BranchTrueFalseTotal
if $type =~ /vbscript/i 0 1 1
2004  
2005 1 my ($cdata_start,$cdata_end);
2006 1 ▶ if ($XHTML) {
Branch: 1 branch
BranchTrueFalseTotal
if ($XHTML) { } 1 0 1
2007 1 $cdata_start = "$comment<![CDATA[\n";
2008 1 $cdata_end .= "\n$comment]]>";
2009 } else {
2010 0 $cdata_start = "\n<!-- Hide script\n";
2011 0 $cdata_end = $comment;
2012 0 $cdata_end .= " End script hiding -->\n";
2013 }
2014 1 my(@satts);
2015 1 ▶ push(@satts,'src'=>$src) if $src;
Branch: 1 branch
BranchTrueFalseTotal
if $src 1 0 1
2016 1 push(@satts,'type'=>$type);
2017 1 ▶ push(@satts,'charset'=>$charset) if ($src && $charset);
Branch: 1 branch
BranchTrueFalseTotal
if $src and $charset 1 0 1
Condition33%1/3
$src and $charset
!ll&&!rl&&r
001
MC/DC0%0/2
$src and $charset
$src $charset
Truth table33%1/3
A and B
A= $srcB= $charset
ABresult
0X0
100
111
2018 1 ▶ $code = $cdata_start . $code . $cdata_end if defined $code;
Branch: 1 branch
BranchTrueFalseTotal
if defined $code 0 1 1
2019 1 ▶ push(@result,$self->script({@satts},$code || ''));
Condition50%1/2
$code || ''
l!l
01
MC/DC0%0/1
$code || ''
$code
Truth table50%1/2
A
A= $code
Aresult
11
00
2020 }
2021 1 @result;
2022 }
2023  
2024 #### Method: end_html
2025 # End an HTML document.
2026 # Trivial method for completeness. Just returns "</body>"
2027 ####
2028 3 ▶sub end_html {
Subroutine end_html: called CC=1 SCAR=0.0
Pod undocumented
2029 3 return "\n</body>\n</html>";
2030 }
2031  
2032 ################################
2033 # METHODS USED IN BUILDING FORMS
2034 ################################
2035  
2036 #### Method: isindex
2037 # Just prints out the isindex tag.
2038 # Parameters:
2039 # $action -> optional URL of script to run
2040 # Returns:
2041 # A string containing a <isindex> tag
2042 0 ▶sub isindex {
Subroutine isindex: not called CC=4 SCAR=30.0
Pod undocumented
2043 0 my($self,@p) = self_or_default(@_);
2044 0 my($action,@other) = rearrange([ACTION],@p);
2045 0 ▶ $action = qq/ action="$action"/ if $action;
Branch: 1 branch
BranchTrueFalseTotal
if $action 0 0 0
2046 0 ▶ my($other) = @other ? " @other" : '';
Branch: 1 branch
BranchTrueFalseTotal
@other ? : 0 0 0
2047 0 ▶ return $XHTML ? "<isindex$action$other />" : "<isindex$action$other>";
Branch: 1 branch
BranchTrueFalseTotal
$XHTML ? : 0 0 0
2048 }
2049  
2050 #### Method: start_form
2051 # Start a form
2052 # Parameters:
2053 # $method -> optional submission method to use (GET or POST)
2054 # $action -> optional URL of script to run
2055 # $enctype ->encoding to use (URL_ENCODED or MULTIPART)
2056 31 ▶sub start_form {
Subroutine start_form: called CC=8 SCAR=20.9
Pod undocumented
2057 31 my($self,@p) = self_or_default(@_);
2058  
2059 31 my($method,$action,$enctype,@other) =
2060 rearrange([METHOD,ACTION,ENCTYPE],@p);
2061  
2062 31 ▶ $method = $self->_maybe_escapeHTML(lc($method || 'post'));
Condition100%2/2
$method || 'post'
l!l
1120
MC/DC100%1/1
$method || 'post'
$method
Truth table100%2/2
A
A= $method
Aresult
11
00
2063  
2064 31 ▶ if( $XHTML ){
Branch: 1 branch
BranchTrueFalseTotal
if ($XHTML) { } 26 5 31
2065 26 ▶ $enctype = $self->_maybe_escapeHTML($enctype || &MULTIPART);
Condition66%2/3
$enctype || &MULTIPART
l!l&&r!l&&!r
4220
MC/DC0%0/2
$enctype || &MULTIPART
$enctype &MULTIPART
Truth table66%2/3
A || B
A= $enctypeB= &MULTIPART
ABresult
1X1
011
000
2066 }else{
2067 5 ▶ $enctype = $self->_maybe_escapeHTML($enctype || &URL_ENCODED);
Condition66%2/3
$enctype || &URL_ENCODED
l!l&&r!l&&!r
410
MC/DC0%0/2
$enctype || &URL_ENCODED
$enctype &URL_ENCODED
Truth table66%2/3
A || B
A= $enctypeB= &URL_ENCODED
ABresult
1X1
011
000
2068 }
2069  
2070 31 ▶ if (defined $action) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $action) { } 12 19 31
2071 12 $action = $self->_maybe_escapeHTML($action);
2072 }
2073 else {
2074 19 ▶ $action = $self->_maybe_escapeHTML($self->_request_uri_path || $self->self_url);
Condition66%2/3
$self->_request_uri_path || $self->self_url
l!l&&r!l&&!r
1810
MC/DC0%0/2
$self->_request_uri_path || $self->self_url
$self->_request_uri_path $self->self_url
Truth table66%2/3
A || B
A= $self->_request_uri_pathB= $self->self_url
ABresult
1X1
011
000
2075 }
2076 31 $action = qq(action="$action");
2077 31 ▶ my($other) = @other ? " @other" : '';
Branch: 1 branch
BranchTrueFalseTotal
@other ? : 3 28 31
2078 31 $self->{'.parametersToAdd'}={};
2079 31 return qq/<form method="$method" $action enctype="$enctype"$other>/;
2080 }
2081  
2082 #### Method: start_multipart_form
2083 4 ▶sub start_multipart_form {
Subroutine start_multipart_form: called CC=3 SCAR=12.7
Pod undocumented
2084 4 my($self,@p) = self_or_default(@_);
2085 4 ▶ if (defined($p[0]) && substr($p[0],0,1) eq '-') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $p[0] and substr($p[0], 0, 1) eq '-') { } 0 4 4
Condition33%1/3
defined $p[0] and substr($p[0], 0, 1) eq "-"
!ll&&!rl&&r
040
MC/DC0%0/2
defined $p[0] and substr($p[0], 0, 1) eq "-"
defined $p[0] substr($p[0], 0, 1) eq "-"
Truth table33%1/3
A and B
A= defined $p[0]B= substr($p[0], 0, 1) eq "-"
ABresult
0X0
100
111
2086 0 return $self->start_form(-enctype=>&MULTIPART,@p);
2087 } else {
2088 4 my($method,$action,@other) =
2089 rearrange([METHOD,ACTION],@p);
2090 4 return $self->start_form($method,$action,&MULTIPART,@other);
2091 }
2092 }
2093  
2094 #### Method: end_form
2095 # End a form
2096 # Note: This repeated below under the older name.
2097 1 ▶sub end_form {
Subroutine end_form: called CC=5 SCAR=22.7
Pod undocumented
2098 1 my($self,@p) = self_or_default(@_);
2099 1 ▶ if ( $NOSTICKY ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($NOSTICKY) { } 0 1 1
2100 0 ▶ return wantarray ? ("</form>") : "\n</form>";
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
2101 } else {
2102 1 ▶ if (my @fields = $self->get_fields) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@fields) = $self->get_fields) { } 0 1 1
2103 0 ▶ return wantarray ? ("<div>",@fields,"</div>","</form>")
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
2104 : "<div>".(join '',@fields)."</div>\n</form>";
2105 } else {
2106 1 return "</form>";
2107 }
2108 }
2109 }
2110  
2111 #### Method: end_multipart_form
2112 # end a multipart form
2113 0 ▶sub end_multipart_form {
Subroutine end_multipart_form: not called CC=1 SCAR=6.9
Pod undocumented
2114 0 &end_form;
2115 }
2116  
2117 8 ▶sub _textfield {
Subroutine _textfield: called CC=10 SCAR=23.5
2118 8 my($self,$tag,@p) = self_or_default(@_);
2119 8 my($name,$default,$size,$maxlength,$override,$tabindex,@other) =
2120 rearrange([NAME,[DEFAULT,VALUE,VALUES],SIZE,MAXLENGTH,[OVERRIDE,FORCE],TABINDEX],@p);
2121  
2122 8 ▶ my $current = $override ? $default :
Branch: 2 branches
BranchTrueFalseTotal
$override ? : 2 6 8
defined $self->param($name) ? : 4 2 6
2123 (defined($self->param($name)) ? $self->param($name) : $default);
2124  
2125 8 ▶ $current = defined($current) ? $self->_maybe_escapeHTML($current,1) : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $current ? : 8 0 8
2126 8 ▶ $name = defined($name) ? $self->_maybe_escapeHTML($name) : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $name ? : 6 2 8
2127 8 ▶ my($s) = defined($size) ? qq/ size="$size"/ : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $size ? : 0 8 8
2128 8 ▶ my($m) = defined($maxlength) ? qq/ maxlength="$maxlength"/ : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $maxlength ? : 0 8 8
2129 8 ▶ my($other) = @other ? " @other" : '';
Branch: 1 branch
BranchTrueFalseTotal
@other ? : 2 6 8
2130 # this entered at cristy's request to fix problems with file upload fields
2131 # and WebTV -- not sure it won't break stuff
2132 8 ▶ my($value) = $current ne '' ? qq(value="$current") : '';
Branch: 1 branch
BranchTrueFalseTotal
$current ne '' ? : 8 0 8
2133 8 $tabindex = $self->element_tab($tabindex);
2134 8 ▶ return $XHTML ? qq(<input type="$tag" name="$name" $tabindex$value$s$m$other />)
Branch: 1 branch
BranchTrueFalseTotal
$XHTML ? : 8 0 8
2135 : qq(<input type="$tag" name="$name" $value$s$m$other>);
2136 }
2137  
2138 #### Method: textfield
2139 # Parameters:
2140 # $name -> Name of the text field
2141 # $default -> Optional default value of the field if not
2142 # already defined.
2143 # $size -> Optional width of field in characaters.
2144 # $maxlength -> Optional maximum number of characters.
2145 # Returns:
2146 # A string containing a <input type="text"> field
2147 #
2148 7 ▶sub textfield {
Subroutine textfield: called CC=1 SCAR=0.0
Pod undocumented
2149 7 my($self,@p) = self_or_default(@_);
2150 7 $self->_textfield('text',@p);
2151 }
2152  
2153 #### Method: filefield
2154 # Parameters:
2155 # $name -> Name of the file upload field
2156 # $size -> Optional width of field in characaters.
2157 # $maxlength -> Optional maximum number of characters.
2158 # Returns:
2159 # A string containing a <input type="file"> field
2160 #
2161 0 ▶sub filefield {
Subroutine filefield: not called CC=1 SCAR=6.9
Pod undocumented
2162 0 my($self,@p) = self_or_default(@_);
2163 0 $self->_textfield('file',@p);
2164 }
2165  
2166 #### Method: password
2167 # Create a "secret password" entry field
2168 # Parameters:
2169 # $name -> Name of the field
2170 # $default -> Optional default value of the field if not
2171 # already defined.
2172 # $size -> Optional width of field in characters.
2173 # $maxlength -> Optional maximum characters that can be entered.
2174 # Returns:
2175 # A string containing a <input type="password"> field
2176 #
2177 1 ▶sub password_field {
Subroutine password_field: called CC=1 SCAR=0.0
Pod undocumented
2178 1 my ($self,@p) = self_or_default(@_);
2179 1 $self->_textfield('password',@p);
2180 }
2181  
2182 #### Method: textarea
2183 # Parameters:
2184 # $name -> Name of the text field
2185 # $default -> Optional default value of the field if not
2186 # already defined.
2187 # $rows -> Optional number of rows in text area
2188 # $columns -> Optional number of columns in text area
2189 # Returns:
2190 # A string containing a <textarea></textarea> tag
2191 #
2192 2 ▶sub textarea {
Subroutine textarea: called CC=8 SCAR=22.0
Pod undocumented
2193 2 my($self,@p) = self_or_default(@_);
2194 2 my($name,$default,$rows,$cols,$override,$tabindex,@other) =
2195 rearrange([NAME,[DEFAULT,VALUE],ROWS,[COLS,COLUMNS],[OVERRIDE,FORCE],TABINDEX],@p);
2196  
2197 2 ▶ my($current)= $override ? $default :
Branch: 2 branches
BranchTrueFalseTotal
$override ? : 0 2 2
defined $self->param($name) ? : 0 2 2
2198 (defined($self->param($name)) ? $self->param($name) : $default);
2199  
2200 2 ▶ $name = defined($name) ? $self->_maybe_escapeHTML($name) : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $name ? : 2 0 2
2201 2 ▶ $current = defined($current) ? $self->_maybe_escapeHTML($current) : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $current ? : 2 0 2
2202 2 ▶ my($r) = $rows ? qq/ rows="$rows"/ : '';
Branch: 1 branch
BranchTrueFalseTotal
$rows ? : 2 0 2
2203 2 ▶ my($c) = $cols ? qq/ cols="$cols"/ : '';
Branch: 1 branch
BranchTrueFalseTotal
$cols ? : 2 0 2
2204 2 ▶ my($other) = @other ? " @other" : '';
Branch: 1 branch
BranchTrueFalseTotal
@other ? : 1 1 2
2205 2 $tabindex = $self->element_tab($tabindex);
2206 2 return qq{<textarea name="$name" $tabindex$r$c$other>$current</textarea>};
2207 }
2208  
2209 #### Method: button
2210 # Create a javascript button.
2211 # Parameters:
2212 # $name -> (optional) Name for the button. (-name)
2213 # $value -> (optional) Value of the button when selected (and visible name) (-value)
2214 # $onclick -> (optional) Text of the JavaScript to run when the button is
2215 # clicked.
2216 # Returns:
2217 # A string containing a <input type="button"> tag
2218 ####
2219 4 ▶sub button {
Subroutine button: called CC=8 SCAR=20.8
Pod undocumented
2220 4 my($self,@p) = self_or_default(@_);
2221  
2222 4 my($label,$value,$script,$tabindex,@other) = rearrange([NAME,[VALUE,LABEL],
2223 [ONCLICK,SCRIPT],TABINDEX],@p);
2224  
2225 4 $label=$self->_maybe_escapeHTML($label);
2226 4 $value=$self->_maybe_escapeHTML($value,1);
2227 4 $script=$self->_maybe_escapeHTML($script);
2228  
2229 4 ▶ $script ||= '';
Condition100%2/2
$script ||= ""
l!l
13
MC/DC100%1/1
$script ||= ""
$script
Truth table100%2/2
A
A= $script
Aresult
11
00
2230  
2231 4 my($name) = '';
2232 4 ▶ $name = qq/ name="$label"/ if $label;
Branch: 1 branch
BranchTrueFalseTotal
if $label 3 1 4
2233 4 ▶ $value = $value || $label;
Condition66%2/3
$value || $label
l!l&&r!l&&!r
031
MC/DC50%1/2
$value || $label
$value $label
Truth table66%2/3
A || B
A= $valueB= $label
ABresult
1X1
011
000
2234 4 my($val) = '';
2235 4 ▶ $val = qq/ value="$value"/ if $value;
Branch: 1 branch
BranchTrueFalseTotal
if $value 3 1 4
2236 4 ▶ $script = qq/ onclick="$script"/ if $script;
Branch: 1 branch
BranchTrueFalseTotal
if $script 1 3 4
2237 4 ▶ my($other) = @other ? " @other" : '';
Branch: 1 branch
BranchTrueFalseTotal
@other ? : 1 3 4
2238 4 $tabindex = $self->element_tab($tabindex);
2239 4 ▶ return $XHTML ? qq(<input type="button" $tabindex$name$val$script$other />)
Branch: 1 branch
BranchTrueFalseTotal
$XHTML ? : 4 0 4
2240 : qq(<input type="button"$name$val$script$other>);
2241 }
2242  
2243 #### Method: submit
2244 # Create a "submit query" button.
2245 # Parameters:
2246 # $name -> (optional) Name for the button.
2247 # $value -> (optional) Value of the button when selected (also doubles as label).
2248 # $label -> (optional) Label printed on the button(also doubles as the value).
2249 # Returns:
2250 # A string containing a <input type="submit"> tag
2251 ####
2252 7 ▶sub submit {
Subroutine submit: called CC=7 SCAR=19.5
Pod undocumented
2253 7 my($self,@p) = self_or_default(@_);
2254  
2255 7 my($label,$value,$tabindex,@other) = rearrange([NAME,[VALUE,LABEL],TABINDEX],@p);
2256  
2257 7 $label=$self->_maybe_escapeHTML($label);
2258 7 $value=$self->_maybe_escapeHTML($value,1);
2259  
2260 7 ▶ my $name = $NOSTICKY ? '' : 'name=".submit" ';
Branch: 1 branch
BranchTrueFalseTotal
$NOSTICKY ? : 0 7 7
2261 7 ▶ $name = qq/name="$label" / if defined($label);
Branch: 1 branch
BranchTrueFalseTotal
if defined $label 5 2 7
2262 7 ▶ $value = defined($value) ? $value : $label;
Branch: 1 branch
BranchTrueFalseTotal
defined $value ? : 5 2 7
2263 7 my $val = '';
2264 7 ▶ $val = qq/value="$value" / if defined($value);
Branch: 1 branch
BranchTrueFalseTotal
if defined $value 5 2 7
2265 7 $tabindex = $self->element_tab($tabindex);
2266 7 ▶ my($other) = @other ? "@other " : '';
Branch: 1 branch
BranchTrueFalseTotal
@other ? : 1 6 7
2267 7 ▶ return $XHTML ? qq(<input type="submit" $tabindex$name$val$other/>)
Branch: 1 branch
BranchTrueFalseTotal
$XHTML ? : 7 0 7
2268 : qq(<input type="submit" $name$val$other>);
2269 }
2270  
2271 #### Method: reset
2272 # Create a "reset" button.
2273 # Parameters:
2274 # $name -> (optional) Name for the button.
2275 # Returns:
2276 # A string containing a <input type="reset"> tag
2277 ####
2278 0 ▶sub reset {
Subroutine reset: not called CC=6 SCAR=37.4
Pod undocumented
2279 0 my($self,@p) = self_or_default(@_);
2280 0 my($label,$value,$tabindex,@other) = rearrange(['NAME',['VALUE','LABEL'],TABINDEX],@p);
2281 0 $label=$self->_maybe_escapeHTML($label);
2282 0 $value=$self->_maybe_escapeHTML($value,1);
2283 0 my ($name) = ' name=".reset"';
2284 0 ▶ $name = qq/ name="$label"/ if defined($label);
Branch: 1 branch
BranchTrueFalseTotal
if defined $label 0 0 0
2285 0 ▶ $value = defined($value) ? $value : $label;
Branch: 1 branch
BranchTrueFalseTotal
defined $value ? : 0 0 0
2286 0 my($val) = '';
2287 0 ▶ $val = qq/ value="$value"/ if defined($value);
Branch: 1 branch
BranchTrueFalseTotal
if defined $value 0 0 0
2288 0 ▶ my($other) = @other ? " @other" : '';
Branch: 1 branch
BranchTrueFalseTotal
@other ? : 0 0 0
2289 0 $tabindex = $self->element_tab($tabindex);
2290 0 ▶ return $XHTML ? qq(<input type="reset" $tabindex$name$val$other />)
Branch: 1 branch
BranchTrueFalseTotal
$XHTML ? : 0 0 0
2291 : qq(<input type="reset"$name$val$other>);
2292 }
2293  
2294 #### Method: defaults
2295 # Create a "defaults" button.
2296 # Parameters:
2297 # $name -> (optional) Name for the button.
2298 # Returns:
2299 # A string containing a <input type="submit" name=".defaults"> tag
2300 #
2301 # Note: this button has a special meaning to the initialization script,
2302 # and tells it to ERASE the current query string so that your defaults
2303 # are used again!
2304 ####
2305 0 ▶sub defaults {
Subroutine defaults: not called CC=4 SCAR=30.0
Pod undocumented
2306 0 my($self,@p) = self_or_default(@_);
2307  
2308 0 my($label,$tabindex,@other) = rearrange([[NAME,VALUE],TABINDEX],@p);
2309  
2310 0 $label=$self->_maybe_escapeHTML($label,1);
2311 0 ▶ $label = $label || "Defaults";
Condition0%0/2
$label || 'Defaults'
l!l
00
MC/DC0%0/1
$label || 'Defaults'
$label
Truth table0%0/2
A
A= $label
Aresult
11
00
2312 0 my($value) = qq/ value="$label"/;
2313 0 ▶ my($other) = @other ? " @other" : '';
Branch: 1 branch
BranchTrueFalseTotal
@other ? : 0 0 0
2314 0 $tabindex = $self->element_tab($tabindex);
2315 0 ▶ return $XHTML ? qq(<input type="submit" name=".defaults" $tabindex$value$other />)
Branch: 1 branch
BranchTrueFalseTotal
$XHTML ? : 0 0 0
2316 : qq/<input type="submit" NAME=".defaults"$value$other>/;
2317 }
2318  
2319 #### Method: comment
2320 # Create an HTML <!-- comment -->
2321 # Parameters: a string
2322 16 ▶sub comment {
Subroutine comment: called CC=2 SCAR=6.9
Pod undocumented
2323 16 my($self,@p) = self_or_CGI(@_);
2324 16 my $text = "@p";
2325 # the text must not be able to end the comment ("-->", "--!>") or start
2326 # a nested one ("<!--"), all of which contain "--" - the surrounding
2327 # spaces deal with the other cases the HTML spec disallows
2328 16 ▶ 1 while $text =~ s/--/- -/g;
Branch: 1 branch
BranchTrueFalseTotal
$text =~ s/--/- -/g and do { '???' } 11 16 27
2329 16 return "<!-- $text -->";
2330 }
2331  
2332 #### Method: checkbox
2333 # Create a checkbox that is not logically linked to any others.
2334 # The field value is "on" when the button is checked.
2335 # Parameters:
2336 # $name -> Name of the checkbox
2337 # $checked -> (optional) turned on by default if true
2338 # $value -> (optional) value of the checkbox, 'on' by default
2339 # $label -> (optional) a user-readable label printed next to the box.
2340 # Otherwise the checkbox name is used.
2341 # Returns:
2342 # A string containing a <input type="checkbox"> field
2343 ####
2344 9 ▶sub checkbox {
Subroutine checkbox: called CC=9 SCAR=22.0
Pod undocumented
2345 9 my($self,@p) = self_or_default(@_);
2346  
2347 9 my($name,$checked,$value,$label,$labelattributes,$override,$tabindex,@other) =
2348 rearrange([NAME,[CHECKED,SELECTED,ON],VALUE,LABEL,LABELATTRIBUTES,
2349 [OVERRIDE,FORCE],TABINDEX],@p);
2350  
2351 9 ▶ $value = defined $value ? $value : 'on';
Branch: 1 branch
BranchTrueFalseTotal
defined $value ? : 9 0 9
2352  
2353 9 ▶ if (!$override && ($self->{'.fieldnames'}->{$name} ||
Branch: 1 branch
BranchTrueFalseTotal
if (not $override and $self->{'.fieldnames'}{$name} || defined $self->param($name)) { } 6 3 9
Condition83%5/6
not $override and $self->{".fieldnames"}{$name} || defined $self->param($name)
!ll&&!rl&&r
216
$self->{".fieldnames"}{$name} or defined $self->param($name)
l!l&&r!l&&!r
061
MC/DC66%2/3
not $override and $self->{".fieldnames"}{$name} || defined $self->param($name)
not $override $self->{".fieldnames"}{$name} defined $self->param($name)
Truth table75%3/4
not(A) and B or C
A= not $overrideB= $self->{".fieldnames"}{$name}C= defined $self->param($name)
ABCresult
0XX0
1000
11X1
1011
2354 defined $self->param($name))) {
2355 6 ▶ $checked = grep($_ eq $value,$self->param($name)) ? $self->_checked(1) : '';
Branch: 1 branch
BranchTrueFalseTotal
grep(($_ eq $value), $self->param($name)) ? : 2 4 6
2356 } else {
2357 3 $checked = $self->_checked($checked);
2358 }
2359 9 ▶ my($the_label) = defined $label ? $label : $name;
Branch: 1 branch
BranchTrueFalseTotal
defined $label ? : 7 2 9
2360 9 $name = $self->_maybe_escapeHTML($name);
2361 9 $value = $self->_maybe_escapeHTML($value,1);
2362 9 $the_label = $self->_maybe_escapeHTML($the_label);
2363 9 ▶ my($other) = @other ? "@other " : '';
Branch: 1 branch
BranchTrueFalseTotal
@other ? : 1 8 9
2364 9 $tabindex = $self->element_tab($tabindex);
2365 9 $self->register_parameter($name);
2366 9 ▶ return $XHTML ? CGI::label($labelattributes,
Branch: 1 branch
BranchTrueFalseTotal
$XHTML ? : 9 0 9
2367 qq{<input type="checkbox" name="$name" value="$value" $tabindex$checked$other/>$the_label})
2368 : qq{<input type="checkbox" name="$name" value="$value"$checked$other>$the_label};
2369 }
2370  
2371 # Escape HTML
2372 361 ▶sub escapeHTML {
Subroutine escapeHTML: called CC=6 SCAR=17.9
Pod undocumented
2373 361 require HTML::Entities;
2374 # hack to work around earlier hacks
2375 361 ▶ push @_,$_[0] if @_==1 && $_[0] eq 'CGI';
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 and $_[0] eq "CGI" 1 360 361
Condition100%3/3
@_ == 1 and $_[0] eq "CGI"
!ll&&!rl&&r
35461
MC/DC100%2/2
@_ == 1 and $_[0] eq "CGI"
@_ == 1 $_[0] eq "CGI"
Truth table100%3/3
A and B
A= @_ == 1B= $_[0] eq "CGI"
ABresult
0X0
100
111
2376 361 my ($self,$toencode,$newlinestoo) = CGI::self_or_default(@_);
2377 361 ▶ return undef unless defined($toencode);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $toencode 0 361 361
2378 361 my $encode_entities = $ENCODE_ENTITIES;
2379 361 ▶ $encode_entities .= "\012\015" if ( $encode_entities && $newlinestoo );
Branch: 1 branch
BranchTrueFalseTotal
if $encode_entities and $newlinestoo 104 257 361
Condition100%3/3
$encode_entities and $newlinestoo
!ll&&!rl&&r
1256104
MC/DC100%2/2
$encode_entities and $newlinestoo
$encode_entities $newlinestoo
Truth table100%3/3
A and B
A= $encode_entitiesB= $newlinestoo
ABresult
0X0
100
111
2380 361 return HTML::Entities::encode_entities($toencode,$encode_entities);
2381 }
2382  
2383 # unescape HTML -- used internally
2384 20 ▶sub unescapeHTML {
Subroutine unescapeHTML: called CC=4 SCAR=15.2
Pod undocumented
2385 20 require HTML::Entities;
2386 # hack to work around earlier hacks
2387 20 ▶ push @_,$_[0] if @_==1 && $_[0] eq 'CGI';
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 and $_[0] eq "CGI" 0 20 20
Condition33%1/3
@_ == 1 and $_[0] eq "CGI"
!ll&&!rl&&r
0200
MC/DC0%0/2
@_ == 1 and $_[0] eq "CGI"
@_ == 1 $_[0] eq "CGI"
Truth table33%1/3
A and B
A= @_ == 1B= $_[0] eq "CGI"
ABresult
0X0
100
111
2388 20 my ($self,$string) = CGI::self_or_default(@_);
2389 20 ▶ return undef unless defined($string);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $string 0 20 20
2390 20 return HTML::Entities::decode_entities($string);
2391 }
2392  
2393 # Internal procedure - don't use
2394 1 ▶sub _tableize {
Subroutine _tableize: called CC=15 SCAR=29.5
2395 1 my($rows,$columns,$rowheaders,$colheaders,@elements) = @_;
2396 1 ▶ my @rowheaders = $rowheaders ? @$rowheaders : ();
Branch: 1 branch
BranchTrueFalseTotal
$rowheaders ? : 0 1 1
2397 1 ▶ my @colheaders = $colheaders ? @$colheaders : ();
Branch: 1 branch
BranchTrueFalseTotal
$colheaders ? : 0 1 1
2398 1 my($result);
2399  
2400 1 ▶ if (defined($columns)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $columns) 1 0 1
2401 1 ▶ $rows = int(0.99 + @elements/$columns) unless defined($rows);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rows 0 1 1
2402 }
2403 1 ▶ if (defined($rows)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $rows) 1 0 1
2404 1 ▶ $columns = int(0.99 + @elements/$rows) unless defined($columns);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $columns 0 1 1
2405 }
2406  
2407 # rearrange into a pretty table
2408 1 $result = "<table>";
2409 1 my($row,$column);
2410 1 ▶ unshift(@colheaders,'') if @colheaders && @rowheaders;
Branch: 1 branch
BranchTrueFalseTotal
if @colheaders and @rowheaders 0 1 1
Condition33%1/3
@colheaders and @rowheaders
!ll&&!rl&&r
100
MC/DC0%0/2
@colheaders and @rowheaders
@colheaders @rowheaders
Truth table33%1/3
A and B
A= @colheadersB= @rowheaders
ABresult
0X0
100
111
2411 1 ▶ $result .= "<tr>" if @colheaders;
Branch: 1 branch
BranchTrueFalseTotal
if @colheaders 0 1 1
2412 1 for (@colheaders) {
2413 0 $result .= "<th>$_</th>";
2414 }
2415 1 ▶ for ($row=0;$row<$rows;$row++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($row < $rows) 2 1 3
2416 2 $result .= "<tr>";
2417 2 ▶ $result .= "<th>$rowheaders[$row]</th>" if @rowheaders;
Branch: 1 branch
BranchTrueFalseTotal
if @rowheaders 0 2 2
2418 2 ▶ for ($column=0;$column<$columns;$column++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($column < $columns) 4 2 6
2419 4 ▶ $result .= "<td>" . $elements[$column*$rows + $row] . "</td>"
Branch: 1 branch
BranchTrueFalseTotal
if defined $elements[$column * $rows + $row] 4 0 4
2420 if defined($elements[$column*$rows + $row]);
2421 }
2422 2 $result .= "</tr>";
2423 }
2424 1 $result .= "</table>";
2425 1 return $result;
2426 }
2427  
2428 #### Method: radio_group
2429 # Create a list of logically-linked radio buttons.
2430 # Parameters:
2431 # $name -> Common name for all the buttons.
2432 # $values -> A pointer to a regular array containing the
2433 # values for each button in the group.
2434 # $default -> (optional) Value of the button to turn on by default. Pass '-'
2435 # to turn _nothing_ on.
2436 # $linebreak -> (optional) Set to true to place linebreaks
2437 # between the buttons.
2438 # $labels -> (optional)
2439 # A pointer to a hash of labels to print next to each checkbox
2440 # in the form $label{'value'}="Long explanatory label".
2441 # Otherwise the provided values are used as the labels.
2442 # Returns:
2443 # An ARRAY containing a series of <input type="radio"> fields
2444 ####
2445 5 ▶sub radio_group {
Subroutine radio_group: called CC=1 SCAR=0.0
Pod undocumented
2446 5 my($self,@p) = self_or_default(@_);
2447 5 $self->_box_group('radio',@p);
2448 }
2449  
2450 #### Method: checkbox_group
2451 # Create a list of logically-linked checkboxes.
2452 # Parameters:
2453 # $name -> Common name for all the check boxes
2454 # $values -> A pointer to a regular array containing the
2455 # values for each checkbox in the group.
2456 # $defaults -> (optional)
2457 # 1. If a pointer to a regular array of checkbox values,
2458 # then this will be used to decide which
2459 # checkboxes to turn on by default.
2460 # 2. If a scalar, will be assumed to hold the
2461 # value of a single checkbox in the group to turn on.
2462 # $linebreak -> (optional) Set to true to place linebreaks
2463 # between the buttons.
2464 # $labels -> (optional)
2465 # A pointer to a hash of labels to print next to each checkbox
2466 # in the form $label{'value'}="Long explanatory label".
2467 # Otherwise the provided values are used as the labels.
2468 # Returns:
2469 # An ARRAY containing a series of <input type="checkbox"> fields
2470 ####
2471  
2472 8 ▶sub checkbox_group {
Subroutine checkbox_group: called CC=1 SCAR=0.0
Pod undocumented
2473 8 my($self,@p) = self_or_default(@_);
2474 8 $self->_box_group('checkbox',@p);
2475 }
2476  
2477 13 ▶sub _box_group {
Subroutine _box_group: called CC=26 SCAR=34.6
2478 13 my $self = shift;
2479 13 my $box_type = shift;
2480  
2481 13 my($name,$values,$defaults,$linebreak,$labels,$labelattributes,
2482 $attributes,$rows,$columns,$rowheaders,$colheaders,
2483 $override,$nolabels,$tabindex,$disabled,@other) =
2484 rearrange([NAME,[VALUES,VALUE],[DEFAULT,DEFAULTS],LINEBREAK,LABELS,LABELATTRIBUTES,
2485 ATTRIBUTES,ROWS,[COLUMNS,COLS],[ROWHEADERS,ROWHEADER],[COLHEADERS,COLHEADER],
2486 [OVERRIDE,FORCE],NOLABELS,TABINDEX,DISABLED
2487 ],@_);
2488  
2489  
2490 13 my($result,$checked,@elements,@values);
2491  
2492 13 @values = $self->_set_values_and_labels($values,\$labels,$name);
2493 13 my %checked = $self->previous_or_default($name,$defaults,$override);
2494  
2495 # If no check array is specified, check the first by default
2496 13 ▶ $checked{$values[0]}++ if $box_type eq 'radio' && !%checked;
Branch: 1 branch
BranchTrueFalseTotal
if $box_type eq "radio" and not %checked 1 12 13
Condition100%3/3
$box_type eq "radio" and not %checked
!ll&&!rl&&r
841
MC/DC100%2/2
$box_type eq "radio" and not %checked
$box_type eq "radio" not %checked
Truth table100%3/3
A and not(B)
A= $box_type eq "radio"B= not %checked
ABresult
0X0
100
111
2497  
2498 13 $name=$self->_maybe_escapeHTML($name);
2499  
2500 13 my %tabs = ();
2501 13 ▶ if ($TABINDEX && $tabindex) {
Branch: 1 branch
BranchTrueFalseTotal
if ($TABINDEX and $tabindex) 0 13 13
Condition66%2/3
$TABINDEX and $tabindex
!ll&&!rl&&r
850
MC/DC0%0/2
$TABINDEX and $tabindex
$TABINDEX $tabindex
Truth table66%2/3
A and B
A= $TABINDEXB= $tabindex
ABresult
0X0
100
111
2502 0 ▶ if (!ref $tabindex) {
Branch: 3 branches
BranchTrueFalseTotal
if (not ref $tabindex) { } 0 0 0
elsif (ref $tabindex eq 'ARRAY') { } 0 0 0
elsif (ref $tabindex eq 'HASH') { } 0 0 0
2503 0 $self->element_tab($tabindex);
2504 } elsif (ref $tabindex eq 'ARRAY') {
2505 0 %tabs = map {$_=>$self->element_tab} @$tabindex;
2506 } elsif (ref $tabindex eq 'HASH') {
2507 0 %tabs = %$tabindex;
2508 }
2509 }
2510 13 ▶ %tabs = map {$_=>$self->element_tab} @values unless %tabs;
Branch: 1 branch
BranchTrueFalseTotal
unless %tabs 13 0 13
2511 13 ▶ my $other = @other ? "@other " : '';
Branch: 1 branch
BranchTrueFalseTotal
@other ? : 2 11 13
2512 13 my $radio_checked;
2513  
2514 # for disabling groups of radio/checkbox buttons
2515 my %disabled;
2516 13 for (@{$disabled}) {
2517 1 $disabled{$_}=1;
2518 }
2519  
2520 13 for (@values) {
2521 37 my $disable="";
2522 37 ▶ if ($disabled{$_}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($disabled{$_}) 1 36 37
2523 1 $disable="disabled='1'";
2524 }
2525  
2526 my $checkit = $self->_checked($box_type eq 'radio' ? ($checked{$_} && !$radio_checked++)
2527 37 ▶ : $checked{$_});
Branch: 1 branch
BranchTrueFalseTotal
$box_type eq 'radio' ? : 12 25 37
Condition100%3/3
$checked{$_} and not $radio_checked++
!ll&&!rl&&r
345
MC/DC100%2/2
$checked{$_} and not $radio_checked++
$checked{$_} not $radio_checked++
Truth table100%3/3
A and not(B)
A= $checked{$_}B= not $radio_checked++
ABresult
0X0
100
111
2528 37 my($break);
2529 37 ▶ if ($linebreak) {
Branch: 1 branch
BranchTrueFalseTotal
if ($linebreak) { } 4 33 37
2530 4 ▶ $break = $XHTML ? "<br />" : "<br>";
Branch: 1 branch
BranchTrueFalseTotal
$XHTML ? : 4 0 4
2531 }
2532 else {
2533 33 $break = '';
2534 }
2535 37 my($label)='';
2536 37 ▶ unless (defined($nolabels) && $nolabels) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $nolabels and $nolabels) 37 0 37
Condition33%1/3
defined $nolabels and $nolabels
!ll&&!rl&&r
3700
MC/DC0%0/2
defined $nolabels and $nolabels
defined $nolabels $nolabels
Truth table33%1/3
A and B
A= defined $nolabelsB= $nolabels
ABresult
0X0
100
111
2537 37 $label = $_;
2538 37 ▶ $label = $labels->{$_} if defined($labels) && defined($labels->{$_});
Branch: 1 branch
BranchTrueFalseTotal
if defined $labels and defined $labels->{$_} 2 35 37
Condition100%3/3
defined $labels and defined $labels->{$_}
!ll&&!rl&&r
3322
MC/DC100%2/2
defined $labels and defined $labels->{$_}
defined $labels defined $labels->{$_}
Truth table100%3/3
A and B
A= defined $labelsB= defined $labels->{$_}
ABresult
0X0
100
111
2539 37 $label = $self->_maybe_escapeHTML($label,1);
2540 37 ▶ $label = "<span style=\"color:gray\">$label</span>" if $disabled{$_};
Branch: 1 branch
BranchTrueFalseTotal
if $disabled{$_} 1 36 37
2541 }
2542 37 my $attribs = $self->_set_attributes($_, $attributes);
2543 37 my $tab = $tabs{$_};
2544 37 $_=$self->_maybe_escapeHTML($_);
2545  
2546 37 ▶ if ($XHTML) {
Branch: 1 branch
BranchTrueFalseTotal
if ($XHTML) { } 34 3 37
2547 34 push @elements,
2548 CGI::label($labelattributes,
2549 qq(<input type="$box_type" name="$name" value="$_" $checkit$other$tab$attribs$disable/>$label)).${break};
2550 } else {
2551 3 push(@elements,qq/<input type="$box_type" name="$name" value="$_" $checkit$other$tab$attribs$disable>${label}${break}/);
2552 }
2553 }
2554 13 $self->register_parameter($name);
2555 13 ▶ return wantarray ? @elements : "@elements"
Branch: 2 branches
BranchTrueFalseTotal
unless defined $columns or defined $rows 12 1 13
wantarray ? : 0 12 12
Condition66%2/3
defined $columns or defined $rows
l!l&&r!l&&!r
1012
MC/DC50%1/2
defined $columns or defined $rows
defined $columns defined $rows
Truth table66%2/3
A or B
A= defined $columnsB= defined $rows
ABresult
1X1
011
000
2556 unless defined($columns) || defined($rows);
2557 1 return _tableize($rows,$columns,$rowheaders,$colheaders,@elements);
2558 }
2559  
2560 #### Method: popup_menu
2561 # Create a popup menu.
2562 # Parameters:
2563 # $name -> Name for all the menu
2564 # $values -> A pointer to a regular array containing the
2565 # text of each menu item.
2566 # $default -> (optional) Default item to display
2567 # $labels -> (optional)
2568 # A pointer to a hash of labels to print next to each checkbox
2569 # in the form $label{'value'}="Long explanatory label".
2570 # Otherwise the provided values are used as the labels.
2571 # Returns:
2572 # A string containing the definition of a popup menu.
2573 ####
2574 8 ▶sub popup_menu {
Subroutine popup_menu: called CC=14 SCAR=26.6
Pod undocumented
2575 8 my($self,@p) = self_or_default(@_);
2576  
2577 8 my($name,$values,$default,$labels,$attributes,$override,$tabindex,@other) =
2578 rearrange([NAME,[VALUES,VALUE],[DEFAULT,DEFAULTS],LABELS,
2579 ATTRIBUTES,[OVERRIDE,FORCE],TABINDEX],@p);
2580 8 my($result,%selected);
2581  
2582 8 ▶ if (!$override && defined($self->param($name))) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $override and defined $self->param($name)) { } 0 8 8
elsif (defined $default) { } 7 1 8
Condition66%2/3
not $override and defined $self->param($name)
!ll&&!rl&&r
260
MC/DC0%0/2
not $override and defined $self->param($name)
not $override defined $self->param($name)
Truth table66%2/3
not(A) and B
A= not $overrideB= defined $self->param($name)
ABresult
0X0
100
111
2583 0 $selected{$self->param($name)}++;
2584 } elsif (defined $default) {
2585 7 ▶ %selected = map {$_=>1} ref($default) eq 'ARRAY'
Branch: 1 branch
BranchTrueFalseTotal
ref $default eq 'ARRAY' ? : 0 7 7
2586 ? @$default
2587 : $default;
2588 }
2589 8 $name=$self->_maybe_escapeHTML($name);
2590 # RT #30057 - ignore -multiple, if you need this
2591 # then use scrolling_list
2592 8 @other = grep { $_ !~ /^multiple=/i } @other;
2593 8 ▶ my($other) = @other ? " @other" : '';
Branch: 1 branch
BranchTrueFalseTotal
@other ? : 2 6 8
2594  
2595 8 my(@values);
2596 8 @values = $self->_set_values_and_labels($values,\$labels,$name);
2597 8 $tabindex = $self->element_tab($tabindex);
2598 8 ▶ $name = q{} if ! defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 1 7 8
2599 8 $result = qq/<select name="$name" $tabindex$other>\n/;
2600 8 for (@values) {
2601 22 ▶ if (/<optgroup/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/<optgroup/) { } 3 19 22
2602 3 for my $v (split(/\n/)) {
2603 11 ▶ my $selectit = $XHTML ? 'selected="selected"' : 'selected';
Branch: 1 branch
BranchTrueFalseTotal
$XHTML ? : 11 0 11
2604 11 for my $selected (sort keys %selected) {
2605 11 $v =~ s/(value="\Q$selected\E")/$selectit $1/;
2606 }
2607 11 $result .= "$v\n";
2608 }
2609 }
2610 else {
2611 19 my $attribs = $self->_set_attributes($_, $attributes);
2612 19 my($selectit) = $self->_selected($selected{$_});
2613 19 my($label) = $_;
2614 19 ▶ $label = $labels->{$_} if defined($labels) && defined($labels->{$_});
Branch: 1 branch
BranchTrueFalseTotal
if defined $labels and defined $labels->{$_} 6 13 19
Condition66%2/3
defined $labels and defined $labels->{$_}
!ll&&!rl&&r
1306
MC/DC50%1/2
defined $labels and defined $labels->{$_}
defined $labels defined $labels->{$_}
Truth table66%2/3
A and B
A= defined $labelsB= defined $labels->{$_}
ABresult
0X0
100
111
2615 19 my($value) = $self->_maybe_escapeHTML($_);
2616 19 $label = $self->_maybe_escapeHTML($label,1);
2617 19 $result .= "<option${attribs} ${selectit}value=\"$value\">$label</option>\n";
2618 }
2619 }
2620  
2621 8 $result .= "</select>";
2622 8 return $result;
2623 }
2624  
2625 #### Method: optgroup
2626 # Create a optgroup.
2627 # Parameters:
2628 # $name -> Label for the group
2629 # $values -> A pointer to a regular array containing the
2630 # values for each option line in the group.
2631 # $labels -> (optional)
2632 # A pointer to a hash of labels to print next to each item
2633 # in the form $label{'value'}="Long explanatory label".
2634 # Otherwise the provided values are used as the labels.
2635 # $labeled -> (optional)
2636 # A true value indicates the value should be used as the label attribute
2637 # in the option elements.
2638 # The label attribute specifies the option label presented to the user.
2639 # This defaults to the content of the <option> element, but the label
2640 # attribute allows authors to more easily use optgroup without sacrificing
2641 # compatibility with browsers that do not support option groups.
2642 # $novals -> (optional)
2643 # A true value indicates to suppress the val attribute in the option elements
2644 # Returns:
2645 # A string containing the definition of an option group.
2646 ####
2647 14 ▶sub optgroup {
Subroutine optgroup: called CC=11 SCAR=24.0
Pod undocumented
2648 14 my($self,@p) = self_or_default(@_);
2649 14 my($name,$values,$attributes,$labeled,$novals,$labels,@other)
2650 = rearrange([NAME,[VALUES,VALUE],ATTRIBUTES,LABELED,NOVALS,LABELS],@p);
2651  
2652 14 my($result,@values);
2653 14 @values = $self->_set_values_and_labels($values,\$labels,$name,$labeled,$novals);
2654 14 ▶ my($other) = @other ? " @other" : '';
Branch: 1 branch
BranchTrueFalseTotal
@other ? : 1 13 14
2655  
2656 14 ▶ $name = $self->_maybe_escapeHTML($name) || q{};
Condition100%2/2
$self->_maybe_escapeHTML($name) || ''
l!l
122
MC/DC100%1/1
$self->_maybe_escapeHTML($name) || ''
$self->_maybe_escapeHTML($name)
Truth table100%2/2
A
A= $self->_maybe_escapeHTML($name)
Aresult
11
00
2657 14 $result = qq/<optgroup label="$name"$other>\n/;
2658 14 for (@values) {
2659 24 ▶ if (/<optgroup/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/<optgroup/) { } 2 22 24
2660 # a nested optgroup, passed through as is (there used to be code
2661 # here to mark a selected value, using a $selected that was never
2662 # set - unlike popup_menu() / scrolling_list(), optgroup() doesn't
2663 # know which values are selected)
2664 2 $result .= "$_\n" for split(/\n/);
2665 }
2666 else {
2667 22 my $attribs = $self->_set_attributes($_, $attributes);
2668 22 my($label) = $_;
2669 22 ▶ $label = $labels->{$_} if defined($labels) && defined($labels->{$_});
Branch: 1 branch
BranchTrueFalseTotal
if defined $labels and defined $labels->{$_} 1 21 22
Condition100%3/3
defined $labels and defined $labels->{$_}
!ll&&!rl&&r
2011
MC/DC100%2/2
defined $labels and defined $labels->{$_}
defined $labels defined $labels->{$_}
Truth table100%3/3
A and B
A= defined $labelsB= defined $labels->{$_}
ABresult
0X0
100
111
2670 22 $label=$self->_maybe_escapeHTML($label);
2671 22 my($value)=$self->_maybe_escapeHTML($_,1);
2672 22 ▶ $result .= $labeled ? $novals ? "<option$attribs label=\"$value\">$label</option>\n"
Branch: 3 branches
BranchTrueFalseTotal
$labeled ? : 4 18 22
$novals ? : 2 2 4
$novals ? : 2 16 18
2673 : "<option$attribs label=\"$value\" value=\"$value\">$label</option>\n"
2674 : $novals ? "<option$attribs>$label</option>\n"
2675 : "<option$attribs value=\"$value\">$label</option>\n";
2676 }
2677 }
2678 14 $result .= "</optgroup>";
2679 14 return $result;
2680 }
2681  
2682 #### Method: scrolling_list
2683 # Create a scrolling list.
2684 # Parameters:
2685 # $name -> name for the list
2686 # $values -> A pointer to a regular array containing the
2687 # values for each option line in the list.
2688 # $defaults -> (optional)
2689 # 1. If a pointer to a regular array of options,
2690 # then this will be used to decide which
2691 # lines to turn on by default.
2692 # 2. Otherwise holds the value of the single line to turn on.
2693 # $size -> (optional) Size of the list.
2694 # $multiple -> (optional) If set, allow multiple selections.
2695 # $labels -> (optional)
2696 # A pointer to a hash of labels to print next to each checkbox
2697 # in the form $label{'value'}="Long explanatory label".
2698 # Otherwise the provided values are used as the labels.
2699 # Returns:
2700 # A string containing the definition of a scrolling list.
2701 ####
2702 12 ▶sub scrolling_list {
Subroutine scrolling_list: called CC=12 SCAR=24.9
Pod undocumented
2703 12 my($self,@p) = self_or_default(@_);
2704 12 my($name,$values,$defaults,$size,$multiple,$labels,$attributes,$override,$tabindex,@other)
2705 = rearrange([NAME,[VALUES,VALUE],[DEFAULTS,DEFAULT],
2706 SIZE,MULTIPLE,LABELS,ATTRIBUTES,[OVERRIDE,FORCE],TABINDEX],@p);
2707  
2708 12 my($result,@values);
2709 12 @values = $self->_set_values_and_labels($values,\$labels,$name);
2710  
2711 12 ▶ $size = $size || scalar(@values);
Condition100%2/2
$size || scalar @values
l!l
111
MC/DC100%1/1
$size || scalar @values
$size
Truth table100%2/2
A
A= $size
Aresult
11
00
2712  
2713 12 my(%selected) = $self->previous_or_default($name,$defaults,$override);
2714  
2715 12 ▶ my($is_multiple) = $multiple ? qq/ multiple="multiple"/ : '';
Branch: 1 branch
BranchTrueFalseTotal
$multiple ? : 1 11 12
2716 12 ▶ my($has_size) = $size ? qq/ size="$size"/: '';
Branch: 1 branch
BranchTrueFalseTotal
$size ? : 12 0 12
2717 12 ▶ my($other) = @other ? " @other" : '';
Branch: 1 branch
BranchTrueFalseTotal
@other ? : 1 11 12
2718  
2719 12 $name=$self->_maybe_escapeHTML($name);
2720 12 $tabindex = $self->element_tab($tabindex);
2721 12 $result = qq/<select name="$name" $tabindex$has_size$is_multiple$other>\n/;
2722 12 for (@values) {
2723 20 ▶ if (/<optgroup/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/<optgroup/) { } 10 10 20
2724 10 for my $v (split(/\n/)) {
2725 45 ▶ my $selectit = $XHTML ? 'selected="selected"' : 'selected';
Branch: 1 branch
BranchTrueFalseTotal
$XHTML ? : 45 0 45
2726 45 for my $selected (sort keys %selected) {
2727 45 $v =~ s/(value="\Q$selected\E")/$selectit $1/;
2728 }
2729 45 $result .= "$v\n";
2730 }
2731 }
2732 else {
2733 10 my $attribs = $self->_set_attributes($_, $attributes);
2734 10 my($selectit) = $self->_selected($selected{$_});
2735 10 my($label) = $_;
2736 10 ▶ $label = $labels->{$_} if defined($labels) && defined($labels->{$_});
Branch: 1 branch
BranchTrueFalseTotal
if defined $labels and defined $labels->{$_} 3 7 10
Condition66%2/3
defined $labels and defined $labels->{$_}
!ll&&!rl&&r
703
MC/DC50%1/2
defined $labels and defined $labels->{$_}
defined $labels defined $labels->{$_}
Truth table66%2/3
A and B
A= defined $labelsB= defined $labels->{$_}
ABresult
0X0
100
111
2737 10 my($value) = $self->_maybe_escapeHTML($_);
2738 10 $label = $self->_maybe_escapeHTML($label,1);
2739 10 $result .= "<option${attribs} ${selectit}value=\"$value\">$label</option>\n";
2740 }
2741 }
2742  
2743 12 $result .= "</select>";
2744 12 $self->register_parameter($name);
2745 12 return $result;
2746 }
2747  
2748 #### Method: hidden
2749 # Parameters:
2750 # $name -> Name of the hidden field
2751 # @default -> (optional) Initial values of field (may be an array)
2752 # or
2753 # $default->[initial values of field]
2754 # Returns:
2755 # A string containing a <input type="hidden" name="name" value="value">
2756 ####
2757 7 ▶sub hidden {
Subroutine hidden: called CC=12 SCAR=25.1
Pod undocumented
2758 7 my($self,@p) = self_or_default(@_);
2759  
2760 # this is the one place where we departed from our standard
2761 # calling scheme, so we have to special-case (darn)
2762 7 my(@result,@value);
2763 7 my($name,$default,$override,@other) =
2764 rearrange([NAME,[DEFAULT,VALUE,VALUES],[OVERRIDE,FORCE]],@p);
2765  
2766 7 my $do_override = 0;
2767 7 ▶ if ( ref($p[0]) || substr($p[0],0,1) eq '-') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $p[0] or substr($p[0], 0, 1) eq '-') { } 5 2 7
Condition66%2/3
ref $p[0] or substr($p[0], 0, 1) eq "-"
l!l&&r!l&&!r
052
MC/DC50%1/2
ref $p[0] or substr($p[0], 0, 1) eq "-"
ref $p[0] substr($p[0], 0, 1) eq "-"
Truth table66%2/3
A or B
A= ref $p[0]B= substr($p[0], 0, 1) eq "-"
ABresult
1X1
011
000
2768 5 ▶ @value = ref($default) ? @{$default} : $default;
Branch: 1 branch
BranchTrueFalseTotal
ref $default ? : 4 1 5
2769 5 $do_override = $override;
2770 } else {
2771 2 for ($default,$override,@other) {
2772 6 ▶ push(@value,$_) if defined($_);
Branch: 1 branch
BranchTrueFalseTotal
if defined $_ 5 1 6
2773 }
2774 2 undef @other;
2775 }
2776  
2777 # use previous values if override is not set
2778 7 my @prev = $self->param($name);
2779 7 ▶ @value = @prev if !$do_override && @prev;
Branch: 1 branch
BranchTrueFalseTotal
if not $do_override and @prev 0 7 7
Condition66%2/3
not $do_override and @prev
!ll&&!rl&&r
160
MC/DC0%0/2
not $do_override and @prev
not $do_override @prev
Truth table66%2/3
not(A) and B
A= not $do_overrideB= @prev
ABresult
0X0
100
111
2780  
2781 7 $name=$self->_maybe_escapeHTML($name);
2782 7 for (@value) {
2783 18 ▶ $_ = defined($_) ? $self->_maybe_escapeHTML($_,1) : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 18 0 18
2784 18 ▶ push @result,$XHTML ? qq(<input type="hidden" name="$name" value="$_" @other />)
Branch: 1 branch
BranchTrueFalseTotal
$XHTML ? : 18 0 18
2785 : qq(<input type="hidden" name="$name" value="$_" @other>);
2786 }
2787 7 ▶ return wantarray ? @result : join('',@result);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 6 7
2788 }
2789  
2790 #### Method: image_button
2791 # Parameters:
2792 # $name -> Name of the button
2793 # $src -> URL of the image source
2794 # $align -> Alignment style (TOP, BOTTOM or MIDDLE)
2795 # Returns:
2796 # A string containing a <input type="image" name="name" src="url" align="alignment">
2797 ####
2798 1 ▶sub image_button {
Subroutine image_button: called CC=4 SCAR=14.5
Pod undocumented
2799 1 my($self,@p) = self_or_default(@_);
2800  
2801 1 my($name,$src,$alignment,@other) =
2802 rearrange([NAME,SRC,ALIGN],@p);
2803  
2804 1 ▶ my($align) = $alignment ? " align=\L\"$alignment\"" : '';
Branch: 1 branch
BranchTrueFalseTotal
$alignment ? : 1 0 1
2805 1 ▶ my($other) = @other ? " @other" : '';
Branch: 1 branch
BranchTrueFalseTotal
@other ? : 1 0 1
2806 1 $name=$self->_maybe_escapeHTML($name);
2807 1 ▶ return $XHTML ? qq(<input type="image" name="$name" src="$src"$align$other />)
Branch: 1 branch
BranchTrueFalseTotal
$XHTML ? : 1 0 1
2808 : qq/<input type="image" name="$name" src="$src"$align$other>/;
2809 }
2810  
2811 #### Method: self_url
2812 # Returns a URL containing the current script and all its
2813 # param/value pairs arranged as a query. You can use this
2814 # to create a link that, when selected, will reinvoke the
2815 # script with all its state information preserved.
2816 ####
2817 24 ▶sub self_url {
Subroutine self_url: called CC=1 SCAR=0.0
Pod undocumented
2818 24 my($self,@p) = self_or_default(@_);
2819 24 return $self->url('-path_info'=>1,'-query'=>1,'-full'=>1,@p);
2820 }
2821  
2822 # This is provided as a synonym to self_url() for people unfortunate
2823 # enough to have incorporated it into their programs already!
2824 1 ▶sub state {
Subroutine state: called CC=1 SCAR=0.0
Pod documented
2825 1 &self_url;
2826 }
2827  
2828 #### Method: url
2829 # Like self_url, but doesn't return the query string part of
2830 # the URL.
2831 ####
2832 163 ▶sub url {
Subroutine url: called CC=30 SCAR=34.2
Pod documented
2833 163 my($self,@p) = self_or_default(@_);
2834 163 my ($relative,$absolute,$full,$path_info,$query,$base,$rewrite) =
2835 rearrange(['RELATIVE','ABSOLUTE','FULL',['PATH','PATH_INFO'],['QUERY','QUERY_STRING'],'BASE','REWRITE'],@p);
2836 163 my $url = '';
2837 163 ▶ $full++ if $base || !($relative || $absolute);
Branch: 1 branch
BranchTrueFalseTotal
if $base or not $relative || $absolute 92 71 163
Condition83%5/6
$base or not $relative || $absolute
l!l&&r!l&&!r
09271
$relative || $absolute
l!l&&r!l&&!r
314092
MC/DC66%2/3
$base or not $relative || $absolute
$base $relative $absolute
Truth table75%3/4
A or not(B || C)
A= $baseB= $relativeC= $absolute
ABCresult
1XX1
0001
01X0
0010
2838 163 ▶ $rewrite++ unless defined $rewrite;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rewrite 156 7 163
2839  
2840 163 my $path = $self->path_info;
2841 163 my $script_name = $self->script_name;
2842 163 ▶ my $request_uri = $self->_request_uri_path || '';
Condition100%2/2
$self->_request_uri_path || ''
l!l
11251
MC/DC100%1/1
$self->_request_uri_path || ''
$self->_request_uri_path
Truth table100%2/2
A
A= $self->_request_uri_path
Aresult
11
00
2843 163 ▶ my $query_str = $query ? $self->query_string : '';
Branch: 1 branch
BranchTrueFalseTotal
$query ? : 45 118 163
2844  
2845 163 $script_name =~ s/\?.*$//s; # remove query string
2846 163 $request_uri =~ s/\?.*$//s; # remove query string
2847 163 $request_uri = unescape($request_uri);
2848 # unescaping %2F / %5C may have produced a leading // or \ again
2849 163 $request_uri =~ s{^[/\\]+}{/};
2850  
2851 163 ▶ my $uri = $rewrite && $request_uri ? $request_uri : $script_name;
Branch: 1 branch
BranchTrueFalseTotal
$rewrite && $request_uri ? : 108 55 163
Condition100%3/3
$rewrite and $request_uri
!ll&&!rl&&r
451108
MC/DC100%2/2
$rewrite and $request_uri
$rewrite $request_uri
Truth table100%3/3
A and B
A= $rewriteB= $request_uri
ABresult
0X0
100
111
2852  
2853 163 ▶ if ( defined( $ENV{PATH_INFO} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ENV{"PATH_INFO"}) 53 110 163
2854 # IIS sometimes sets PATH_INFO to the same value as SCRIPT_NAME so only sub it out
2855 # if SCRIPT_NAME isn't defined or isn't the same value as PATH_INFO
2856 $uri =~ s/\Q$ENV{PATH_INFO}\E$//
2857 53 ▶ if ( ! defined( $ENV{SCRIPT_NAME} ) or $ENV{PATH_INFO} ne $ENV{SCRIPT_NAME} );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $ENV{"SCRIPT_NAME"} or $ENV{"PATH_INFO"} ne $ENV{"SCRIPT_NAME"} 52 1 53
Condition100%3/3
not defined $ENV{"SCRIPT_NAME"} or $ENV{"PATH_INFO"} ne $ENV{"SCRIPT_NAME"}
l!l&&r!l&&!r
4481
MC/DC100%2/2
not defined $ENV{"SCRIPT_NAME"} or $ENV{"PATH_INFO"} ne $ENV{"SCRIPT_NAME"}
not defined $ENV{"SCRIPT_NAME"} $ENV{"PATH_INFO"} ne $ENV{"SCRIPT_NAME"}
Truth table100%3/3
not(A) or B
A= not defined $ENV{"SCRIPT_NAME"}B= $ENV{"PATH_INFO"} ne $ENV{"SCRIPT_NAME"}
ABresult
1X1
011
000
2858  
2859 # if we're not IIS then keep to spec, the relevant info is here:
2860 # https://tools.ietf.org/html/rfc3875#section-4.1.13, namely
2861 # "No PATH_INFO segment (see section 4.1.5) is included in the
2862 # SCRIPT_NAME value." (see GH #126, GH #152, GH #176)
2863 53 ▶ if ( ! $IIS ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($IIS) 47 6 53
2864 47 $uri =~ s/\Q$ENV{PATH_INFO}\E$//;
2865 }
2866 }
2867  
2868 163 ▶ if ($full) {
Branch: 3 branches
BranchTrueFalseTotal
if ($full) { } 92 71 163
elsif ($relative) { } 31 40 71
elsif ($absolute) { } 40 0 40
2869 92 my $protocol = $self->protocol();
2870 92 $url = "$protocol://";
2871 92 ▶ my $vh = _valid_http_host() || '';
Condition100%2/2
_valid_http_host() || ''
l!l
5933
MC/DC100%1/1
_valid_http_host() || ''
_valid_http_host()
Truth table100%2/2
A
A= _valid_http_host()
Aresult
11
00
2872 92 $vh =~ s/\:\d+$//; # some clients add the port number (incorrectly). Get rid of it.
2873  
2874 92 ▶ $url .= $vh || server_name();
Condition66%2/3
$vh || server_name()
l!l&&r!l&&!r
59330
MC/DC0%0/2
$vh || server_name()
$vh server_name()
Truth table66%2/3
A || B
A= $vhB= server_name()
ABresult
1X1
011
000
2875  
2876 92 my $port = $self->virtual_port;
2877  
2878 # add the port to the url unless it's the protocol's default port
2879 92 ▶ $url .= ':' . $port unless (lc($protocol) eq 'http' && $port == 80)
Branch: 1 branch
BranchTrueFalseTotal
unless lc $protocol eq "http" and $port == 80 or lc $protocol eq "https" and $port == 443 33 59 92
Condition55%5/9
lc $protocol eq "http" and $port == 80 or lc $protocol eq "https" and $port == 443
l!l&&r!l&&!r
59033
lc $protocol eq "http" and $port == 80
!ll&&!rl&&r
03359
lc $protocol eq "https" and $port == 443
!ll&&!rl&&r
3300
MC/DC25%1/4
lc $protocol eq "http" and $port == 80 or lc $protocol eq "https" and $port == 443
lc $protocol eq "http" $port == 80 lc $protocol eq "https" $port == 443
Truth table28%2/7
A and B or C and D
A= lc $protocol eq "http"B= $port == 80C= lc $protocol eq "https"D= $port == 443
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
2880 or (lc($protocol) eq 'https' && $port == 443);
2881  
2882 92 ▶ return $url if $base;
Branch: 1 branch
BranchTrueFalseTotal
if $base 0 92 92
2883  
2884 92 $url .= $uri;
2885 } elsif ($relative) {
2886 31 ($url) = $uri =~ m!([^/]+)$!;
2887 } elsif ($absolute) {
2888 40 $url = $uri;
2889 }
2890  
2891 163 ▶ $url .= $path if $path_info and defined $path;
Branch: 1 branch
BranchTrueFalseTotal
if $path_info and defined $path 69 94 163
Condition66%2/3
$path_info and defined $path
!ll&&!rl&&r
94069
MC/DC50%1/2
$path_info and defined $path
$path_info defined $path
Truth table66%2/3
A and B
A= $path_infoB= defined $path
ABresult
0X0
100
111
2892 163 ▶ $url .= "?$query_str" if $query and $query_str ne '';
Branch: 1 branch
BranchTrueFalseTotal
if $query and $query_str ne "" 13 150 163
Condition100%3/3
$query and $query_str ne ""
!ll&&!rl&&r
1183213
MC/DC100%2/2
$query and $query_str ne ""
$query $query_str ne ""
Truth table100%3/3
A and B
A= $queryB= $query_str ne ""
ABresult
0X0
100
111
2893 163 ▶ $url ||= '';
Condition100%2/2
$url ||= ""
l!l
1621
MC/DC100%1/1
$url ||= ""
$url
Truth table100%2/2
A
A= $url
Aresult
11
00
2894  
2895 163 ▶ unless ($full) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($full) 71 92 163
2896 # a URL that isn't full must not be protocol relative (// or \,
2897 # which browsers treat as /), which would be another host, nor
2898 # look like it has a scheme (e.g. relative "javascript:alert(1)")
2899 71 $url =~ s{^[/\\]{2,}}{/};
2900 71 ▶ $url = "./$url" if $url =~ m{^[^/?#]*:};
Branch: 1 branch
BranchTrueFalseTotal
if $url =~ m[^[^/?#]*:] 2 69 71
2901 }
2902  
2903 163 $url = URI->new( $url )->canonical->as_string;
2904 # canonical() decodes %27 (an RFC 2396 unreserved character) back to a
2905 # quote - and a raw quote may be in the request URI - which would let
2906 # request data break out of a single quoted attribute or JS string
2907 163 $url =~ s/'/%27/g;
2908 163 return $url
2909 }
2910  
2911 #### Method: cookie
2912 # Set or read a cookie from the specified name.
2913 # Cookie can then be passed to header().
2914 # Usual rules apply to the stickiness of -value.
2915 # Parameters:
2916 # -name -> name for this cookie (optional)
2917 # -value -> value of this cookie (scalar, array or hash)
2918 # -path -> paths for which this cookie is valid (optional)
2919 # -domain -> internet domain in which this cookie is valid (optional)
2920 # -secure -> if true, cookie only passed through secure channel (optional)
2921 # -expires -> expiry date in format Wdy, DD Mon YYYY HH:MM:SS GMT (optional)
2922 ####
2923 8 ▶sub cookie {
Subroutine cookie: called CC=19 SCAR=33.6
Pod undocumented
2924 8 my($self,@p) = self_or_default(@_);
2925 8 my($name,$value,$path,$domain,$secure,$expires,$httponly,$max_age,$samesite,$priority) =
2926 rearrange([NAME,[VALUE,VALUES],PATH,DOMAIN,SECURE,EXPIRES,HTTPONLY,'MAX-AGE',SAMESITE,PRIORITY],@p);
2927  
2928 8 require CGI::Cookie;
2929  
2930 # if no value is supplied, then we retrieve the
2931 # value of the cookie, if any. For efficiency, we cache the parsed
2932 # cookies in our state variables.
2933 8 ▶ unless ( defined($value) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $value) 2 6 8
2934 2 ▶ $self->{'.cookies'} = CGI::Cookie->fetch unless $COOKIE_CACHE && exists $self->{'.cookies'};
Branch: 1 branch
BranchTrueFalseTotal
unless $COOKIE_CACHE and exists $self->{".cookies"} 2 0 2
Condition33%1/3
$COOKIE_CACHE and exists $self->{".cookies"}
!ll&&!rl&&r
200
MC/DC0%0/2
$COOKIE_CACHE and exists $self->{".cookies"}
$COOKIE_CACHE exists $self->{".cookies"}
Truth table33%1/3
A and B
A= $COOKIE_CACHEB= exists $self->{".cookies"}
ABresult
0X0
100
111
2935
2936 # If no name is supplied, then retrieve the names of all our cookies.
2937 2 ▶ return () unless $self->{'.cookies'};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{".cookies"} 0 2 2
2938 # hash keys are never tainted
2939 2 ▶ return map { $_ . $TAINTED } keys %{$self->{'.cookies'}} unless $name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 1 1 2
2940 1 ▶ return () unless $self->{'.cookies'}->{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{".cookies"}{$name} 0 1 1
2941 1 ▶ return $self->{'.cookies'}->{$name}->value if defined($name) && $name ne '';
Branch: 1 branch
BranchTrueFalseTotal
if defined $name and $name ne "" 1 0 1
Condition33%1/3
defined $name and $name ne ""
!ll&&!rl&&r
001
MC/DC0%0/2
defined $name and $name ne ""
defined $name $name ne ""
Truth table33%1/3
A and B
A= defined $nameB= $name ne ""
ABresult
0X0
100
111
2942 }
2943  
2944 # If we get here, we're creating a new cookie
2945 6 ▶ return undef unless defined($name) && $name ne ''; # this is an error
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name and $name ne "" 0 6 6
Condition33%1/3
defined $name and $name ne ""
!ll&&!rl&&r
006
MC/DC0%0/2
defined $name and $name ne ""
defined $name $name ne ""
Truth table33%1/3
A and B
A= defined $nameB= $name ne ""
ABresult
0X0
100
111
2946  
2947 6 my @param;
2948 6 push(@param,'-name'=>$name);
2949 6 push(@param,'-value'=>$value);
2950 6 ▶ push(@param,'-domain'=>$domain) if $domain;
Branch: 1 branch
BranchTrueFalseTotal
if $domain 0 6 6
2951 6 ▶ push(@param,'-path'=>$path) if $path;
Branch: 1 branch
BranchTrueFalseTotal
if $path 6 0 6
2952 6 ▶ push(@param,'-expires'=>$expires) if $expires;
Branch: 1 branch
BranchTrueFalseTotal
if $expires 0 6 6
2953 6 ▶ push(@param,'-secure'=>$secure) if $secure;
Branch: 1 branch
BranchTrueFalseTotal
if $secure 0 6 6
2954 6 ▶ push(@param,'-httponly'=>$httponly) if $httponly;
Branch: 1 branch
BranchTrueFalseTotal
if $httponly 0 6 6
2955 6 ▶ push(@param,'-max-age'=>$max_age) if $max_age;
Branch: 1 branch
BranchTrueFalseTotal
if $max_age 0 6 6
2956 6 ▶ push(@param,'-samesite'=>$samesite) if $samesite;
Branch: 1 branch
BranchTrueFalseTotal
if $samesite 0 6 6
2957 6 ▶ push(@param,'-priority'=>$priority) if $priority;
Branch: 1 branch
BranchTrueFalseTotal
if $priority 0 6 6
2958  
2959 6 return CGI::Cookie->new(@param);
2960 }
2961  
2962 8 ▶sub parse_keywordlist {
Subroutine parse_keywordlist: called CC=1 SCAR=0.0
Pod undocumented
2963 8 my($self,$tosplit) = @_;
2964 8 $tosplit = unescape($tosplit); # unescape the keywords
2965 8 $tosplit=~tr/+/ /; # pluses to spaces
2966 8 my(@keywords) = split(/\s+/,$tosplit);
2967 8 return @keywords;
2968 }
2969  
2970 10 ▶sub param_fetch {
Subroutine param_fetch: called CC=3 SCAR=11.6
Pod undocumented
2971 10 my($self,@p) = self_or_default(@_);
2972 10 my($name) = rearrange([NAME],@p);
2973 10 ▶ return [] unless defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 1 9 10
2974  
2975 9 ▶ unless (exists($self->{param}{$name})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"param"}{$name}) 0 9 9
2976 0 $self->add_parameter($name);
2977 0 $self->{param}{$name} = [];
2978 }
2979
2980 9 return $self->{param}{$name};
2981 }
2982  
2983 ###############################################
2984 # OTHER INFORMATION PROVIDED BY THE ENVIRONMENT
2985 ###############################################
2986  
2987 #### Method: path_info
2988 # Return the extra virtual path information provided
2989 # after the URL (if any)
2990 ####
2991 186 ▶sub path_info {
Subroutine path_info: called CC=6 SCAR=18.2
Pod documented
2992 186 my ($self,$info) = self_or_default(@_);
2993 186 ▶ if (defined($info)) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $info) { } 1 185 186
elsif (not defined $self->{'.path_info'}) { } 54 131 185
2994 1 ▶ $info = "/$info" if $info ne '' && substr($info,0,1) ne '/';
Branch: 1 branch
BranchTrueFalseTotal
if $info ne "" and substr($info, 0, 1) ne "/" 0 1 1
Condition33%1/3
$info ne "" and substr($info, 0, 1) ne "/"
!ll&&!rl&&r
010
MC/DC0%0/2
$info ne "" and substr($info, 0, 1) ne "/"
$info ne "" substr($info, 0, 1) ne "/"
Truth table33%1/3
A and B
A= $info ne ""B= substr($info, 0, 1) ne "/"
ABresult
0X0
100
111
2995 1 $self->{'.path_info'} = $info;
2996 } elsif (! defined($self->{'.path_info'}) ) {
2997 54 my (undef,$path_info) = $self->_name_and_path_from_env;
2998 54 ▶ $self->{'.path_info'} = $path_info || '';
Condition100%2/2
$path_info || ''
l!l
1242
MC/DC100%1/1
$path_info || ''
$path_info
Truth table100%2/2
A
A= $path_info
Aresult
11
00
2999 }
3000 186 return $self->{'.path_info'};
3001 }
3002  
3003 # This function returns a potentially modified version of SCRIPT_NAME
3004 # and PATH_INFO. Some HTTP servers do sanitise the paths in those
3005 # variables. It is the case of at least Apache 2. If for instance the
3006 # user requests: /path/./to/script.cgi/x//y/z/../x?y, Apache will set:
3007 # REQUEST_URI=/path/./to/script.cgi/x//y/z/../x?y
3008 # SCRIPT_NAME=/path/to/env.cgi
3009 # PATH_INFO=/x/y/x
3010 #
3011 # This is all fine except that some bogus CGI scripts expect
3012 # PATH_INFO=/http://foo when the user requests
3013 # http://xxx/script.cgi/http://foo
3014 #
3015 # Old versions of this module used to accomodate with those scripts, so
3016 # this is why we do this here to keep those scripts backward compatible.
3017 # Basically, we accomodate with those scripts but within limits, that is
3018 # we only try to preserve the number of / that were provided by the user
3019 # if $REQUEST_URI and "$SCRIPT_NAME$PATH_INFO" only differ by the number
3020 # of consecutive /.
3021 #
3022 # So for instance, in: http://foo/x//y/script.cgi/a//b, we'll return a
3023 # script_name of /x//y/script.cgi and a path_info of /a//b, but in:
3024 # http://foo/./x//z/script.cgi/a/../b//c, we'll return the versions
3025 # possibly sanitised by the HTTP server, so in the case of Apache 2:
3026 # script_name == /foo/x/z/script.cgi and path_info == /b/c.
3027 #
3028 # Future versions of this module may no longer do that, so one should
3029 # avoid relying on the browser, proxy, server, and CGI.pm preserving the
3030 # number of consecutive slashes as no guarantee can be made there.
3031 90 ▶sub _name_and_path_from_env {
Subroutine _name_and_path_from_env: called CC=7 SCAR=19.5
3032 90 my $self = shift;
3033 90 ▶ my $script_name = $ENV{SCRIPT_NAME} || '';
Condition100%2/2
$ENV{'SCRIPT_NAME'} || ''
l!l
5832
MC/DC100%1/1
$ENV{'SCRIPT_NAME'} || ''
$ENV{'SCRIPT_NAME'}
Truth table100%2/2
A
A= $ENV{'SCRIPT_NAME'}
Aresult
11
00
3034 90 ▶ my $path_info = $ENV{PATH_INFO} || '';
Condition100%2/2
$ENV{'PATH_INFO'} || ''
l!l
2664
MC/DC100%1/1
$ENV{'PATH_INFO'} || ''
$ENV{'PATH_INFO'}
Truth table100%2/2
A
A= $ENV{'PATH_INFO'}
Aresult
11
00
3035 90 ▶ my $uri = $self->request_uri || '';
Condition100%2/2
$self->request_uri || ''
l!l
5238
MC/DC100%1/1
$self->request_uri || ''
$self->request_uri
Truth table100%2/2
A
A= $self->request_uri
Aresult
11
00
3036  
3037 90 $uri =~ s/\?.*//s;
3038 90 $uri = unescape($uri);
3039  
3040 90 ▶ if ( $IIS ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($IIS) { } 10 80 90
elsif ($uri ne "$script_name$path_info") { } 42 38 80
3041 # IIS doesn't set $ENV{PATH_INFO} correctly. It sets it to
3042 # $ENV{SCRIPT_NAME}path_info
3043 # IIS also doesn't set $ENV{REQUEST_URI} so we don't want to do
3044 # the test below, hence this comes first
3045 10 $path_info =~ s/^\Q$script_name\E(.*)/$1/;
3046 } elsif ($uri ne "$script_name$path_info") {
3047 42 my $script_name_pattern = quotemeta($script_name);
3048 42 my $path_info_pattern = quotemeta($path_info);
3049 42 $script_name_pattern =~ s{(?:\\/)+}{/+}g;
3050 42 $path_info_pattern =~ s{(?:\\/)+}{/+}g;
3051  
3052 42 ▶ if ($uri =~ /^($script_name_pattern)($path_info_pattern)$/s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($uri =~ /^($script_name_pattern)($path_info_pattern)$/s) 2 40 42
3053 # REQUEST_URI and SCRIPT_NAME . PATH_INFO only differ by the
3054 # numer of consecutive slashes, so we can extract the info from
3055 # REQUEST_URI:
3056 # (regex captures are untainted)
3057 2 ($script_name, $path_info) = ($1 . $TAINTED, $2 . $TAINTED);
3058 }
3059 }
3060 90 return ($script_name,$path_info);
3061 }
3062  
3063 #### Method: request_method
3064 # Returns 'POST', 'GET', 'PUT', 'PATCH' or 'HEAD'
3065 ####
3066 7 ▶sub request_method {
Subroutine request_method: called CC=2 SCAR=7.6
Pod documented
3067 7 ▶ return (defined $ENV{'REQUEST_METHOD'}) ? $ENV{'REQUEST_METHOD'} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $ENV{'REQUEST_METHOD'} ? : 7 0 7
3068 }
3069  
3070 #### Method: content_type
3071 # Returns the content_type string
3072 ####
3073 0 ▶sub content_type {
Subroutine content_type: not called CC=2 SCAR=17.9
Pod documented
3074 0 ▶ return (defined $ENV{'CONTENT_TYPE'}) ? $ENV{'CONTENT_TYPE'} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $ENV{'CONTENT_TYPE'} ? : 0 0 0
3075 }
3076  
3077 #### Method: path_translated
3078 # Return the physical path information provided
3079 # by the URL (if any)
3080 ####
3081 0 ▶sub path_translated {
Subroutine path_translated: not called CC=2 SCAR=17.9
Pod documented
3082 0 ▶ return (defined $ENV{'PATH_TRANSLATED'}) ? $ENV{'PATH_TRANSLATED'} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $ENV{'PATH_TRANSLATED'} ? : 0 0 0
3083 }
3084  
3085 #### Method: request_uri
3086 # Return the literal request URI
3087 ####
3088 285 ▶sub request_uri {
Subroutine request_uri: called CC=2 SCAR=6.9
Pod documented
3089 285 ▶ return (defined $ENV{'REQUEST_URI'}) ? $ENV{'REQUEST_URI'} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $ENV{'REQUEST_URI'} ? : 195 90 285
3090 }
3091  
3092 # REQUEST_URI is the raw request-target, so is client controlled and may be
3093 # in absolute-form (http://host/path) or start with multiple slashes (or
3094 # backslashes, which browsers treat as slashes) - any of which would make a
3095 # URL built from it point at another host. Reduce it to a path on this host.
3096 182 ▶sub _request_uri_path {
Subroutine _request_uri_path: called CC=4 SCAR=13.9
3097 182 my ($self) = @_;
3098 182 my $uri = $self->request_uri;
3099 182 ▶ return undef unless defined $uri && length $uri;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $uri and length $uri 52 130 182
Condition66%2/3
defined $uri and length $uri
!ll&&!rl&&r
520130
MC/DC50%1/2
defined $uri and length $uri
defined $uri length $uri
Truth table66%2/3
A and B
A= defined $uriB= length $uri
ABresult
0X0
100
111
3100 130 $uri =~ s{^[A-Za-z][A-Za-z0-9+.-]*://[^/?#]*}{}; # absolute-form
3101 130 $uri =~ s{^[/\\]+}{/};
3102 130 ▶ $uri = "/$uri" unless $uri =~ m{^/};
Branch: 1 branch
BranchTrueFalseTotal
unless $uri =~ m[^/] 6 124 130
3103 130 return $uri;
3104 }
3105  
3106 #### Method: query_string
3107 # Synthesize a query string from our current
3108 # parameters
3109 ####
3110 62 ▶sub query_string {
Subroutine query_string: called CC=6 SCAR=18.0
Pod undocumented
3111 62 my($self) = self_or_default(@_);
3112 62 my($param,$value,@pairs);
3113 62 for $param ($self->param) {
3114 67 my($eparam) = escape($param);
3115 67 for $value ($self->param($param)) {
3116 85 $value = escape($value);
3117 85 ▶ next unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 7 78 85
3118 78 push(@pairs,"$eparam=$value");
3119 }
3120 }
3121 62 for (sort keys %{$self->{'.fieldnames'}}) {
3122 0 push(@pairs,".cgifields=".escape("$_"));
3123 }
3124 62 ▶ return join($USE_PARAM_SEMICOLONS ? ';' : '&',@pairs);
Branch: 1 branch
BranchTrueFalseTotal
$USE_PARAM_SEMICOLONS ? : 62 0 62
3125 }
3126  
3127 1 ▶sub env_query_string {
Subroutine env_query_string: called CC=2 SCAR=7.6
Pod documented
3128 1 ▶ return (defined $ENV{'QUERY_STRING'}) ? $ENV{'QUERY_STRING'} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $ENV{'QUERY_STRING'} ? : 1 0 1
3129 }
3130  
3131 #### Method: accept
3132 # Without parameters, returns an array of the
3133 # MIME types the browser accepts.
3134 # With a single parameter equal to a MIME
3135 # type, will return undef if the browser won't
3136 # accept it, 1 if the browser accepts it but
3137 # doesn't give a preference, or a floating point
3138 # value between 0.0 and 1.0 if the browser
3139 # declares a quantitative score for it.
3140 # This handles MIME type globs correctly.
3141 ####
3142 3 ▶sub Accept {
Subroutine Accept: called CC=10 SCAR=29.0
Pod documented
3143 3 my($self,$search) = self_or_CGI(@_);
3144 3 my(%prefs,$type,$pref,$pat);
3145
3146 3 ▶ my(@accept) = defined $self->http('accept')
Branch: 1 branch
BranchTrueFalseTotal
defined $self->http('accept') ? : 3 0 3
3147 ? split(',',$self->http('accept'))
3148 : ();
3149  
3150 3 for (@accept) {
3151 6 ($pref) = /q=(\d\.\d+|\d+)/;
3152 6 ($type) = m#(\S+/[^;]+)#;
3153 6 ▶ next unless $type;
Branch: 1 branch
BranchTrueFalseTotal
unless $type 0 6 6
3154 6 ▶ $prefs{$type}=$pref ? $pref . $TAINTED : 1; # captures are untainted
Branch: 1 branch
BranchTrueFalseTotal
$pref ? : 6 0 6
3155 }
3156  
3157 # hash keys are never tainted
3158 3 ▶ return map { $_ . $TAINTED } keys %prefs unless $search;
Branch: 1 branch
BranchTrueFalseTotal
unless $search 1 2 3
3159
3160 # if a search type is provided, we may need to
3161 # perform a pattern matching operation.
3162 # The MIME types use a glob mechanism, which
3163 # is easily translated into a perl pattern match
3164  
3165 # First return the preference for directly supported
3166 # types:
3167 2 ▶ return $prefs{$search} if $prefs{$search};
Branch: 1 branch
BranchTrueFalseTotal
if $prefs{$search} 2 0 2
3168  
3169 # Didn't get it, so try pattern matching.
3170 0 for (sort keys %prefs) {
3171 0 ▶ next unless /\*/; # not a pattern match
Branch: 1 branch
BranchTrueFalseTotal
unless /\*/ 0 0 0
3172 0 ($pat = $_) =~ s/([^\w*])/\\$1/g; # escape meta characters
3173 0 $pat =~ s/\*/.*/g; # turn it into a pattern
3174 0 ▶ return $prefs{$_} if $search=~/$pat/;
Branch: 1 branch
BranchTrueFalseTotal
if $search =~ /$pat/ 0 0 0
3175 }
3176 }
3177  
3178 #### Method: user_agent
3179 # If called with no parameters, returns the user agent.
3180 # If called with one parameter, does a pattern match (case
3181 # insensitive) on the user agent.
3182 ####
3183 4 ▶sub user_agent {
Subroutine user_agent: called CC=4 SCAR=14.0
Pod documented
3184 4 my($self,$match)=self_or_CGI(@_);
3185 4 my $user_agent = $self->http('user_agent');
3186 4 ▶ return $user_agent unless defined $match && $match && $user_agent;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $match and $match and $user_agent 2 2 4
Condition66%4/6
defined $match and $match and $user_agent
!ll&&!rl&&r
202
defined $match and $match
!ll&&!rl&&r
202
MC/DC33%1/3
defined $match and $match and $user_agent
defined $match $match $user_agent
Truth table50%2/4
A and B and C
A= defined $matchB= $matchC= $user_agent
ABCresult
0XX0
10X0
1100
1111
3187 2 return $user_agent =~ /$match/i;
3188 }
3189  
3190 #### Method: raw_cookie
3191 # Returns the magic cookies for the session.
3192 # The cookies are not parsed or altered in any way, i.e.
3193 # cookies are returned exactly as given in the HTTP
3194 # headers. If a cookie name is given, only that cookie's
3195 # value is returned, otherwise the entire raw cookie
3196 # is returned.
3197 ####
3198 1 ▶sub raw_cookie {
Subroutine raw_cookie: called CC=7 SCAR=25.1
Pod documented
3199 1 my($self,$key) = self_or_CGI(@_);
3200  
3201 1 require CGI::Cookie;
3202  
3203 1 ▶ if (defined($key)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $key) 1 0 1
3204 $self->{'.raw_cookies'} = CGI::Cookie->raw_fetch
3205 1 ▶ unless $self->{'.raw_cookies'};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{".raw_cookies"} 1 0 1
3206  
3207 1 ▶ return () unless $self->{'.raw_cookies'};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{".raw_cookies"} 0 1 1
3208 1 ▶ return () unless $self->{'.raw_cookies'}->{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{".raw_cookies"}{$key} 0 1 1
3209 1 return $self->{'.raw_cookies'}->{$key};
3210 }
3211 0 ▶ return $self->http('cookie') || $ENV{'COOKIE'} || '';
Condition0%0/5
$self->http('cookie') || $ENV{'COOKIE'} || ''
l!l
00
$self->http("cookie") or $ENV{"COOKIE"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->http('cookie') || $ENV{'COOKIE'} || ''
$self->http("cookie") $ENV{"COOKIE"}
Truth table0%0/3
A or B
A= $self->http("cookie")B= $ENV{"COOKIE"}
ABresult
1X1
011
000
3212 }
3213  
3214 #### Method: virtual_host
3215 # Return the name of the virtual_host, which
3216 # is not always the same as the server
3217 ######
3218 28 ▶sub virtual_host {
Subroutine virtual_host: called CC=2 SCAR=7.0
Pod documented
3219 28 ▶ my $vh = _valid_http_host() || server_name();
Condition66%2/3
_valid_http_host() || server_name()
l!l&&r!l&&!r
11170
MC/DC0%0/2
_valid_http_host() || server_name()
_valid_http_host() server_name()
Truth table66%2/3
A || B
A= _valid_http_host()B= server_name()
ABresult
1X1
011
000
3220 28 $vh =~ s/:\d+$//; # get rid of port number
3221 28 return $vh;
3222 }
3223  
3224 # Return the Host header if it is a syntactically valid host[:port], else
3225 # undef. The header is client supplied so anything else (userinfo, paths,
3226 # quotes, whitespace, etc) is rejected. X-Forwarded-Host is not consulted
3227 # by default as it can be set by any client and is not part of cache keys,
3228 # unless $TRUST_X_FORWARDED_HOST is set, in which case it is preferred
3229 # (the last entry if it is a list, i.e. the one added by the nearest proxy)
3230 # but must still be a valid host[:port].
3231 231 ▶sub _valid_http_host {
Subroutine _valid_http_host: called CC=6 SCAR=17.9
3232 231 my $host = $ENV{'HTTP_HOST'};
3233 231 ▶ if ( $TRUST_X_FORWARDED_HOST && defined $ENV{'HTTP_X_FORWARDED_HOST'}
Branch: 1 branch
BranchTrueFalseTotal
if ($TRUST_X_FORWARDED_HOST and defined $ENV{"HTTP_X_FORWARDED_HOST"} and length $ENV{"HTTP_X_FORWARDED_HOST"}) 22 209 231
Condition100%6/6
$TRUST_X_FORWARDED_HOST and defined $ENV{"HTTP_X_FORWARDED_HOST"} and length $ENV{"HTTP_X_FORWARDED_HOST"}
!ll&&!rl&&r
207222
$TRUST_X_FORWARDED_HOST and defined $ENV{"HTTP_X_FORWARDED_HOST"}
!ll&&!rl&&r
205224
MC/DC100%3/3
$TRUST_X_FORWARDED_HOST and defined $ENV{"HTTP_X_FORWARDED_HOST"} and length $ENV{"HTTP_X_FORWARDED_HOST"}
$TRUST_X_FORWARDED_HOST defined $ENV{"HTTP_X_FORWARDED_HOST"} length $ENV{"HTTP_X_FORWARDED_HOST"}
Truth table100%4/4
A and B and C
A= $TRUST_X_FORWARDED_HOSTB= defined $ENV{"HTTP_X_FORWARDED_HOST"}C= length $ENV{"HTTP_X_FORWARDED_HOST"}
ABCresult
0XX0
10X0
1100
1111
3234 && length $ENV{'HTTP_X_FORWARDED_HOST'} ) {
3235 22 ( $host = $ENV{'HTTP_X_FORWARDED_HOST'} ) =~ s/^.*,\s*//s;
3236 22 $host =~ s/\s+\z//;
3237 }
3238 231 ▶ return undef unless defined $host;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $host 37 194 231
3239 194 ▶ return $host if $host =~ /\A(?:[A-Za-z0-9_.-]+|\[[0-9A-Fa-f:.]+\])(?::\d{1,5})?\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $host =~ /\A(?:[A-Za-z0-9_.-]+|\[[0-9A-Fa-f:.]+\])(?::\d{1,5})?\z/ 134 60 194
3240 60 return undef;
3241 }
3242  
3243 #### Method: remote_host
3244 # Return the name of the remote host, or its IP
3245 # address if unavailable. If this variable isn't
3246 # defined, it returns "localhost" for debugging
3247 # purposes.
3248 ####
3249 0 ▶sub remote_host {
Subroutine remote_host: not called CC=3 SCAR=24.8
Pod documented
3250 0 ▶ return $ENV{'REMOTE_HOST'} || $ENV{'REMOTE_ADDR'}
Condition0%0/5
$ENV{'REMOTE_HOST'} || $ENV{'REMOTE_ADDR'} || 'localhost'
l!l
00
$ENV{"REMOTE_HOST"} or $ENV{"REMOTE_ADDR"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$ENV{'REMOTE_HOST'} || $ENV{'REMOTE_ADDR'} || 'localhost'
$ENV{"REMOTE_HOST"} $ENV{"REMOTE_ADDR"}
Truth table0%0/3
A or B
A= $ENV{"REMOTE_HOST"}B= $ENV{"REMOTE_ADDR"}
ABresult
1X1
011
000
3251 || 'localhost';
3252 }
3253  
3254 #### Method: remote_addr
3255 # Return the IP addr of the remote host.
3256 ####
3257 0 ▶sub remote_addr {
Subroutine remote_addr: not called CC=2 SCAR=17.9
Pod documented
3258 0 ▶ return $ENV{'REMOTE_ADDR'} || '127.0.0.1';
Condition0%0/2
$ENV{'REMOTE_ADDR'} || '127.0.0.1'
l!l
00
MC/DC0%0/1
$ENV{'REMOTE_ADDR'} || '127.0.0.1'
$ENV{'REMOTE_ADDR'}
Truth table0%0/2
A
A= $ENV{'REMOTE_ADDR'}
Aresult
11
00
3259 }
3260  
3261 #### Method: script_name
3262 # Return the partial URL to this script for
3263 # self-referencing scripts. Also see
3264 # self_url(), which returns a URL with all state information
3265 # preserved.
3266 ####
3267 168 ▶sub script_name {
Subroutine script_name: called CC=3 SCAR=11.2
Pod documented
3268 168 my ($self,@p) = self_or_default(@_);
3269 168 ▶ if (@p) {
Branch: 2 branches
BranchTrueFalseTotal
if (@p) { } 0 168 168
elsif (not exists $self->{'.script_name'}) { } 36 132 168
3270 0 $self->{'.script_name'} = shift @p;
3271 } elsif (!exists $self->{'.script_name'}) {
3272 36 my ($script_name,$path_info) = $self->_name_and_path_from_env();
3273 36 $self->{'.script_name'} = $script_name;
3274 }
3275 168 return $self->{'.script_name'};
3276 }
3277  
3278 #### Method: referer
3279 # Return the HTTP_REFERER: useful for generating
3280 # a GO BACK button.
3281 ####
3282 0 ▶sub referer {
Subroutine referer: not called CC=1 SCAR=6.9
Pod documented
3283 0 my($self) = self_or_CGI(@_);
3284 0 return $self->http('referer');
3285 }
3286  
3287 #### Method: server_name
3288 # Return the name of the server
3289 ####
3290 50 ▶sub server_name {
Subroutine server_name: called CC=2 SCAR=6.9
Pod documented
3291 50 ▶ return $ENV{'SERVER_NAME'} || 'localhost';
Condition100%2/2
$ENV{'SERVER_NAME'} || 'localhost'
l!l
473
MC/DC100%1/1
$ENV{'SERVER_NAME'} || 'localhost'
$ENV{'SERVER_NAME'}
Truth table100%2/2
A
A= $ENV{'SERVER_NAME'}
Aresult
11
00
3292 }
3293  
3294 #### Method: server_software
3295 # Return the name of the server software
3296 ####
3297 5 ▶sub server_software {
Subroutine server_software: called CC=2 SCAR=7.6
Pod documented
3298 5 ▶ return $ENV{'SERVER_SOFTWARE'} || 'cmdline';
Condition50%1/2
$ENV{'SERVER_SOFTWARE'} || 'cmdline'
l!l
05
MC/DC0%0/1
$ENV{'SERVER_SOFTWARE'} || 'cmdline'
$ENV{'SERVER_SOFTWARE'}
Truth table50%1/2
A
A= $ENV{'SERVER_SOFTWARE'}
Aresult
11
00
3299 }
3300  
3301 #### Method: virtual_port
3302 # Return the server port, taking virtual hosts into account
3303 ####
3304 111 ▶sub virtual_port {
Subroutine virtual_port: called CC=4 SCAR=14.0
Pod documented
3305 111 my($self) = self_or_default(@_);
3306 111 my $vh = _valid_http_host();
3307 111 my $protocol = $self->protocol;
3308 111 ▶ if ($vh) {
Branch: 1 branch
BranchTrueFalseTotal
if ($vh) { } 64 47 111
3309 64 ▶ return ($vh =~ /:(\d+)$/)[0] || ($protocol eq 'https' ? 443 : 80);
Branch: 1 branch
BranchTrueFalseTotal
$protocol eq 'https' ? : 0 58 58
Condition66%2/3
($vh =~ /:(\d+)$/)[0] || ($protocol eq 'https' ? 443 : 80)
l!l&&r!l&&!r
6580
MC/DC0%0/2
($vh =~ /:(\d+)$/)[0] || ($protocol eq 'https' ? 443 : 80)
($vh =~ /:(\d+)$/)[0] ($protocol eq 'https' ? 443 : 80)
Truth table66%2/3
A || B
A= ($vh =~ /:(\d+)$/)[0]B= ($protocol eq 'https' ? 443 : 80)
ABresult
1X1
011
000
3310 } else {
3311 47 return $self->server_port();
3312 }
3313 }
3314  
3315 #### Method: server_port
3316 # Return the tcp/ip port the server is running on
3317 ####
3318 251 ▶sub server_port {
Subroutine server_port: called CC=2 SCAR=6.9
Pod documented
3319 251 ▶ return $ENV{'SERVER_PORT'} || 80; # for debugging
Condition100%2/2
$ENV{'SERVER_PORT'} || 80
l!l
20645
MC/DC100%1/1
$ENV{'SERVER_PORT'} || 80
$ENV{'SERVER_PORT'}
Truth table100%2/2
A
A= $ENV{'SERVER_PORT'}
Aresult
11
00
3320 }
3321  
3322 #### Method: server_protocol
3323 # Return the protocol (usually HTTP/1.0)
3324 ####
3325 203 ▶sub server_protocol {
Subroutine server_protocol: called CC=2 SCAR=6.9
Pod documented
3326 203 ▶ return $ENV{'SERVER_PROTOCOL'} || 'HTTP/1.0'; # for debugging
Condition100%2/2
$ENV{'SERVER_PROTOCOL'} || 'HTTP/1.0'
l!l
97106
MC/DC100%1/1
$ENV{'SERVER_PROTOCOL'} || 'HTTP/1.0'
$ENV{'SERVER_PROTOCOL'}
Truth table100%2/2
A
A= $ENV{'SERVER_PROTOCOL'}
Aresult
11
00
3327 }
3328  
3329 #### Method: http
3330 # Return the value of an HTTP variable, or
3331 # the list of variables if none provided
3332 ####
3333 19 ▶sub http {
Subroutine http: called CC=3 SCAR=11.0
Pod documented
3334 19 my ($self,$parameter) = self_or_CGI(@_);
3335 19 ▶ if ( defined($parameter) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $parameter) 17 2 19
3336 17 $parameter =~ tr/-a-z/_A-Z/;
3337 17 ▶ if ( $parameter =~ /^HTTP(?:_|$)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parameter =~ /^HTTP(?:_|$)/) 2 15 17
3338 2 return $ENV{$parameter};
3339 }
3340 15 return $ENV{"HTTP_$parameter"};
3341 }
3342 2 return grep { /^HTTP(?:_|$)/ } sort keys %ENV;
3343 }
3344  
3345 #### Method: https
3346 # Return the value of HTTPS, or
3347 # the value of an HTTPS variable, or
3348 # the list of variables
3349 ####
3350 206 ▶sub https {
Subroutine https: called CC=4 SCAR=17.9
Pod documented
3351 206 my ($self,$parameter) = self_or_CGI(@_);
3352 206 ▶ if ( defined($parameter) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $parameter) 0 206 206
3353 0 $parameter =~ tr/-a-z/_A-Z/;
3354 0 ▶ if ( $parameter =~ /^HTTPS(?:_|$)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parameter =~ /^HTTPS(?:_|$)/) 0 0 0
3355 0 return $ENV{$parameter};
3356 }
3357 0 return $ENV{"HTTPS_$parameter"};
3358 }
3359 return wantarray
3360 35 ? grep { /^HTTPS(?:_|$)/ } sort keys %ENV
3361 206 ▶ : $ENV{'HTTPS'};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 205 206
3362 }
3363  
3364 #### Method: protocol
3365 # Return the protocol (http or https currently)
3366 ####
3367 203 ▶sub protocol {
Subroutine protocol: called CC=3 SCAR=11.2
Pod undocumented
3368 203 local($^W)=0;
3369 203 my $self = shift;
3370 203 ▶ return 'https' if uc($self->https()) eq 'ON';
Branch: 1 branch
BranchTrueFalseTotal
if uc $self->https eq "ON" 0 203 203
3371 203 ▶ return 'https' if $self->server_port == 443;
Branch: 1 branch
BranchTrueFalseTotal
if $self->server_port == 443 0 203 203
3372 203 my $prot = $self->server_protocol;
3373 203 my($protocol,$version) = split('/',$prot);
3374 203 return "\L$protocol\E";
3375 }
3376  
3377 #### Method: remote_ident
3378 # Return the identity of the remote user
3379 # (but only if his host is running identd)
3380 ####
3381 0 ▶sub remote_ident {
Subroutine remote_ident: not called CC=2 SCAR=17.9
Pod documented
3382 0 ▶ return (defined $ENV{'REMOTE_IDENT'}) ? $ENV{'REMOTE_IDENT'} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $ENV{'REMOTE_IDENT'} ? : 0 0 0
3383 }
3384  
3385 #### Method: auth_type
3386 # Return the type of use verification/authorization in use, if any.
3387 ####
3388 0 ▶sub auth_type {
Subroutine auth_type: not called CC=2 SCAR=17.9
Pod documented
3389 0 ▶ return (defined $ENV{'AUTH_TYPE'}) ? $ENV{'AUTH_TYPE'} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $ENV{'AUTH_TYPE'} ? : 0 0 0
3390 }
3391  
3392 #### Method: remote_user
3393 # Return the authorization name used for user
3394 # verification.
3395 ####
3396 0 ▶sub remote_user {
Subroutine remote_user: not called CC=2 SCAR=17.9
Pod documented
3397 0 ▶ return (defined $ENV{'REMOTE_USER'}) ? $ENV{'REMOTE_USER'} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $ENV{'REMOTE_USER'} ? : 0 0 0
3398 }
3399  
3400 #### Method: user_name
3401 # Try to return the remote user's name by hook or by
3402 # crook
3403 ####
3404 0 ▶sub user_name {
Subroutine user_name: not called CC=3 SCAR=24.8
Pod documented
3405 0 my ($self) = self_or_CGI(@_);
3406 0 ▶ return $self->http('from') || $ENV{'REMOTE_IDENT'} || $ENV{'REMOTE_USER'};
Condition0%0/6
$self->http('from') || $ENV{'REMOTE_IDENT'} || $ENV{'REMOTE_USER'}
l!l&&r!l&&!r
000
$self->http("from") or $ENV{"REMOTE_IDENT"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$self->http('from') || $ENV{'REMOTE_IDENT'} || $ENV{'REMOTE_USER'}
$self->http("from") $ENV{"REMOTE_IDENT"} $ENV{'REMOTE_USER'}
Truth table0%0/4
A or B || C
A= $self->http("from")B= $ENV{"REMOTE_IDENT"}C= $ENV{'REMOTE_USER'}
ABCresult
1XX1
01X1
0011
0000
3407 }
3408  
3409 #### Method: nosticky
3410 # Set or return the NOSTICKY global flag
3411 ####
3412 1 ▶sub nosticky {
Subroutine nosticky: called CC=2 SCAR=7.1
Pod undocumented
3413 1 my ($self,$param) = self_or_CGI(@_);
3414 1 ▶ $CGI::NOSTICKY = $param if defined($param);
Branch: 1 branch
BranchTrueFalseTotal
if defined $param 1 0 1
3415 1 return $CGI::NOSTICKY;
3416 }
3417  
3418 #### Method: nph
3419 # Set or return the NPH global flag
3420 ####
3421 1 ▶sub nph {
Subroutine nph: called CC=2 SCAR=7.1
Pod documented
3422 1 my ($self,$param) = self_or_CGI(@_);
3423 1 ▶ $CGI::NPH = $param if defined($param);
Branch: 1 branch
BranchTrueFalseTotal
if defined $param 1 0 1
3424 1 return $CGI::NPH;
3425 }
3426  
3427 #### Method: private_tempfiles
3428 # Set or return the private_tempfiles global flag
3429 ####
3430 1 ▶sub private_tempfiles {
Subroutine private_tempfiles: called CC=1 SCAR=0.0
Pod undocumented
3431 1 warn "private_tempfiles has been deprecated";
3432 1 return 0;
3433 }
3434 #### Method: close_upload_files
3435 # Set or return the close_upload_files global flag
3436 ####
3437 1 ▶sub close_upload_files {
Subroutine close_upload_files: called CC=2 SCAR=7.1
Pod undocumented
3438 1 my ($self,$param) = self_or_CGI(@_);
3439 1 ▶ $CGI::CLOSE_UPLOAD_FILES = $param if defined($param);
Branch: 1 branch
BranchTrueFalseTotal
if defined $param 1 0 1
3440 1 return $CGI::CLOSE_UPLOAD_FILES;
3441 }
3442  
3443 #### Method: default_dtd
3444 # Set or return the default_dtd global
3445 ####
3446 1 ▶sub default_dtd {
Subroutine default_dtd: called CC=4 SCAR=17.9
Pod undocumented
3447 1 my ($self,$param,$param2) = self_or_CGI(@_);
3448 1 ▶ if (defined $param2 && defined $param) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $param2 and defined $param) { } 0 1 1
elsif (defined $param) { } 0 1 1
Condition33%1/3
defined $param2 and defined $param
!ll&&!rl&&r
100
MC/DC0%0/2
defined $param2 and defined $param
defined $param2 defined $param
Truth table33%1/3
A and B
A= defined $param2B= defined $param
ABresult
0X0
100
111
3449 0 $CGI::DEFAULT_DTD = [ $param, $param2 ];
3450 } elsif (defined $param) {
3451 0 $CGI::DEFAULT_DTD = $param;
3452 }
3453 1 return $CGI::DEFAULT_DTD;
3454 }
3455  
3456 # -------------- really private subroutines -----------------
3457 430 ▶sub _maybe_escapeHTML {
Subroutine _maybe_escapeHTML: called CC=6 SCAR=18.7
3458 # hack to work around earlier hacks
3459 430 ▶ push @_,$_[0] if @_==1 && $_[0] eq 'CGI';
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 and $_[0] eq "CGI" 0 430 430
Condition33%1/3
@_ == 1 and $_[0] eq "CGI"
!ll&&!rl&&r
43000
MC/DC0%0/2
@_ == 1 and $_[0] eq "CGI"
@_ == 1 $_[0] eq "CGI"
Truth table33%1/3
A and B
A= @_ == 1B= $_[0] eq "CGI"
ABresult
0X0
100
111
3460 430 my ($self,$toencode,$newlinestoo) = CGI::self_or_default(@_);
3461 430 ▶ return undef unless defined($toencode);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $toencode 16 414 430
3462 414 ▶ return $toencode if ref($self) && !$self->{'escape'};
Branch: 1 branch
BranchTrueFalseTotal
if ref $self and not $self->{"escape"} 60 354 414
Condition66%2/3
ref $self and not $self->{"escape"}
!ll&&!rl&&r
035460
MC/DC50%1/2
ref $self and not $self->{"escape"}
ref $self not $self->{"escape"}
Truth table66%2/3
A and not(B)
A= ref $selfB= not $self->{"escape"}
ABresult
0X0
100
111
3463 354 return $self->escapeHTML($toencode, $newlinestoo);
3464 }
3465  
3466 25 ▶sub previous_or_default {
Subroutine previous_or_default: called CC=10 SCAR=23.1
Pod undocumented
3467 25 my($self,$name,$defaults,$override) = @_;
3468 25 my(%selected);
3469  
3470 25 ▶ if (!$override && ($self->{'.fieldnames'}->{$name} ||
Branch: 2 branches
BranchTrueFalseTotal
if (not $override and $self->{'.fieldnames'}{$name} || defined $self->param($name)) { } 15 10 25
elsif (defined $defaults and ref $defaults and ref $defaults eq 'ARRAY') { } 6 4 10
Condition83%5/6
not $override and $self->{".fieldnames"}{$name} || defined $self->param($name)
!ll&&!rl&&r
3715
$self->{".fieldnames"}{$name} or defined $self->param($name)
l!l&&r!l&&!r
0157
MC/DC66%2/3
not $override and $self->{".fieldnames"}{$name} || defined $self->param($name)
not $override $self->{".fieldnames"}{$name} defined $self->param($name)
Truth table75%3/4
not(A) and B or C
A= not $overrideB= $self->{".fieldnames"}{$name}C= defined $self->param($name)
ABCresult
0XX0
1000
11X1
1011
3471 defined($self->param($name)) ) ) {
3472 15 $selected{$_}++ for $self->param($name);
3473 ▶ } elsif (defined($defaults) && ref($defaults) &&
Condition83%5/6
defined $defaults and ref $defaults and ref $defaults eq "ARRAY"
!ll&&!rl&&r
406
defined $defaults and ref $defaults
!ll&&!rl&&r
136
MC/DC66%2/3
defined $defaults and ref $defaults and ref $defaults eq "ARRAY"
defined $defaults ref $defaults ref $defaults eq "ARRAY"
Truth table75%3/4
A and B and C
A= defined $defaultsB= ref $defaultsC= ref $defaults eq "ARRAY"
ABCresult
0XX0
10X0
1100
1111
3474 (ref($defaults) eq 'ARRAY')) {
3475 6 $selected{$_}++ for @{$defaults};
3476 } else {
3477 4 ▶ $selected{$defaults}++ if defined($defaults);
Branch: 1 branch
BranchTrueFalseTotal
if defined $defaults 3 1 4
3478 }
3479  
3480 25 return %selected;
3481 }
3482  
3483 34 ▶sub register_parameter {
Subroutine register_parameter: called CC=1 SCAR=0.0
Pod undocumented
3484 34 my($self,$param) = @_;
3485 34 $self->{'.parametersToAdd'}->{$param}++;
3486 }
3487  
3488 1 ▶sub get_fields {
Subroutine get_fields: called CC=1 SCAR=0.0
Pod undocumented
3489 1 my($self) = @_;
3490 return $self->CGI::hidden('-name'=>'.cgifields',
3491 1 '-values'=>[sort keys %{$self->{'.parametersToAdd'}}],
3492 '-override'=>1);
3493 }
3494  
3495 79 ▶sub read_from_cmdline {
Subroutine read_from_cmdline: called CC=7 SCAR=20.2
Pod undocumented
3496 79 my($input,@words);
3497 79 my($query_string);
3498 79 my($subpath);
3499 79 ▶ if ($DEBUG && @ARGV) {
Branch: 2 branches
BranchTrueFalseTotal
if ($DEBUG and @ARGV) { } 2 77 79
elsif ($DEBUG > 1) { } 0 77 77
Condition66%2/3
$DEBUG and @ARGV
!ll&&!rl&&r
0772
MC/DC50%1/2
$DEBUG and @ARGV
$DEBUG @ARGV
Truth table66%2/3
A and B
A= $DEBUGB= @ARGV
ABresult
0X0
100
111
3500 2 @words = @ARGV;
3501 } elsif ($DEBUG > 1) {
3502 0 require Text::ParseWords;
3503 0 print STDERR "(offline mode: enter name=value pairs on standard input; press ^D or ^Z when done)\n";
3504 0 chomp(@lines = <STDIN>); # remove newlines
3505 0 $input = join(" ",@lines);
3506 0 @words = &Text::ParseWords::old_shellwords($input);
3507 }
3508 79 for (@words) {
3509 3 s/\\=/%3D/g;
3510 3 s/\\&/%26/g;
3511 }
3512  
3513 79 ▶ if ("@words"=~/=/) {
Branch: 1 branch
BranchTrueFalseTotal
if (join($", @words) =~ /=/) { } 2 77 79
3514 2 $query_string = join('&',@words);
3515 } else {
3516 77 $query_string = join('+',@words);
3517 }
3518 79 ▶ if ($query_string =~ /^(.*?)\?(.*)$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($query_string =~ /^(.*?)\?(.*)$/) 1 78 79
3519 {
3520 1 $query_string = $2;
3521 1 $subpath = $1;
3522 }
3523 79 return { 'query_string' => $query_string, 'subpath' => $subpath };
3524 }
3525  
3526 #####
3527 # subroutine: read_multipart
3528 #
3529 # Read multipart data and store it into our parameters.
3530 # An interesting feature is that if any of the parts is a file, we
3531 # create a temporary file and open up a filehandle on it so that the
3532 # caller can read from it if necessary.
3533 #####
3534 1758 ▶sub read_multipart {
Subroutine read_multipart: called CC=37 SCAR=41.4
Pod undocumented
3535 1758 my($self,$boundary,$length) = @_;
3536 1758 my($buffer) = $self->new_MultipartBuffer($boundary,$length);
3537 1742 ▶ return unless $buffer;
Branch: 1 branch
BranchTrueFalseTotal
unless $buffer 0 1742 1742
3538 1742 my(%header,$body);
3539 1742 my $filenumber = 0;
3540 1742 my ( $parts,$uploads ) = ( 0,0 );
3541 1742 ▶ while (!$buffer->eof) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $buffer->eof) 3612 1737 5349
3542 3612 %header = $buffer->readHeader;
3543  
3544 3611 ▶ unless (%header) {
Branch: 1 branch
BranchTrueFalseTotal
unless (%header) 1 3610 3611
3545 1 $self->cgi_error("400 Bad request (malformed multipart POST)");
3546 1 return;
3547 }
3548  
3549 # every part costs time to parse (even those that are then skipped),
3550 # and every upload a temp file, so limit their number - the reader is
3551 # run by _within_request_limits
3552 3610 ▶ die $REQUEST_TOO_LARGE if $MAX_PARAMS > 0 && ++$parts > $MAX_PARAMS;
Branch: 1 branch
BranchTrueFalseTotal
if $MAX_PARAMS > 0 and ++$parts > $MAX_PARAMS 2 3608 3610
Condition66%2/3
$MAX_PARAMS > 0 and ++$parts > $MAX_PARAMS
!ll&&!rl&&r
036082
MC/DC50%1/2
$MAX_PARAMS > 0 and ++$parts > $MAX_PARAMS
$MAX_PARAMS > 0 ++$parts > $MAX_PARAMS
Truth table66%2/3
A and B
A= $MAX_PARAMS > 0B= ++$parts > $MAX_PARAMS
ABresult
0X0
100
111
3553  
3554 3608 ▶ $header{'Content-Disposition'} ||= ''; # quench uninit variable warning
Condition50%1/2
$header{"Content-Disposition"} ||= ""
l!l
36080
MC/DC0%0/1
$header{"Content-Disposition"} ||= ""
$header{"Content-Disposition"}
Truth table50%1/2
A
A= $header{"Content-Disposition"}
Aresult
11
00
3555  
3556 3608 my $disposition = _mp_disposition_params( $header{'Content-Disposition'} );
3557 3608 my $param = _mp_value_parse( $disposition,'name' );
3558 3608 $param .= $TAINTED;
3559  
3560 # See RFC 1867, 2183, 2045
3561 # NB: File content will be loaded into memory should
3562 # content-disposition parsing fail.
3563 3608 my $filename = _mp_value_parse( $disposition,'filename' );
3564  
3565 3608 ▶ $filename ||= ''; # quench uninit variable warning
Condition100%2/2
$filename ||= ""
l!l
1623446
MC/DC100%1/1
$filename ||= ""
$filename
Truth table100%2/2
A
A= $filename
Aresult
11
00
3566  
3567 3608 $filename .= $TAINTED; # regex captures are untainted
3568 # Test for Opera's multiple upload feature
3569 my($multipart) = ( defined( $header{'Content-Type'} ) &&
3570 3608 ▶ $header{'Content-Type'} =~ /multipart\/mixed/ ) ?
Branch: 1 branch
BranchTrueFalseTotal
defined $header{'Content-Type'} && $header{'Content-Type'} =~ m[multipart/mixed] ? : 0 3608 3608
Condition66%2/3
defined $header{"Content-Type"} and $header{"Content-Type"} =~ m[multipart/mixed]
!ll&&!rl&&r
3554540
MC/DC0%0/2
defined $header{"Content-Type"} and $header{"Content-Type"} =~ m[multipart/mixed]
defined $header{"Content-Type"} $header{"Content-Type"} =~ m[multipart/mixed]
Truth table66%2/3
A and B
A= defined $header{"Content-Type"}B= $header{"Content-Type"} =~ m[multipart/mixed]
ABresult
0X0
100
111
3571 1 : 0;
3572  
3573 # skip a field using one of the names reserved for the request body
3574 3608 ▶ if ( $RESERVED_PARAM{$param} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($RESERVED_PARAM{$param}) 9 3599 3608
3575 9 ▶ while ( defined( $buffer->read ) ) { }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $buffer->read) 9 9 18
3576 9 next;
3577 }
3578  
3579 # add this parameter to our list
3580 3599 $self->add_parameter($param);
3581  
3582 # If no filename specified, then just read the data and assign it
3583 # to our parameter list.
3584 3599 ▶ if ( ( !defined($filename) || $filename eq '' ) && !$multipart ) {
Branch: 1 branch
BranchTrueFalseTotal
if (!defined($filename) || $filename eq "" and not $multipart) 3438 161 3599
Condition66%4/6
!defined($filename) || $filename eq "" and not $multipart
!ll&&!rl&&r
16103438
not defined $filename or $filename eq ""
l!l&&r!l&&!r
03438161
MC/DC33%1/3
!defined($filename) || $filename eq "" and not $multipart
not defined $filename $filename eq "" not $multipart
Truth table40%2/5
not(A) or B and not(C)
A= not defined $filenameB= $filename eq ""C= not $multipart
ABCresult
00X0
1X00
0100
1X11
0111
3585 3438 my($value) = $buffer->readBody;
3586 3438 $value .= $TAINTED;
3587 3438 push(@{$self->{param}{$param}},$value);
3588 3438 next;
3589 }
3590  
3591 # the filename is client supplied, so remove any path from it
3592 161 ▶ $filename = _sanitize_upload_filename( $filename )
Branch: 1 branch
BranchTrueFalseTotal
if $SANITIZE_UPLOAD_FILENAMES and $filename ne "" 143 18 161
Condition66%2/3
$SANITIZE_UPLOAD_FILENAMES and $filename ne ""
!ll&&!rl&&r
180143
MC/DC50%1/2
$SANITIZE_UPLOAD_FILENAMES and $filename ne ""
$SANITIZE_UPLOAD_FILENAMES $filename ne ""
Truth table66%2/3
A and B
A= $SANITIZE_UPLOAD_FILENAMESB= $filename ne ""
ABresult
0X0
100
111
3593 if $SANITIZE_UPLOAD_FILENAMES && $filename ne '';
3594  
3595 UPLOADS: {
3596 # If we get here, then we are dealing with a potentially large
3597 # uploaded form. Save the data to a temporary file, then open
3598 # the file for reading.
3599  
3600 # skip the file if uploads disabled
3601 161 ▶ if ($DISABLE_UPLOADS) {
Branch: 1 branch
BranchTrueFalseTotal
if ($DISABLE_UPLOADS) 0 161 161
3602 0 ▶ while (defined($data = $buffer->read)) { }
Branch: 1 branch
BranchTrueFalseTotal
if (defined($data = $buffer->read)) 0 0 0
3603 0 last UPLOADS;
3604 }
3605  
3606 # set the filename to some recognizable value
3607 161 ▶ if ( ( !defined($filename) || $filename eq '' ) && $multipart ) {
Branch: 1 branch
BranchTrueFalseTotal
if (!defined($filename) || $filename eq "" and $multipart) 0 161 161
Condition33%2/6
!defined($filename) || $filename eq "" and $multipart
!ll&&!rl&&r
16100
not defined $filename or $filename eq ""
l!l&&r!l&&!r
00161
MC/DC0%0/3
!defined($filename) || $filename eq "" and $multipart
not defined $filename $filename eq "" $multipart
Truth table20%1/5
not(A) or B and C
A= not defined $filenameB= $filename eq ""C= $multipart
ABCresult
00X0
1X00
0100
1X11
0111
3608 0 $filename = "multipart/mixed";
3609 }
3610  
3611 my $tmp_dir = $CGI::OS eq 'WINDOWS'
3612 161 ▶ ? ( $ENV{TEMP} || $ENV{TMP} || ( $ENV{WINDIR} ? ( $ENV{WINDIR} . $SL . 'TEMP' ) : undef ) )
Branch: 2 branches
BranchTrueFalseTotal
$OS eq 'WINDOWS' ? : 0 161 161
$ENV{'WINDIR'} ? : 0 0 0
Condition0%0/6
$ENV{"TEMP"} or $ENV{"TMP"} or $ENV{"WINDIR"} ? $ENV{"WINDIR"} . $SL . 'TEMP' : undef
l!l&&r!l&&!r
000
$ENV{"TEMP"} or $ENV{"TMP"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$ENV{"TEMP"} or $ENV{"TMP"} or $ENV{"WINDIR"} ? $ENV{"WINDIR"} . $SL . 'TEMP' : undef
$ENV{"TEMP"} $ENV{"TMP"} $ENV{"WINDIR"} ? $ENV{"WINDIR"} . $SL . 'TEMP' : undef
Truth table0%0/4
A or B or C
A= $ENV{"TEMP"}B= $ENV{"TMP"}C= $ENV{"WINDIR"} ? $ENV{"WINDIR"} . $SL . 'TEMP' : undef
ABCresult
1XX1
01X1
0011
0000
3613 : undef; # File::Temp defaults to TMPDIR
3614  
3615 161 ▶ die $REQUEST_TOO_LARGE if $MAX_UPLOADS > 0 && ++$uploads > $MAX_UPLOADS;
Branch: 1 branch
BranchTrueFalseTotal
if $MAX_UPLOADS > 0 and ++$uploads > $MAX_UPLOADS 1 160 161
Condition100%3/3
$MAX_UPLOADS > 0 and ++$uploads > $MAX_UPLOADS
!ll&&!rl&&r
201401
MC/DC100%2/2
$MAX_UPLOADS > 0 and ++$uploads > $MAX_UPLOADS
$MAX_UPLOADS > 0 ++$uploads > $MAX_UPLOADS
Truth table100%3/3
A and B
A= $MAX_UPLOADS > 0B= ++$uploads > $MAX_UPLOADS
ABresult
0X0
100
111
3616  
3617 160 require CGI::File::Temp;
3618 160 my $filehandle = CGI::File::Temp->new(
3619 UNLINK => $UNLINK_TMP_FILES,
3620 DIR => $tmp_dir,
3621 );
3622 160 $filehandle->_mp_filename( $filename );
3623  
3624 160 ▶ $CGI::DefaultClass->binmode($filehandle) if $CGI::needs_binmode
Branch: 1 branch
BranchTrueFalseTotal
if $needs_binmode and defined fileno $filehandle 0 160 160
Condition33%1/3
$needs_binmode and defined fileno $filehandle
!ll&&!rl&&r
16000
MC/DC0%0/2
$needs_binmode and defined fileno $filehandle
$needs_binmode defined fileno $filehandle
Truth table33%1/3
A and B
A= $needs_binmodeB= defined fileno $filehandle
ABresult
0X0
100
111
3625 && defined fileno($filehandle);
3626  
3627 # if this is an multipart/mixed attachment, save the header
3628 # together with the body for later parsing with an external
3629 # MIME parser module
3630 160 ▶ if ( $multipart ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($multipart) 0 160 160
3631 0 for ( sort keys %header ) {
3632 0 print $filehandle "$_: $header{$_}${CRLF}";
3633 }
3634 0 print $filehandle "${CRLF}";
3635 }
3636  
3637 160 my ($data);
3638 160 local($\) = '';
3639 160 my $totalbytes = 0;
3640 160 ▶ while (defined($data = $buffer->read)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($data = $buffer->read)) 248 160 408
3641 248 ▶ if (defined $self->{'.upload_hook'})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{".upload_hook"}) 37 211 248
3642 {
3643 37 $totalbytes += length($data);
3644 37 &{$self->{'.upload_hook'}}($filename ,$data, $totalbytes, $self->{'.upload_data'});
3645 }
3646 248 ▶ print $filehandle $data if ($self->{'use_tempfile'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"use_tempfile"} 248 0 248
3647 }
3648  
3649 # back up to beginning of file
3650 160 seek($filehandle,0,0);
3651  
3652 ## Close the filehandle if requested this allows a multipart MIME
3653 ## upload to contain many files, and we won't die due to too many
3654 ## open file handles. The user can access the files using the hash
3655 ## below.
3656 160 ▶ close $filehandle if $CLOSE_UPLOAD_FILES;
Branch: 1 branch
BranchTrueFalseTotal
if $CLOSE_UPLOAD_FILES 0 160 160
3657 160 ▶ $CGI::DefaultClass->binmode($filehandle) if $CGI::needs_binmode;
Branch: 1 branch
BranchTrueFalseTotal
if $needs_binmode 0 160 160
3658  
3659 # Save some information about the uploaded file where we can get
3660 # at it later.
3661 # Use the typeglob + filename as the key, as this is guaranteed to be
3662 # unique for each filehandle. Don't use the file descriptor as
3663 # this will be re-used for each filehandle if the
3664 # close_upload_files feature is used.
3665 160 $self->{'.tmpfiles'}->{$filehandle->filename . $filehandle} = {
3666 hndl => $filehandle,
3667 name => $filehandle->filename,
3668 info => {%header},
3669 };
3670 160 push(@{$self->{param}{$param}},$filehandle);
3671 }
3672 }
3673 }
3674  
3675 # The upload filename is client supplied and may contain a path (older
3676 # browsers send the full path, and an attacker can send anything), so it
3677 # must not be usable for path traversal if an application uses it when
3678 # saving the upload. Remove control characters and any directory part,
3679 # splitting on both / and \ so Windows paths are handled too. The raw
3680 # value remains available via uploadInfo()->{'Content-Disposition'}.
3681 143 ▶sub _sanitize_upload_filename {
Subroutine _sanitize_upload_filename: called CC=4 SCAR=13.9
3682 143 my ( $filename ) = @_;
3683 143 $filename =~ s/[\x00-\x1f\x7f]//g;
3684 143 $filename =~ s/.*[\/\\]//s;
3685 # nothing usable left, but this is still a file upload so must have a
3686 # (true) name - see the overloaded stringification in CGI::File::Temp
3687 143 ▶ $filename = 'upload' if $filename eq '' || $filename eq '.' || $filename eq '..';
Branch: 1 branch
BranchTrueFalseTotal
if $filename eq "" or $filename eq "." or $filename eq ".." 5 138 143
Condition100%6/6
$filename eq "" or $filename eq "." or $filename eq ".."
l!l&&r!l&&!r
32138
$filename eq "" or $filename eq "."
l!l&&r!l&&!r
21140
MC/DC100%3/3
$filename eq "" or $filename eq "." or $filename eq ".."
$filename eq "" $filename eq "." $filename eq ".."
Truth table100%4/4
A or B or C
A= $filename eq ""B= $filename eq "."C= $filename eq ".."
ABCresult
1XX1
01X1
0011
0000
3688 143 return $filename;
3689 }
3690  
3691 # Split a Content-Disposition value into its parameters, left to right, so
3692 # that a quoted value is skipped as a whole - searching the whole string
3693 # for e.g. "name=" found it inside another parameter's quoted value, so
3694 # filename="x;name=admin"; name=user gave a field name of "admin", and
3695 # name="x filename=y" made a plain field an upload. Returns a list of
3696 # [ name, raw value (quotes included, undef if there is no =) ].
3697 3608 ▶sub _mp_disposition_params {
Subroutine _mp_disposition_params: called CC=4 SCAR=13.9
3698 3608 my ( $string ) = @_;
3699 3608 my @params;
3700 3608 ▶ $string = '' unless defined $string;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $string 0 3608 3608
3701 3608 $string =~ /\G[^;]*/gc; # the disposition type
3702 3608 ▶ while ( $string =~ /\G;[ \t]*/gc ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ /\G;[ \t]*/cg) 3776 3608 7384
3703 3776 $string =~ /\G([^\s=;"]*)/gc;
3704 3776 my ( $name,$value ) = ( $1 );
3705 3776 ▶ if ( $string =~ /\G=/gc ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ /\G=/cg) 3776 0 3776
3706 # a quoted string (which may be unterminated), else up to the next ;
3707 3776 $string =~ /\G("(?:\\"|[^"])*"?|[^;]*)/gc;
3708 3776 $value = $1;
3709 }
3710 3776 push( @params,[ $name,$value ] );
3711 3776 $string =~ /\G[^;]*/gc; # skip anything else up to the next ;
3712 }
3713 3608 return \@params;
3714 }
3715  
3716 # Get the value of the name or filename parameter (the first occurrence)
3717 # from the output of _mp_disposition_params
3718 7216 ▶sub _mp_value_parse {
Subroutine _mp_value_parse: called CC=9 SCAR=22.0
3719 7216 my ( $params,$field ) = @_;
3720  
3721 3773 my ( $raw ) = map { $_->[1] } grep {
3722 7216 ▶ defined $_->[1] && ( $field eq 'filename' ? lc( $_->[0] ) eq $field : $_->[0] eq $field )
Branch: 1 branch
BranchTrueFalseTotal
$field eq 'filename' ? : 3776 3776 7552
Condition66%2/3
defined $_->[1] && ($field eq 'filename' ? lc $_->[0] eq $field : $_->[0] eq $field)
!ll&&!rl&&r
037793773
MC/DC50%1/2
defined $_->[1] && ($field eq 'filename' ? lc $_->[0] eq $field : $_->[0] eq $field)
defined $_->[1] ($field eq 'filename' ? lc $_->[0] eq $field : $_->[0] eq $field)
Truth table66%2/3
A && B
A= defined $_->[1]B= ($field eq 'filename' ? lc $_->[0] eq $field : $_->[0] eq $field)
ABresult
0X0
100
111
3723 } @$params;
3724 7216 ▶ return undef unless defined $raw;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $raw 3444 3772 7216
3725  
3726 3772 ▶ if ( $field eq 'filename' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($field eq "filename") 164 3608 3772
3727 164 ▶ return $1 if $raw =~ /\A"([^"]*)"/;
Branch: 1 branch
BranchTrueFalseTotal
if $raw =~ /\A"([^"]*)"/ 155 9 164
3728 9 ▶ return '' if $raw =~ /\A"/;
Branch: 1 branch
BranchTrueFalseTotal
if $raw =~ /\A"/ 1 8 9
3729 8 return ( $raw =~ /\A([a-z\d!\#'\*\+,\.^_\`\{\}\|\~]*)/i )[0];
3730 }
3731  
3732 # a quoted token cannot contain anything but an unescaped quote
3733 3608 ▶ return $1 if $raw =~ /\A"((?:\\"|[^"])*)"/;
Branch: 1 branch
BranchTrueFalseTotal
if $raw =~ /\A"((?:\\"|[^"])*)"/ 3602 6 3608
3734 6 ▶ return undef if $raw =~ /\A"/; # unterminated
Branch: 1 branch
BranchTrueFalseTotal
if $raw =~ /\A"/ 0 6 6
3735 # a plain token cannot contain any reserved characters
3736 # https://tools.ietf.org/html/rfc2616#section-2.2
3737 # separators = "(" | ")" | "<" | ">" | "@"
3738 # | "," | ";" | ":" | "\" | <">
3739 # | "/" | "[" | "]" | "?" | "="
3740 # | "{" | "}" | SP | HT
3741 6 return ( $raw =~ /\A([^\(\)<>\@,;:\\"\/\[\]\?=\{\} \015\n\t]*)/ )[0];
3742 }
3743  
3744 #####
3745 # subroutine: read_multipart_related
3746 #
3747 # Read multipart/related data and store it into our parameters. The
3748 # first parameter sets the start of the data. The part identified by
3749 # this Content-ID will not be stored as a file upload, but will be
3750 # returned by this method. All other parts will be available as file
3751 # uploads accessible by their Content-ID
3752 #####
3753 10 ▶sub read_multipart_related {
Subroutine read_multipart_related: called CC=24 SCAR=36.8
Pod undocumented
3754 10 my($self,$start,$boundary,$length) = @_;
3755 10 my($buffer) = $self->new_MultipartBuffer($boundary,$length);
3756 8 ▶ return unless $buffer;
Branch: 1 branch
BranchTrueFalseTotal
unless $buffer 0 8 8
3757 8 my(%header,$body);
3758 8 my $filenumber = 0;
3759 8 my $returnvalue;
3760 8 my ( $parts,$uploads ) = ( 0,0 );
3761 8 ▶ while (!$buffer->eof) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($buffer->eof) 23 6 29
3762 23 %header = $buffer->readHeader;
3763  
3764 23 ▶ unless (%header) {
Branch: 1 branch
BranchTrueFalseTotal
unless (%header) 0 23 23
3765 0 $self->cgi_error("400 Bad request (malformed multipart POST)");
3766 0 return;
3767 }
3768  
3769 # limit the number of parts, as in read_multipart
3770 23 ▶ die $REQUEST_TOO_LARGE if $MAX_PARAMS > 0 && ++$parts > $MAX_PARAMS;
Branch: 1 branch
BranchTrueFalseTotal
if $MAX_PARAMS > 0 and ++$parts > $MAX_PARAMS 1 22 23
Condition66%2/3
$MAX_PARAMS > 0 and ++$parts > $MAX_PARAMS
!ll&&!rl&&r
0221
MC/DC50%1/2
$MAX_PARAMS > 0 and ++$parts > $MAX_PARAMS
$MAX_PARAMS > 0 ++$parts > $MAX_PARAMS
Truth table66%2/3
A and B
A= $MAX_PARAMS > 0B= ++$parts > $MAX_PARAMS
ABresult
0X0
100
111
3771  
3772 22 my($param) = $header{'Content-ID'}=~/\<([^\>]*)\>/;
3773 22 $param .= $TAINTED;
3774  
3775 # If this is the start part, then just read the data and assign it
3776 # to our return variable.
3777 22 ▶ if ( $param eq $start ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($param eq $start) 7 15 22
3778 7 $returnvalue = $buffer->readBody;
3779 7 $returnvalue .= $TAINTED;
3780 7 next;
3781 }
3782  
3783 # skip a part using one of the names reserved for the request body
3784 15 ▶ if ( $RESERVED_PARAM{$param} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($RESERVED_PARAM{$param}) 2 13 15
3785 2 ▶ while ( defined( $buffer->read ) ) { }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $buffer->read) 2 2 4
3786 2 next;
3787 }
3788  
3789 # add this parameter to our list
3790 13 $self->add_parameter($param);
3791  
3792 UPLOADS: {
3793 # If we get here, then we are dealing with a potentially large
3794 # uploaded form. Save the data to a temporary file, then open
3795 # the file for reading.
3796  
3797 # skip the file if uploads disabled
3798 13 ▶ if ($DISABLE_UPLOADS) {
Branch: 1 branch
BranchTrueFalseTotal
if ($DISABLE_UPLOADS) 0 13 13
3799 0 ▶ while (defined($data = $buffer->read)) { }
Branch: 1 branch
BranchTrueFalseTotal
if (defined($data = $buffer->read)) 0 0 0
3800 0 last UPLOADS;
3801 }
3802  
3803 my $tmp_dir = $CGI::OS eq 'WINDOWS'
3804 13 ▶ ? ( $ENV{TEMP} || $ENV{TMP} || ( $ENV{WINDIR} ? ( $ENV{WINDIR} . $SL . 'TEMP' ) : undef ) )
Branch: 2 branches
BranchTrueFalseTotal
$OS eq 'WINDOWS' ? : 0 13 13
$ENV{'WINDIR'} ? : 0 0 0
Condition0%0/6
$ENV{"TEMP"} or $ENV{"TMP"} or $ENV{"WINDIR"} ? $ENV{"WINDIR"} . $SL . 'TEMP' : undef
l!l&&r!l&&!r
000
$ENV{"TEMP"} or $ENV{"TMP"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$ENV{"TEMP"} or $ENV{"TMP"} or $ENV{"WINDIR"} ? $ENV{"WINDIR"} . $SL . 'TEMP' : undef
$ENV{"TEMP"} $ENV{"TMP"} $ENV{"WINDIR"} ? $ENV{"WINDIR"} . $SL . 'TEMP' : undef
Truth table0%0/4
A or B or C
A= $ENV{"TEMP"}B= $ENV{"TMP"}C= $ENV{"WINDIR"} ? $ENV{"WINDIR"} . $SL . 'TEMP' : undef
ABCresult
1XX1
01X1
0011
0000
3805 : undef; # File::Temp defaults to TMPDIR
3806  
3807 13 ▶ die $REQUEST_TOO_LARGE if $MAX_UPLOADS > 0 && ++$uploads > $MAX_UPLOADS;
Branch: 1 branch
BranchTrueFalseTotal
if $MAX_UPLOADS > 0 and ++$uploads > $MAX_UPLOADS 1 12 13
Condition66%2/3
$MAX_UPLOADS > 0 and ++$uploads > $MAX_UPLOADS
!ll&&!rl&&r
0121
MC/DC50%1/2
$MAX_UPLOADS > 0 and ++$uploads > $MAX_UPLOADS
$MAX_UPLOADS > 0 ++$uploads > $MAX_UPLOADS
Truth table66%2/3
A and B
A= $MAX_UPLOADS > 0B= ++$uploads > $MAX_UPLOADS
ABresult
0X0
100
111
3808  
3809 12 require CGI::File::Temp;
3810 12 my $filehandle = CGI::File::Temp->new(
3811 UNLINK => $UNLINK_TMP_FILES,
3812 DIR => $tmp_dir,
3813 );
3814 12 $filehandle->_mp_filename( $filehandle->filename );
3815  
3816 12 ▶ $CGI::DefaultClass->binmode($filehandle) if $CGI::needs_binmode
Branch: 1 branch
BranchTrueFalseTotal
if $needs_binmode and defined fileno $filehandle 0 12 12
Condition33%1/3
$needs_binmode and defined fileno $filehandle
!ll&&!rl&&r
1200
MC/DC0%0/2
$needs_binmode and defined fileno $filehandle
$needs_binmode defined fileno $filehandle
Truth table33%1/3
A and B
A= $needs_binmodeB= defined fileno $filehandle
ABresult
0X0
100
111
3817 && defined fileno($filehandle);
3818  
3819 12 my ($data);
3820 12 local($\) = '';
3821 12 my $totalbytes;
3822 12 ▶ while (defined($data = $buffer->read)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($data = $buffer->read)) 12 12 24
3823 12 ▶ if (defined $self->{'.upload_hook'})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{".upload_hook"}) 0 12 12
3824 {
3825 0 $totalbytes += length($data);
3826 0 &{$self->{'.upload_hook'}}($param ,$data, $totalbytes, $self->{'.upload_data'});
3827 }
3828 12 ▶ print $filehandle $data if ($self->{'use_tempfile'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"use_tempfile"} 12 0 12
3829 }
3830  
3831 # back up to beginning of file
3832 12 seek($filehandle,0,0);
3833  
3834 ## Close the filehandle if requested this allows a multipart MIME
3835 ## upload to contain many files, and we won't die due to too many
3836 ## open file handles. The user can access the files using the hash
3837 ## below.
3838 12 ▶ close $filehandle if $CLOSE_UPLOAD_FILES;
Branch: 1 branch
BranchTrueFalseTotal
if $CLOSE_UPLOAD_FILES 0 12 12
3839 12 ▶ $CGI::DefaultClass->binmode($filehandle) if $CGI::needs_binmode;
Branch: 1 branch
BranchTrueFalseTotal
if $needs_binmode 0 12 12
3840  
3841 # Save some information about the uploaded file where we can get
3842 # at it later.
3843 # Use the typeglob + filename as the key, as this is guaranteed to be
3844 # unique for each filehandle. Don't use the file descriptor as
3845 # this will be re-used for each filehandle if the
3846 # close_upload_files feature is used.
3847 12 $self->{'.tmpfiles'}->{$filehandle->filename . $filehandle} = {
3848 hndl => $filehandle,
3849 name => $filehandle->filename,
3850 info => {%header},
3851 };
3852 12 push(@{$self->{param}{$param}},$filehandle);
3853 }
3854 }
3855 6 return $returnvalue;
3856 }
3857  
3858 135 ▶sub upload {
Subroutine upload: called CC=4 SCAR=14.0
Pod documented
3859 135 my($self,$param_name) = self_or_default(@_);
3860 135 ▶ my @param = grep {ref($_) && defined(fileno($_))} $self->param($param_name);
Condition33%1/3
ref $_ && defined fileno $_
!ll&&!rl&&r
00136
MC/DC0%0/2
ref $_ && defined fileno $_
ref $_ defined fileno $_
Truth table33%1/3
A && B
A= ref $_B= defined fileno $_
ABresult
0X0
100
111
3861 135 ▶ return unless @param;
Branch: 1 branch
BranchTrueFalseTotal
unless @param 1 134 135
3862 134 ▶ return wantarray ? @param : $param[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 4 130 134
3863 }
3864  
3865 12 ▶sub tmpFileName {
Subroutine tmpFileName: called CC=8 SCAR=20.9
Pod undocumented
3866 12 my($self,$filename) = self_or_default(@_);
3867  
3868 # preferred calling convention: $filename came directly from param or upload
3869 12 ▶ if (ref $filename) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $filename) 7 5 12
3870 7 ▶ return $self->{'.tmpfiles'}->{$filename->filename . $filename}->{name} || '';
Condition50%1/2
$self->{'.tmpfiles'}{$filename->filename . $filename}{'name'} || ''
l!l
70
MC/DC0%0/1
$self->{'.tmpfiles'}{$filename->filename . $filename}{'name'} || ''
$self->{'.tmpfiles'}{$filename->filename . $filename}{'name'}
Truth table50%1/2
A
A= $self->{'.tmpfiles'}{$filename->filename . $filename}{'name'}
Aresult
11
00
3871 }
3872  
3873 # backwards compatible with older versions: $filename is merely equal to
3874 # one of our filenames when compared as strings
3875 5 foreach my $param_name ($self->param) {
3876 17 foreach my $filehandle ($self->multi_param($param_name)) {
3877 21 ▶ next unless ref($filehandle);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $filehandle 1 20 21
3878 20 ▶ if ($filehandle eq $filename) {
Branch: 1 branch
BranchTrueFalseTotal
if ($filehandle eq $filename) 4 16 20
3879 4 ▶ return $self->{'.tmpfiles'}->{$filehandle->filename . $filehandle}->{name} || '';
Condition50%1/2
$self->{'.tmpfiles'}{$filehandle->filename . $filehandle}{'name'} || ''
l!l
40
MC/DC0%0/1
$self->{'.tmpfiles'}{$filehandle->filename . $filehandle}{'name'} || ''
$self->{'.tmpfiles'}{$filehandle->filename . $filehandle}{'name'}
Truth table50%1/2
A
A= $self->{'.tmpfiles'}{$filehandle->filename . $filehandle}{'name'}
Aresult
11
00
3880 }
3881 }
3882 }
3883  
3884 1 return '';
3885 }
3886  
3887 68 ▶sub uploadInfo {
Subroutine uploadInfo: called CC=3 SCAR=11.0
Pod undocumented
3888 68 my($self,$filename) = self_or_default(@_);
3889 # only an upload filehandle - anything else (e.g. a plain filename from
3890 # Vars, or a param value of "0") was dereferenced as a symbolic ref, and
3891 # then a method called on it, which died
3892 68 ▶ return unless ref($filename) && UNIVERSAL::can($filename,'filename');
Branch: 1 branch
BranchTrueFalseTotal
unless ref $filename and UNIVERSAL::can($filename, "filename") 15 53 68
Condition100%3/3
ref $filename and UNIVERSAL::can($filename, "filename")
!ll&&!rl&&r
11453
MC/DC100%2/2
ref $filename and UNIVERSAL::can($filename, "filename")
ref $filename UNIVERSAL::can($filename, "filename")
Truth table100%3/3
A and B
A= ref $filenameB= UNIVERSAL::can($filename, "filename")
ABresult
0X0
100
111
3893 53 return $self->{'.tmpfiles'}->{$filename->filename . $filename}->{info};
3894 }
3895  
3896 # internal routine, don't use
3897 47 ▶sub _set_values_and_labels {
Subroutine _set_values_and_labels: called CC=6 SCAR=19.3
3898 47 my $self = shift;
3899 47 my ($v,$l,$n) = @_;
3900 47 ▶ $$l = $v if ref($v) eq 'HASH' && !ref($$l);
Branch: 1 branch
BranchTrueFalseTotal
if ref $v eq "HASH" and not ref $$l 0 47 47
Condition33%1/3
ref $v eq "HASH" and not ref $$l
!ll&&!rl&&r
4700
MC/DC0%0/2
ref $v eq "HASH" and not ref $$l
ref $v eq "HASH" not ref $$l
Truth table33%1/3
A and not(B)
A= ref $v eq "HASH"B= not ref $$l
ABresult
0X0
100
111
3901 47 ▶ return $self->param($n) if !defined($v);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 4 43 47
3902 43 ▶ return $v if !ref($v);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $v 0 43 43
3903 43 ▶ return ref($v) eq 'HASH' ? sort keys %$v : @$v;
Branch: 1 branch
BranchTrueFalseTotal
ref $v eq 'HASH' ? : 0 43 43
3904 }
3905  
3906 # internal routine, don't use
3907 88 ▶sub _set_attributes {
Subroutine _set_attributes: called CC=3 SCAR=11.0
3908 88 my $self = shift;
3909 88 my($element, $attributes) = @_;
3910 88 ▶ return '' unless defined($attributes->{$element});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $attributes->{$element} 86 2 88
3911 2 $attribs = ' ';
3912 2 for my $attrib (sort keys %{$attributes->{$element}}) {
3913 2 (my $clean_attrib = $attrib) =~ s/^-//;
3914 2 $attribs .= "@{[lc($clean_attrib)]}=\"$attributes->{$element}{$attrib}\" ";
3915 }
3916 2 $attribs =~ s/ $//;
3917 2 return $attribs;
3918 }
3919  
3920 #########################################################
3921 # Globals and stubs for other packages that we use.
3922 #########################################################
3923  
3924 ######################## CGI::MultipartBuffer ####################
3925  
3926 package CGI::MultipartBuffer;
3927  
3928 84 $_DEBUG = 0;
3929  
3930 # how many bytes to read at a time. We use
3931 # a 4K buffer by default.
3932 84 ▶$MultipartBuffer::INITIAL_FILLUNIT ||= 1024 * 4;
Condition100%2/2
$MultipartBuffer::INITIAL_FILLUNIT ||= 4096
l!l
183
MC/DC100%1/1
$MultipartBuffer::INITIAL_FILLUNIT ||= 4096
$MultipartBuffer::INITIAL_FILLUNIT
Truth table100%2/2
A
A= $MultipartBuffer::INITIAL_FILLUNIT
Aresult
11
00
3933 84 ▶$MultipartBuffer::TIMEOUT ||= 240*60; # 4 hour timeout for big files
Condition100%2/2
$MultipartBuffer::TIMEOUT ||= 14400
l!l
183
MC/DC100%1/1
$MultipartBuffer::TIMEOUT ||= 14400
$MultipartBuffer::TIMEOUT
Truth table100%2/2
A
A= $MultipartBuffer::TIMEOUT
Aresult
11
00
3934 84 ▶$MultipartBuffer::SPIN_LOOP_MAX ||= 2000; # bug fix for some Netscape servers
Condition100%2/2
$MultipartBuffer::SPIN_LOOP_MAX ||= 2000
l!l
183
MC/DC100%1/1
$MultipartBuffer::SPIN_LOOP_MAX ||= 2000
$MultipartBuffer::SPIN_LOOP_MAX
Truth table100%2/2
A
A= $MultipartBuffer::SPIN_LOOP_MAX
Aresult
11
00
3935 84 ▶$MultipartBuffer::CRLF ||= $CGI::CRLF;
Condition66%2/3
$MultipartBuffer::CRLF ||= $CGI::CRLF
l!l&&r!l&&!r
1830
MC/DC0%0/2
$MultipartBuffer::CRLF ||= $CGI::CRLF
$MultipartBuffer::CRLF $CGI::CRLF
Truth table66%2/3
A ||= B
A= $MultipartBuffer::CRLFB= $CGI::CRLF
ABresult
1X1
011
000
3936  
3937 84 $INITIAL_FILLUNIT = $MultipartBuffer::INITIAL_FILLUNIT;
3938 84 $MAX_BOUNDARY_LINE = 1024; # when the boundary is read from the body
3939 84 $MAX_BOUNDARY_LENGTH = 200; # RFC 2046 says 70, allow some slack
3940 84 $TIMEOUT = $MultipartBuffer::TIMEOUT;
3941 84 $SPIN_LOOP_MAX = $MultipartBuffer::SPIN_LOOP_MAX;
3942 84 $CRLF = $MultipartBuffer::CRLF;
3943  
3944 1768 ▶sub new {
Subroutine new: called CC=17 SCAR=28.4
3945 1768 my($package,$interface,$boundary,$length) = @_;
3946 1768 $FILLUNIT = $INITIAL_FILLUNIT;
3947 1768 $CGI::DefaultClass->binmode($IN); # if $CGI::needs_binmode; # just do it always
3948  
3949 # If the user types garbage into the file upload field,
3950 # then Netscape passes NOTHING to the server (not good).
3951 # We may hang on this read in that case. So we implement
3952 # a read timeout. If nothing is ready to read
3953 # by then, we return.
3954  
3955 # Netscape seems to be a little bit unreliable
3956 # about providing boundary strings.
3957 1768 my $boundary_read = 0;
3958 1768 my $chunked = !$length;
3959 1768 my $preread = '';
3960 1768 ▶ if ($boundary) {
Branch: 1 branch
BranchTrueFalseTotal
if ($boundary) { } 944 824 1768
3961  
3962 # Under the MIME spec, the boundary consists of the
3963 # characters "--" PLUS the Boundary string. (There used to be a special
3964 # case here for IE 3.01 on the Mac, based on the client controlled
3965 # User-Agent, which any client could use to change how the body was
3966 # parsed - e.g. to smuggle extra fields past a filtering proxy)
3967 944 $boundary = "--$boundary";
3968  
3969 } else { # otherwise we find it ourselves
3970 # read the first (boundary) line, bounded in size so that a client
3971 # can't make us buffer an arbitrarily long line - RFC 2046 limits
3972 # boundaries to 70 characters. anything read past the line is kept
3973 # for the body.
3974 824 my $max = $MAX_BOUNDARY_LINE;
3975 824 ▶ $max = $length if !$chunked && $length < $max;
Branch: 1 branch
BranchTrueFalseTotal
if not $chunked and $length < $max 14 810 824
Condition100%3/3
not $chunked and $length < $max
!ll&&!rl&&r
580514
MC/DC100%2/2
not $chunked and $length < $max
not $chunked $length < $max
Truth table100%3/3
not(A) and B
A= not $chunkedB= $length < $max
ABresult
0X0
100
111
3976 824 my $end;
3977 824 ▶ while ( ( $end = index( $preread,$CRLF ) ) < 0 && length( $preread ) < $max ) {
Branch: 1 branch
BranchTrueFalseTotal
if (($end = index($preread, $CRLF)) < 0 and length $preread < $max) 825 823 1648
Condition100%3/3
($end = index($preread, $CRLF)) < 0 and length $preread < $max
!ll&&!rl&&r
8194825
MC/DC100%2/2
($end = index($preread, $CRLF)) < 0 and length $preread < $max
($end = index($preread, $CRLF)) < 0 length $preread < $max
Truth table100%3/3
A and B
A= ($end = index($preread, $CRLF)) < 0B= length $preread < $max
ABresult
0X0
100
111
3978 825 my $got = $interface->read_from_client(
3979 \$preread, $max - length( $preread ), length( $preread )
3980 );
3981 825 ▶ last unless $got;
Branch: 1 branch
BranchTrueFalseTotal
unless $got 1 824 825
3982 }
3983 824 ▶ die "Malformed multipart POST: boundary line too long or missing\n"
Branch: 1 branch
BranchTrueFalseTotal
if $end < 0 5 819 824
3984 if $end < 0;
3985 819 ▶ $length -= length( $preread ) unless $chunked;
Branch: 1 branch
BranchTrueFalseTotal
unless $chunked 817 2 819
3986 819 $boundary = substr( $preread,0,$end );
3987 819 $preread = substr( $preread,$end + length( $CRLF ) );
3988 819 $boundary_read++;
3989 }
3990  
3991 # RFC 2046 boundaries are 1 to 70 characters, longer ones (allowing
3992 # some slack) are rejected - a boundary approaching the read size
3993 # (INITIAL_FILLUNIT) corrupted and merged parts in read()
3994 1763 ▶ die "Malformed multipart POST: invalid boundary\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $boundary =~ /\A--./s and length($boundary) - 2 <= $MAX_BOUNDARY_LENGTH 9 1754 1763
Condition100%3/3
$boundary =~ /\A--./s and length($boundary) - 2 <= $MAX_BOUNDARY_LENGTH
!ll&&!rl&&r
361754
MC/DC100%2/2
$boundary =~ /\A--./s and length($boundary) - 2 <= $MAX_BOUNDARY_LENGTH
$boundary =~ /\A--./s length($boundary) - 2 <= $MAX_BOUNDARY_LENGTH
Truth table100%3/3
A and B
A= $boundary =~ /\A--./sB= length($boundary) - 2 <= $MAX_BOUNDARY_LENGTH
ABresult
0X0
100
111
3995 unless $boundary =~ /\A--./s
3996 && length( $boundary ) - 2 <= $MAX_BOUNDARY_LENGTH;
3997  
3998 1754 ▶ my $self = {LENGTH=>$length,
Branch: 1 branch
BranchTrueFalseTotal
$boundary_read ? : 815 939 1754
3999 CHUNKED=>$chunked,
4000 TOTAL_READ=>$boundary_read ? length( $boundary ) + length( $CRLF ) + length( $preread ) : 0,
4001 BOUNDARY=>$boundary,
4002 INTERFACE=>$interface,
4003 BUFFER=>$preread,
4004 AT_LINE_START=>1, # the start of the body, or after the boundary line
4005 };
4006  
4007 1754 ▶ $FILLUNIT = length($boundary)
Branch: 1 branch
BranchTrueFalseTotal
if length $boundary > $FILLUNIT 0 1754 1754
4008 if length($boundary) > $FILLUNIT;
4009  
4010 1754 ▶ my $retval = bless $self,ref $package || $package;
Condition33%1/3
ref $package || $package
l!l&&r!l&&!r
017540
MC/DC0%0/2
ref $package || $package
ref $package $package
Truth table33%1/3
A || B
A= ref $packageB= $package
ABresult
1X1
011
000
4011  
4012 # Read the preamble and the topmost (boundary) line plus the CRLF.
4013 1754 ▶ unless ($boundary_read) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($boundary_read) 939 815 1754
4014 939 ▶ while ($self->read(0)) { }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->read(0)) 2 936 938
4015 }
4016 1751 ▶ die "Malformed multipart POST: data truncated\n" if $self->eof;
Branch: 1 branch
BranchTrueFalseTotal
if $self->eof 1 1750 1751
4017  
4018 1750 return $retval;
4019 }
4020  
4021 3635 ▶sub readHeader {
Subroutine readHeader: called CC=14 SCAR=28.8
4022 3635 my($self) = @_;
4023 3635 my($end);
4024 3635 my($ok) = 0;
4025 3635 my($bad) = 0;
4026  
4027 3635 ▶ local($CRLF) = "\015\012" if $CGI::OS eq 'VMS' || $CGI::EBCDIC;
Branch: 1 branch
BranchTrueFalseTotal
if $CGI::OS eq "VMS" or $CGI::EBCDIC 0 3635 3635
Condition33%1/3
$CGI::OS eq "VMS" or $CGI::EBCDIC
l!l&&r!l&&!r
003635
MC/DC0%0/2
$CGI::OS eq "VMS" or $CGI::EBCDIC
$CGI::OS eq "VMS" $CGI::EBCDIC
Truth table33%1/3
A or B
A= $CGI::OS eq "VMS"B= $CGI::EBCDIC
ABresult
1X1
011
000
4028  
4029 3635 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
($ok or $bad) or do { do { $self->fillBuffer($FILLUNIT); ++$ok if ($end = index($self->{"BUFFER"}, "$CRLF$CRLF")) >= 0; ++$ok if $self->{"BUFFER"} eq ""; ++$bad if not $ok and $self->{"LENGTH"} <= 0 } } 3634 0 3634
Condition66%2/3
$ok or $bad
l!l&&r!l&&!r
363310
MC/DC0%0/2
$ok or $bad
$ok $bad
Truth table66%2/3
A or B
A= $okB= $bad
ABresult
1X1
011
000
4030 3635 $self->fillBuffer($FILLUNIT);
4031 3634 ▶ $ok++ if ($end = index($self->{BUFFER},"${CRLF}${CRLF}")) >= 0;
Branch: 1 branch
BranchTrueFalseTotal
if ($end = index($self->{"BUFFER"}, "$CRLF$CRLF")) >= 0 3633 1 3634
4032 3634 ▶ $ok++ if $self->{BUFFER} eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"BUFFER"} eq "" 0 3634 3634
4033 3634 ▶ $bad++ if !$ok && $self->{LENGTH} <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if not $ok and $self->{"LENGTH"} <= 0 1 3633 3634
Condition66%2/3
not $ok and $self->{"LENGTH"} <= 0
!ll&&!rl&&r
363301
MC/DC50%1/2
not $ok and $self->{"LENGTH"} <= 0
not $ok $self->{"LENGTH"} <= 0
Truth table66%2/3
not(A) and B
A= not $okB= $self->{"LENGTH"} <= 0
ABresult
0X0
100
111
4034 # this was a bad idea
4035 # $FILLUNIT *= 2 if length($self->{BUFFER}) >= $FILLUNIT;
4036 } until $ok || $bad;
4037 3634 ▶ return () if $bad;
Branch: 1 branch
BranchTrueFalseTotal
if $bad 1 3633 3634
4038  
4039 #EBCDIC NOTE: translate header into EBCDIC, but watch out for continuation lines!
4040  
4041 3633 my($header) = substr($self->{BUFFER},0,$end+2);
4042 3633 substr($self->{BUFFER},0,$end+4) = '';
4043 3633 $self->{AT_LINE_START} = 1; # the part's content starts on a new line
4044 3633 my %return;
4045  
4046 3633 ▶ if ($CGI::EBCDIC) {
Branch: 1 branch
BranchTrueFalseTotal
if ($CGI::EBCDIC) 0 3633 3633
4047 0 ▶ warn "untranslated header=$header\n" if $_DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $_DEBUG 0 0 0
4048 0 $header = CGI::Util::ascii2ebcdic($header);
4049 0 ▶ warn "translated header=$header\n" if $_DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $_DEBUG 0 0 0
4050 }
4051  
4052 # See RFC 2045 Appendix A and RFC 822 sections 3.4.8
4053 # (Folding Long Header Fields), 3.4.3 (Comments)
4054 # and 3.4.5 (Quoted-Strings).
4055  
4056 3633 my $token = '[-\w!\#$%&\'*+.^_\`|{}~]';
4057 3633 $header=~s/$CRLF\s+/ /og; # merge continuation lines
4058  
4059 3633 ▶ while ($header=~/($token+):\s+([^$CRLF]*)/mgox) {
Branch: 1 branch
BranchTrueFalseTotal
if ($header =~ /($token+):\s+([^$CRLF]*)/gmox) 3700 3633 7333
4060 3700 my ($field_name,$field_value) = ($1,$2);
4061 3700 $field_name =~ s/\b(\w)/uc($1)/eg; #canonicalize
4062 3700 $return{$field_name}=$field_value . $CGI::TAINTED; # captures are untainted
4063 }
4064 3633 return %return;
4065 }
4066  
4067 # This reads and returns the body as a single scalar value.
4068 3445 ▶sub readBody {
Subroutine readBody: called CC=5 SCAR=19.7
4069 3445 my($self) = @_;
4070 3445 my($data);
4071 3445 my($returnval)='';
4072  
4073 #EBCDIC NOTE: want to translate returnval into EBCDIC HERE
4074  
4075 3445 ▶ while (defined($data = $self->read)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($data = $self->read)) 4346 3445 7791
4076 4346 $returnval .= $data;
4077 }
4078  
4079 3445 ▶ if ($CGI::EBCDIC) {
Branch: 1 branch
BranchTrueFalseTotal
if ($CGI::EBCDIC) 0 3445 3445
4080 0 ▶ warn "untranslated body=$returnval\n" if $_DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $_DEBUG 0 0 0
4081 0 $returnval = CGI::Util::ascii2ebcdic($returnval);
4082 0 ▶ warn "translated body=$returnval\n" if $_DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $_DEBUG 0 0 0
4083 }
4084 3445 return $returnval;
4085 }
4086  
4087 # This will read $bytes or until the boundary is hit, whichever happens
4088 # first. After the boundary is hit, we return undef. The next read will
4089 # skip over the boundary and begin reading again;
4090 9186 ▶sub read {
Subroutine read: called CC=17 SCAR=28.5
4091 9186 my($self,$bytes) = @_;
4092  
4093 # default number of bytes to read
4094 9186 ▶ $bytes = $bytes || $FILLUNIT;
Condition33%1/3
$bytes || $FILLUNIT
l!l&&r!l&&!r
091860
MC/DC0%0/2
$bytes || $FILLUNIT
$bytes $FILLUNIT
Truth table33%1/3
A || B
A= $bytesB= $FILLUNIT
ABresult
1X1
011
000
4095  
4096 # Fill up our internal buffer in such a way that the boundary
4097 # is never split between reads.
4098 9186 $self->fillBuffer($bytes);
4099  
4100 9184 ▶ my $boundary_start = $CGI::EBCDIC ? CGI::Util::ebcdic2ascii($self->{BOUNDARY}) : $self->{BOUNDARY};
Branch: 1 branch
BranchTrueFalseTotal
$CGI::EBCDIC ? : 0 9184 9184
4101 9184 ▶ my $boundary_end = $CGI::EBCDIC ? CGI::Util::ebcdic2ascii($self->{BOUNDARY}.'--') : $self->{BOUNDARY}.'--';
Branch: 1 branch
BranchTrueFalseTotal
$CGI::EBCDIC ? : 0 9184 9184
4102  
4103 # Find the boundary in the buffer (it may not be there). Per RFC 2046 it
4104 # is only a delimiter at the start of a line - at the start of the body
4105 # or a part's content, or following a CRLF (which belongs to the
4106 # delimiter, and is stripped from the content below). Matching it
4107 # anywhere else would let content such as "x--BOUNDARY" start a new
4108 # part, and so parse differently to other (e.g. a filtering proxy's)
4109 # parsers.
4110 9184 my $crlf = "\015\012"; # always this on the wire
4111 9184 my $start = -1;
4112 9184 ▶ if ( $self->{AT_LINE_START} && index($self->{BUFFER},$boundary_start) == 0 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'AT_LINE_START'} and index($self->{'BUFFER'}, $boundary_start) == 0) { } 4562 4622 9184
elsif (($start = index($self->{'BUFFER'}, $crlf . $boundary_start)) >= 0) { } 3629 993 4622
Condition100%3/3
$self->{"AT_LINE_START"} and index($self->{"BUFFER"}, $boundary_start) == 0
!ll&&!rl&&r
99136314562
MC/DC100%2/2
$self->{"AT_LINE_START"} and index($self->{"BUFFER"}, $boundary_start) == 0
$self->{"AT_LINE_START"} index($self->{"BUFFER"}, $boundary_start) == 0
Truth table100%3/3
A and B
A= $self->{"AT_LINE_START"}B= index($self->{"BUFFER"}, $boundary_start) == 0
ABresult
0X0
100
111
4113 4562 $start = 0;
4114 } elsif ( ( $start = index($self->{BUFFER},$crlf . $boundary_start) ) >= 0 ) {
4115 3629 $start += length($crlf);
4116 }
4117  
4118 9184 ▶ warn "boundary=$self->{BOUNDARY} length=$self->{LENGTH} start=$start\n" if $_DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $_DEBUG 0 9184 9184
4119  
4120 # protect against malformed multipart POST operations
4121 9184 ▶ die "Malformed multipart POST\n" unless $self->{CHUNKED} || ($start >= 0 || $self->{LENGTH} > 0);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"CHUNKED"} or ($start >= 0 or $self->{"LENGTH"} > 0) 1 9183 9184
Condition100%6/6
$self->{"CHUNKED"} or ($start >= 0 or $self->{"LENGTH"} > 0)
l!l&&r!l&&!r
3491491
$start >= 0 or $self->{"LENGTH"} > 0
l!l&&r!l&&!r
81729771
MC/DC100%3/3
$self->{"CHUNKED"} or ($start >= 0 or $self->{"LENGTH"} > 0)
$self->{"CHUNKED"} $start >= 0 $self->{"LENGTH"} > 0
Truth table100%4/4
A or B or C
A= $self->{"CHUNKED"}B= $start >= 0C= $self->{"LENGTH"} > 0
ABCresult
1XX1
01X1
0011
0000
4122  
4123 #EBCDIC NOTE: want to translate boundary search into ASCII here.
4124  
4125 # If the boundary begins the data, then skip past it
4126 # and return undef.
4127 9183 ▶ if ($start == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($start == 0) 4562 4621 9183
4128  
4129 # clear us out completely if we've hit the last boundary.
4130 4562 ▶ if (index($self->{BUFFER},$boundary_end)==0) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($self->{"BUFFER"}, $boundary_end) == 0) 1743 2819 4562
4131 1743 $self->{BUFFER}='';
4132 1743 $self->{LENGTH}=0;
4133 1743 return undef;
4134 }
4135  
4136 # just remove the boundary.
4137 2819 substr($self->{BUFFER},0,length($boundary_start))='';
4138 2819 $self->{BUFFER} =~ s/^\012\015?//;
4139 2819 $self->{AT_LINE_START} = 0;
4140 2819 return undef;
4141 }
4142  
4143 4621 my $bytesToReturn;
4144 4621 ▶ if ($start > 0) { # read up to the boundary
Branch: 1 branch
BranchTrueFalseTotal
if ($start > 0) { } 3629 992 4621
4145 3629 ▶ $bytesToReturn = $start-2 > $bytes ? $bytes : $start;
Branch: 1 branch
BranchTrueFalseTotal
$start - 2 > $bytes ? : 0 3629 3629
4146 } else { # read the requested number of bytes
4147 # leave enough bytes in the buffer to allow us to read
4148 # the boundary. Thanks to Kevin Hendrick for finding
4149 # this one.
4150 992 $bytesToReturn = $bytes - (length($boundary_start)+1);
4151 }
4152  
4153 4621 my $returnval=substr($self->{BUFFER},0,$bytesToReturn);
4154 4621 substr($self->{BUFFER},0,$bytesToReturn)='';
4155  
4156 # If we hit the boundary, remove the CRLF from the end - the buffer
4157 # then starts with the boundary, at the start of a line.
4158 4621 ▶ $self->{AT_LINE_START} = $bytesToReturn == $start ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$bytesToReturn == $start ? : 3629 992 4621
4159 4621 ▶ return ($bytesToReturn==$start)
Branch: 1 branch
BranchTrueFalseTotal
$bytesToReturn == $start ? : 3629 992 4621
4160 ? substr($returnval,0,-2) : $returnval;
4161 }
4162  
4163 # This fills up our internal buffer in such a way that the
4164 # boundary is never split between reads
4165 12821 ▶sub fillBuffer {
Subroutine fillBuffer: called CC=15 SCAR=27.2
4166 12821 my($self,$bytes) = @_;
4167 12821 ▶ return unless $self->{CHUNKED} || $self->{LENGTH};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"CHUNKED"} or $self->{"LENGTH"} 6597 6224 12821
Condition100%3/3
$self->{"CHUNKED"} or $self->{"LENGTH"}
l!l&&r!l&&!r
4561796597
MC/DC100%2/2
$self->{"CHUNKED"} or $self->{"LENGTH"}
$self->{"CHUNKED"} $self->{"LENGTH"}
Truth table100%3/3
A or B
A= $self->{"CHUNKED"}B= $self->{"LENGTH"}
ABresult
1X1
011
000
4168  
4169 6224 my($boundaryLength) = length($self->{BOUNDARY});
4170 6224 my($bufferLength) = length($self->{BUFFER});
4171 6224 my($bytesToRead) = $bytes - $bufferLength + $boundaryLength + 2;
4172 6224 ▶ $bytesToRead = $self->{LENGTH} if !$self->{CHUNKED} && $self->{LENGTH} < $bytesToRead;
Branch: 1 branch
BranchTrueFalseTotal
if not $self->{"CHUNKED"} and $self->{"LENGTH"} < $bytesToRead 1778 4446 6224
Condition100%3/3
not $self->{"CHUNKED"} and $self->{"LENGTH"} < $bytesToRead
!ll&&!rl&&r
4544011778
MC/DC100%2/2
not $self->{"CHUNKED"} and $self->{"LENGTH"} < $bytesToRead
not $self->{"CHUNKED"} $self->{"LENGTH"} < $bytesToRead
Truth table100%3/3
not(A) and B
A= not $self->{"CHUNKED"}B= $self->{"LENGTH"} < $bytesToRead
ABresult
0X0
100
111
4173  
4174 # Try to read some data. We may hang here if the browser is screwed up.
4175 my $bytesRead = $self->{INTERFACE}->read_from_client(\$self->{BUFFER},
4176 6224 $bytesToRead,
4177 $bufferLength);
4178 6224 ▶ warn "bytesToRead=$bytesToRead, bufferLength=$bufferLength, buffer=$self->{BUFFER}\n" if $_DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $_DEBUG 0 6224 6224
4179 6224 ▶ $self->{BUFFER} = '' unless defined $self->{BUFFER};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"BUFFER"} 0 6224 6224
4180  
4181 # An apparent bug in the Apache server causes the read()
4182 # to return zero bytes repeatedly without blocking if the
4183 # remote user aborts during a file transfer. I don't know how
4184 # they manage this, but the workaround is to abort if we get
4185 # more than SPIN_LOOP_MAX consecutive zero reads.
4186 6224 ▶ if ($bytesRead <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bytesRead <= 0) { } 61 6163 6224
4187 die "CGI.pm: Server closed socket during multipart read (client aborted?).\n"
4188 61 ▶ if ($self->{ZERO_LOOP_COUNTER}++ >= $SPIN_LOOP_MAX);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"ZERO_LOOP_COUNTER"}++ >= $SPIN_LOOP_MAX 0 61 61
4189 } else {
4190 6163 $self->{ZERO_LOOP_COUNTER}=0;
4191 }
4192  
4193 6224 ▶ $self->{LENGTH} -= $bytesRead if !$self->{CHUNKED} && $bytesRead;
Branch: 1 branch
BranchTrueFalseTotal
if not $self->{"CHUNKED"} and $bytesRead 6134 90 6224
Condition100%3/3
not $self->{"CHUNKED"} and $bytesRead
!ll&&!rl&&r
45456134
MC/DC100%2/2
not $self->{"CHUNKED"} and $bytesRead
not $self->{"CHUNKED"} $bytesRead
Truth table100%3/3
not(A) and B
A= not $self->{"CHUNKED"}B= $bytesRead
ABresult
0X0
100
111
4194  
4195 # enforce $POST_MAX as we read, as when there is no CONTENT_LENGTH
4196 # (chunked transfer encoding) it can't be checked up front
4197 6224 ▶ $self->{TOTAL_READ} += $bytesRead if $bytesRead && $bytesRead > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $bytesRead and $bytesRead > 0 6163 61 6224
Condition66%2/3
$bytesRead and $bytesRead > 0
!ll&&!rl&&r
6106163
MC/DC50%1/2
$bytesRead and $bytesRead > 0
$bytesRead $bytesRead > 0
Truth table66%2/3
A and B
A= $bytesReadB= $bytesRead > 0
ABresult
0X0
100
111
4198 die $REQUEST_TOO_LARGE
4199 6224 ▶ if $CGI::POST_MAX > 0 && $self->{TOTAL_READ} > $CGI::POST_MAX;
Branch: 1 branch
BranchTrueFalseTotal
if $CGI::POST_MAX > 0 and $self->{"TOTAL_READ"} > $CGI::POST_MAX 3 6221 6224
Condition100%3/3
$CGI::POST_MAX > 0 and $self->{"TOTAL_READ"} > $CGI::POST_MAX
!ll&&!rl&&r
1962023
MC/DC100%2/2
$CGI::POST_MAX > 0 and $self->{"TOTAL_READ"} > $CGI::POST_MAX
$CGI::POST_MAX > 0 $self->{"TOTAL_READ"} > $CGI::POST_MAX
Truth table100%3/3
A and B
A= $CGI::POST_MAX > 0B= $self->{"TOTAL_READ"} > $CGI::POST_MAX
ABresult
0X0
100
111
4200 }
4201  
4202 # Return true when we've finished reading
4203 7129 ▶sub eof {
Subroutine eof: called CC=3 SCAR=11.0
4204 7129 my($self) = @_;
4205 return 1 if (length($self->{BUFFER}) == 0)
4206 7129 ▶ && ($self->{LENGTH} <= 0);
Branch: 1 branch
BranchTrueFalseTotal
if length $self->{"BUFFER"} == 0 and $self->{"LENGTH"} <= 0 1744 5385 7129
Condition66%2/3
length $self->{"BUFFER"} == 0 and $self->{"LENGTH"} <= 0
!ll&&!rl&&r
538501744
MC/DC50%1/2
length $self->{"BUFFER"} == 0 and $self->{"LENGTH"} <= 0
length $self->{"BUFFER"} == 0 $self->{"LENGTH"} <= 0
Truth table66%2/3
A and B
A= length $self->{"BUFFER"} == 0B= $self->{"LENGTH"} <= 0
ABresult
0X0
100
111
4207 5385 undef;
4208 }
4209  
4210 84 1;
4211  
4212 package CGI;
4213  
4214 # We get a whole bunch of warnings about "possibly uninitialized variables"
4215 # when running with the -w switch. Touch them all once to get rid of the
4216 # warnings. This is ugly and I hate it.
4217 84 ▶if ($^W) {
Branch: 1 branch
BranchTrueFalseTotal
if ($^W) 23 61 84
4218 23 $CGI::CGI = '';
4219 23 $CGI::CGI=<<EOF;
4220 $CGI::VERSION;
4221 $CGI::MultipartBuffer::SPIN_LOOP_MAX;
4222 $CGI::MultipartBuffer::CRLF;
4223 $CGI::MultipartBuffer::TIMEOUT;
4224 $CGI::MultipartBuffer::INITIAL_FILLUNIT;
4225 EOF
4226 ;
4227 }
4228  
4229 84 1;
↑ Summary CGI/Util.pm »