| 1 | package CGI::Easy::Util; | ||||||||||||||||||||||||||||
| 2 | 3 | ▶ | use 5.010001; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use utf8; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 3 | our $VERSION = 'v2.0.1'; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use Export::Attrs; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use URI::Escape qw( uri_unescape uri_escape_utf8 ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 6 | ▶ | sub date_http :Export { | ||||||||||||||||||||||||||
|
Subroutine
date_http: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 15 | 6 | my ($tick) = @_; | |||||||||||||||||||||||||||
| 16 | 6 | return _date($tick, 'http'); | |||||||||||||||||||||||||||
| 17 | 3 | ▶ | } | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 9 | ▶ | sub date_cookie :Export { | ||||||||||||||||||||||||||
|
Subroutine
date_cookie: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 20 | 9 | my ($tick) = @_; | |||||||||||||||||||||||||||
| 21 | 9 | return _date($tick, 'cookie'); | |||||||||||||||||||||||||||
| 22 | 3 | ▶ | } | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 15 | ▶ | sub _date { | ||||||||||||||||||||||||||
|
Subroutine
_date: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 25 | 15 | my ($tick, $format) = @_; | |||||||||||||||||||||||||||
| 26 | 15 | ▶ | my $sp = $format eq 'cookie' ? q{-} : q{ }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | 15 | my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime $tick; | |||||||||||||||||||||||||||
| 28 | 15 | my $wkday = qw(Sun Mon Tue Wed Thu Fri Sat)[$wday]; | |||||||||||||||||||||||||||
| 29 | 15 | my $month = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)[$mon]; | |||||||||||||||||||||||||||
| 30 | 15 | return sprintf "%s, %02d$sp%s$sp%s %02d:%02d:%02d GMT", | |||||||||||||||||||||||||||
| 31 | $wkday, $mday, $month, $year+1900, $hour, $min, $sec; ## no critic(ProhibitMagicNumbers) | ||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 12 | ▶ | sub make_cookie :Export { | ||||||||||||||||||||||||||
|
Subroutine
make_cookie: called CC=9 SCAR=22.3
Pod
documented
| |||||||||||||||||||||||||||||
| 35 | 12 | my ($opt) = @_; | |||||||||||||||||||||||||||
| 36 | 12 | ▶ | return q{} if !defined $opt->{name}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 12 | my $name = $opt->{name}; | |||||||||||||||||||||||||||
| 39 | 12 | ▶ | my $value = defined $opt->{value} ? $opt->{value} : q{}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | 12 | my $domain = $opt->{domain}; | |||||||||||||||||||||||||||
| 41 | 12 | ▶ | my $path = defined $opt->{path} ? $opt->{path} : q{/}; # IE require it | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | my $expires = defined $opt->{expires} && $opt->{expires} =~ /\A\d+\z/xms ? | ||||||||||||||||||||||||||||
| 43 | 12 | ▶ | date_cookie($opt->{expires}) : $opt->{expires}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $opt->{"expires"} and $opt->{"expires"} =~ /\A\d+\z/msx
MC/DC50%1/2
defined $opt->{"expires"} and $opt->{"expires"} =~ /\A\d+\z/msx
defined $opt->{"expires"}
$opt->{"expires"} =~ /\A\d+\z/msx
Truth table66%2/3
A and B
A= defined $opt->{"expires"}B= $opt->{"expires"} =~ /\A\d+\z/msx
| |||||||||||||||||||||||||||||
| 44 | 12 | my $set_cookie = 'Set-Cookie: '; | |||||||||||||||||||||||||||
| 45 | 12 | $set_cookie .= uri_escape_utf8($name) . q{=} . uri_escape_utf8($value); | |||||||||||||||||||||||||||
| 46 | 12 | ▶ | $set_cookie .= "; domain=$domain" if defined $domain; ## no critic(ProhibitPostfixControls) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 12 | $set_cookie .= "; path=$path"; | |||||||||||||||||||||||||||
| 48 | 12 | ▶ | $set_cookie .= "; expires=$expires" if defined $expires;## no critic(ProhibitPostfixControls) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | 12 | ▶ | $set_cookie .= '; secure' if $opt->{secure}; ## no critic(ProhibitPostfixControls) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | 12 | $set_cookie .= "\r\n"; | |||||||||||||||||||||||||||
| 51 | 12 | return $set_cookie; | |||||||||||||||||||||||||||
| 52 | 3 | ▶ | } | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 112 | ▶ | sub uri_unescape_plus :Export { | ||||||||||||||||||||||||||
|
Subroutine
uri_unescape_plus: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 55 | 112 | my ($s) = @_; | |||||||||||||||||||||||||||
| 56 | 112 | $s =~ s/[+]/ /xmsg; | |||||||||||||||||||||||||||
| 57 | 112 | return uri_unescape($s); | |||||||||||||||||||||||||||
| 58 | 3 | ▶ | } | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 38 | ▶ | sub burst_urlencoded :Export { | ||||||||||||||||||||||||||
|
Subroutine
burst_urlencoded: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||||||||||||||||||||
| 61 | 38 | my ($buffer) = @_; | |||||||||||||||||||||||||||
| 62 | 38 | my %param; | |||||||||||||||||||||||||||
| 63 | 38 | ▶ | if (defined $buffer) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | 38 | foreach my $pair (split /[&;]/xms, $buffer) { | |||||||||||||||||||||||||||
| 65 | 49 | my ($name, $data) = split /=/xms, $pair, 2; | |||||||||||||||||||||||||||
| 66 | 49 | ▶ | $name = !defined $name ? q{} : uri_unescape_plus($name); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | 49 | ▶ | $data = !defined $data ? q{} : uri_unescape_plus($data); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | 49 | push @{ $param{$name} }, $data; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | 38 | return \%param; | |||||||||||||||||||||||||||
| 72 | 3 | ▶ | } | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | # This function derived from CGI::Minimal (1.29) by | ||||||||||||||||||||||||||||
| 75 | # Benjamin Franz <snowhare@nihongo.org> | ||||||||||||||||||||||||||||
| 76 | # Copyright (c) Benjamin Franz. All rights reserved. | ||||||||||||||||||||||||||||
| 77 | 2 | ▶ | sub burst_multipart :Export { | ||||||||||||||||||||||||||
|
Subroutine
burst_multipart: called CC=16 SCAR=29.3
Pod
documented
| |||||||||||||||||||||||||||||
| 78 | 2 | my ($buffer, $bdry) = @_; | |||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | # Special case boundaries causing problems with 'split' | ||||||||||||||||||||||||||||
| 81 | 2 | ▶ | if ($bdry =~ m{[^A-Za-z0-9',-./:=]}ms) { ## no critic (ProhibitEnumeratedClasses) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | 0 | my $nbdry = $bdry; | |||||||||||||||||||||||||||
| 83 | 0 | $nbdry =~ s/([^A-Za-z0-9',-.\/:=])/ord($1)/msge;## no critic (ProhibitEnumeratedClasses) | |||||||||||||||||||||||||||
| 84 | 0 | my $quoted_boundary = quotemeta $nbdry; | |||||||||||||||||||||||||||
| 85 | 0 | ▶ | while ($buffer =~ m/$quoted_boundary/ms) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | 0 | $nbdry .= chr(65 + int rand 25); ## no critic (ProhibitParensWithBuiltins, ProhibitMagicNumbers) | |||||||||||||||||||||||||||
| 87 | 0 | $quoted_boundary = quotemeta $nbdry; | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | 0 | my $old_boundary = quotemeta $bdry; | |||||||||||||||||||||||||||
| 90 | 0 | $buffer =~ s/$old_boundary/$nbdry/msg; | |||||||||||||||||||||||||||
| 91 | 0 | $bdry = $nbdry; | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 2 | $bdry = "--$bdry(--)?\r\n"; | |||||||||||||||||||||||||||
| 95 | 2 | my @pairs = split /$bdry/ms, $buffer; | |||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 2 | my (%param, %filename, %mimetype); | |||||||||||||||||||||||||||
| 98 | 2 | foreach my $pair (@pairs) { | |||||||||||||||||||||||||||
| 99 | 16 | ▶ | next if !defined $pair; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | 10 | chop $pair; # Trailing \015 | |||||||||||||||||||||||||||
| 101 | 10 | chop $pair; # Trailing \012 | |||||||||||||||||||||||||||
| 102 | 10 | ▶ | last if $pair eq q{--}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | 10 | ▶ | next if !$pair; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 6 | my ($header, $data) = split /\r\n\r\n/ms, $pair, 2; | |||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | # parse the header | ||||||||||||||||||||||||||||
| 108 | 6 | $header =~ s/\r\n/\n/msg; | |||||||||||||||||||||||||||
| 109 | 6 | my @headerlines = split /\n/ms, $header; | |||||||||||||||||||||||||||
| 110 | 6 | my ($name, $filename, $mimetype); | |||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 6 | foreach my $headfield (@headerlines) { | |||||||||||||||||||||||||||
| 113 | 8 | my ($fname, $fdata) = split /: /ms, $headfield, 2; | |||||||||||||||||||||||||||
| 114 | 8 | ▶ | if (lc $fname eq 'content-type') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 115 | 2 | $mimetype = $fdata; | |||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | 8 | ▶ | if (lc $fname eq 'content-disposition') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 118 | 6 | my @dispositionlist = split /; /ms, $fdata; | |||||||||||||||||||||||||||
| 119 | 6 | foreach my $dispitem (@dispositionlist) { | |||||||||||||||||||||||||||
| 120 | 14 | ▶ | next if $dispitem eq 'form-data'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 121 | 8 | my ($dispfield,$dispdata) = split /=/ms, $dispitem, 2; | |||||||||||||||||||||||||||
| 122 | 8 | $dispdata =~ s/\A\"//ms; | |||||||||||||||||||||||||||
| 123 | 8 | $dispdata =~ s/\"\z//ms; | |||||||||||||||||||||||||||
| 124 | 8 | ▶ | if ($dispfield eq 'name') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 125 | 6 | $name = $dispdata; | |||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | 8 | ▶ | if ($dispfield eq 'filename') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 128 | 2 | $filename = $dispdata; | |||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||
| 133 | 6 | ▶ | next if !defined $name; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 134 | 6 | ▶ | next if !defined $data; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 6 | push @{ $param{$name} }, $data; | |||||||||||||||||||||||||||
| 137 | 6 | push @{ $filename{$name} }, $filename; | |||||||||||||||||||||||||||
| 138 | 6 | push @{ $mimetype{$name} }, $mimetype; | |||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||
| 140 | 2 | return (\%param, \%filename, \%mimetype); | |||||||||||||||||||||||||||
| 141 | 3 | ▶ | } | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | ### Unrelated to CGI, and thus internal/undocumented | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | 10 | ▶ | sub _quote { | ||||||||||||||||||||||||||
|
Subroutine
_quote: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 147 | 10 | my ($s) = @_; | |||||||||||||||||||||||||||
| 148 | 10 | ▶ | croak 'can\'t quote undefined value' if !defined $s; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 149 | 10 | ▶ | if ($s =~ / \s | ' | \A\z /xms) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 150 | 2 | $s =~ s/'/''/xmsg; | |||||||||||||||||||||||||||
| 151 | 2 | $s = "'$s'"; | |||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||
| 153 | 10 | return $s; | |||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | 12 | ▶ | sub _unquote { | ||||||||||||||||||||||||||
|
Subroutine
_unquote: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 157 | 12 | my ($s) = @_; | |||||||||||||||||||||||||||
| 158 | 12 | ▶ | if ($s =~ s/\A'(.*)'\z/$1/xms) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 159 | 1 | $s =~ s/''/'/xmsg; | |||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||
| 161 | 12 | return $s; | |||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | 4 | ▶ | sub quote_list :Export { | ||||||||||||||||||||||||||
|
Subroutine
quote_list: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 165 | 4 | return join q{ }, map {_quote($_)} @_; | |||||||||||||||||||||||||||
| 166 | 3 | ▶ | } | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | 22 | ▶ | sub unquote_list :Export { | ||||||||||||||||||||||||||
|
Subroutine
unquote_list: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 169 | 22 | my ($s) = @_; | |||||||||||||||||||||||||||
| 170 | 22 | ▶ | return if !defined $s; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 171 | 3 | my @w; | |||||||||||||||||||||||||||
| 172 | 3 | ▶ | while ($s =~ /\G ( [^'\s]+ | '[^']*(?:''[^']*)*' ) (?:\s+|\z)/xmsgc) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 173 | 12 | my $w = $1; | |||||||||||||||||||||||||||
| 174 | 12 | push @w, _unquote($w); | |||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||
| 176 | 3 | ▶ | return if $s !~ /\G\z/xmsg; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 177 | 3 | return \@w; | |||||||||||||||||||||||||||
| 178 | 3 | ▶ | } | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | 22 | ▶ | sub unquote_hash :Export { | ||||||||||||||||||||||||||
|
Subroutine
unquote_hash: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 181 | 22 | my $w = unquote_list(@_); | |||||||||||||||||||||||||||
| 182 | 22 | ▶ | return $w && $#{$w} % 2 ? { @{$w} } : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$w and $#{$w;} % 2
MC/DC50%1/2
$w and $#{$w;} % 2
$w
$#{$w;} % 2
Truth table66%2/3
A and B
A= $wB= $#{$w;} % 2
| |||||||||||||||||||||||||||||
| 183 | 3 | ▶ | } | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | 3 | 1; # Magic true value required at end of module | |||||||||||||||||||||||||||
| 187 | __END__ | ||||||||||||||||||||||||||||