| 1 | package MogileFS::Backend; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 4 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use IO::Socket::INET; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 4 | ▶ | use Socket qw( MSG_NOSIGNAL PF_INET IPPROTO_TCP SOCK_STREAM ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 4 | ▶ | use Errno qw( EINPROGRESS EWOULDBLOCK EISCONN ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 4 | ▶ | use POSIX (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 4 | ▶ | use MogileFS::Client; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 4 | ▶ | use List::Util qw/ shuffle /; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 4 | ▶ | use fields ('hosts', # arrayref of "$host:$port" of mogilefsd servers | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 'host_dead', # "$host:$port" -> $time (of last connect failure) | ||||||||||||||||||||||||||||||||||||||||||
| 16 | 'lasterr', # string: \w+ identifier of last error | ||||||||||||||||||||||||||||||||||||||||||
| 17 | 'lasterrstr', # string: english of last error | ||||||||||||||||||||||||||||||||||||||||||
| 18 | 'sock_cache', # cached socket to mogilefsd tracker | ||||||||||||||||||||||||||||||||||||||||||
| 19 | 'pref_ip', # hashref; { ip => preferred ip } | ||||||||||||||||||||||||||||||||||||||||||
| 20 | 'timeout', # time in seconds to allow sockets to become readable | ||||||||||||||||||||||||||||||||||||||||||
| 21 | 'last_host_connected', # "ip:port" of last host connected to | ||||||||||||||||||||||||||||||||||||||||||
| 22 | 'last_host_idx', # array index of the last host we connected to | ||||||||||||||||||||||||||||||||||||||||||
| 23 | 'hooks', # hash: hookname -> coderef | ||||||||||||||||||||||||||||||||||||||||||
| 24 | 4 | ); | |||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 4 | ▶ | use vars qw($FLAG_NOSIGNAL $PROTO_TCP); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 4 | eval { $FLAG_NOSIGNAL = MSG_NOSIGNAL; }; | |||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 1 | my MogileFS::Backend $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 31 | 1 | ▶ | $self = fields::new($self) unless ref $self; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | 1 | return $self->_init(@_); | |||||||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | ▶ | sub reload { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
reload: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | my MogileFS::Backend $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | ▶ | return undef unless $self; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | return $self->_init(@_); | |||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 1 | ▶ | sub _init { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_init: called CC=7 SCAR=20.7
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 1 | my MogileFS::Backend $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 1 | my %args = @_; | |||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | # FIXME: add actual validation | ||||||||||||||||||||||||||||||||||||||||||
| 49 | { | ||||||||||||||||||||||||||||||||||||||||||
| 50 | 1 | $self->{hosts} = $args{hosts} or | |||||||||||||||||||||||||||||||||||||||||
| 51 | 1 | ▶ | _fail("constructor requires parameter 'hosts'"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | _fail("'hosts' argument must be an arrayref") | ||||||||||||||||||||||||||||||||||||||||||
| 54 | 1 | ▶ | unless ref $self->{hosts} eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | _fail("'hosts' argument must be of form: 'host:port'") | ||||||||||||||||||||||||||||||||||||||||||
| 57 | 1 | ▶ | if grep(! /:\d+$/, @{$self->{hosts}}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | _fail("'timeout' argument must be a number") | ||||||||||||||||||||||||||||||||||||||||||
| 60 | 1 | ▶ | if $args{timeout} && $args{timeout} !~ /^\d+$/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$args{"timeout"} and not $args{"timeout"} =~ /^\d+$/
MC/DC0%0/2
$args{"timeout"} and not $args{"timeout"} =~ /^\d+$/
$args{"timeout"}
not $args{"timeout"} =~ /^\d+$/
Truth table33%1/3
A and not(B)
A= $args{"timeout"}B= not $args{"timeout"} =~ /^\d+$/
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 1 | ▶ | $self->{timeout} = $args{timeout} || 3; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args{'timeout'} || 3
MC/DC0%0/1
$args{'timeout'} || 3
$args{'timeout'}
Truth table50%1/2
A
A= $args{'timeout'}
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | 1 | $self->{hosts} = [ shuffle(@{ $self->{hosts} }) ]; | |||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | 1 | $self->{host_dead} = {}; | |||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | 1 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | sub run_hook { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run_hook: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | my MogileFS::Backend $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | my $hookname = shift || return; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
shift() || (return)
MC/DC0%0/1
shift() || (return)
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | my $hook = $self->{hooks}->{$hookname}; | |||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | return unless $hook; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | eval { $hook->(@_) }; | |||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | ▶ | warn "MogileFS::Backend hook '$hookname' threw error: $@\n" if $@; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | sub add_hook { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_hook: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | my MogileFS::Backend $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | my $hookname = shift || return; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
shift() || (return)
MC/DC0%0/1
shift() || (return)
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | $self->{hooks}->{$hookname} = shift; | |||||||||||||||||||||||||||||||||||||||||
| 89 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | delete $self->{hooks}->{$hookname}; | |||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | ▶ | sub set_pref_ip { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_pref_ip: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | my MogileFS::Backend $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | $self->{pref_ip} = shift; | |||||||||||||||||||||||||||||||||||||||||
| 97 | $self->{pref_ip} = undef | ||||||||||||||||||||||||||||||||||||||||||
| 98 | unless $self->{pref_ip} && | ||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | ▶ | ref $self->{pref_ip} eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"pref_ip"} and ref $self->{"pref_ip"} eq "HASH"
MC/DC0%0/2
$self->{"pref_ip"} and ref $self->{"pref_ip"} eq "HASH"
$self->{"pref_ip"}
ref $self->{"pref_ip"} eq "HASH"
Truth table0%0/3
A and B
A= $self->{"pref_ip"}B= ref $self->{"pref_ip"} eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | sub _wait_for_readability { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_wait_for_readability: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | my ($fileno, $timeout) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | return 0 unless $fileno && $timeout; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$fileno and $timeout
MC/DC0%0/2
$fileno and $timeout
$fileno
$timeout
Truth table0%0/3
A and B
A= $filenoB= $timeout
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | my $rin = ''; | |||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | vec($rin, $fileno, 1) = 1; | |||||||||||||||||||||||||||||||||||||||||
| 108 | # FIXME: signals/ptrace attach can interrupt the select. we should resume selecting | ||||||||||||||||||||||||||||||||||||||||||
| 109 | # and keep track of hires time remaining | ||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | my $nfound = select($rin, undef, undef, $timeout); | |||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | # undef/0 are failure, 1 is success | ||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | ▶ | return $nfound ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | 1 | ▶ | sub do_request { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
do_request: called CC=17 SCAR=50.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | 1 | my MogileFS::Backend $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 118 | 1 | my ($cmd, $args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | 1 | ▶ | _fail("invalid arguments to do_request") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$cmd and $args
MC/DC0%0/2
$cmd and $args
$cmd
$args
Truth table33%1/3
A and B
A= $cmdB= $args
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | unless $cmd && $args; | ||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | 1 | ▶ | local $SIG{'PIPE'} = "IGNORE" unless $FLAG_NOSIGNAL; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | 1 | my $sock = $self->{sock_cache}; | |||||||||||||||||||||||||||||||||||||||||
| 126 | 1 | my $argstr = _encode_url_string(%$args); | |||||||||||||||||||||||||||||||||||||||||
| 127 | 1 | my $req = "$cmd $argstr\r\n"; | |||||||||||||||||||||||||||||||||||||||||
| 128 | 1 | my $reqlen = length($req); | |||||||||||||||||||||||||||||||||||||||||
| 129 | 1 | my $rv = 0; | |||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | 1 | ▶ | if ($sock) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 132 | # try our cached one, but assume it might be bogus | ||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | $self->run_hook('do_request_start', $cmd, $self->{last_host_connected}); | |||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | _debug("SOCK: cached = $sock, REQ: $req"); | |||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | $rv = send($sock, $req, $FLAG_NOSIGNAL); | |||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | ▶ | if ($! || ! defined $rv) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$! or not defined $rv
MC/DC0%0/2
$! or not defined $rv
$!
not defined $rv
Truth table0%0/3
A or not(B)
A= $!B= not defined $rv
| |||||||||||||||||||||||||||||||||||||||||||
| 137 | # undef is error, but $! may not be populated, we've found | ||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | $self->run_hook('do_request_send_error', $cmd, $self->{last_host_connected}); | |||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | undef $self->{sock_cache}; | |||||||||||||||||||||||||||||||||||||||||
| 140 | } elsif ($rv != $reqlen) { | ||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | $self->run_hook('do_request_length_mismatch', $cmd, $self->{last_host_connected}); | |||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | return _fail("send() didn't return expected length ($rv, not $reqlen)"); | |||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | 1 | ▶ | unless ($rv) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 147 | 1 | ▶ | $sock = $self->_get_sock | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 148 | or return _fail("couldn't connect to mogilefsd backend"); | ||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | $self->run_hook('do_request_start', $cmd, $self->{last_host_connected}); | |||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | _debug("SOCK: $sock, REQ: $req"); | |||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | $rv = send($sock, $req, $FLAG_NOSIGNAL); | |||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | ▶ | if ($!) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | $self->run_hook('do_request_send_error', $cmd, $self->{last_host_connected}); | |||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | return _fail("error talking to mogilefsd tracker: $!"); | |||||||||||||||||||||||||||||||||||||||||
| 155 | } elsif ($rv != $reqlen) { | ||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | $self->run_hook('do_request_length_mismatch', $cmd, $self->{last_host_connected}); | |||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | return _fail("send() didn't return expected length ($rv, not $reqlen)"); | |||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | $self->{sock_cache} = $sock; | |||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||
| 162 | # wait up to 3 seconds for the socket to come to life | ||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | ▶ | unless (_wait_for_readability(fileno($sock), $self->{timeout})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | close($sock); | |||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | $self->run_hook('do_request_read_timeout', $cmd, $self->{last_host_connected}); | |||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | undef $self->{sock_cache}; | |||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | return _fail("timed out after $self->{timeout}s against $self->{last_host_connected} when sending command: [$req]"); | |||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | # guard against externally-modified $/ changes. patch from | ||||||||||||||||||||||||||||||||||||||||||
| 171 | # Andreas J. Koenig. in practice nobody should do this, though, | ||||||||||||||||||||||||||||||||||||||||||
| 172 | # and this line should be unnecessary. | ||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | local $/ = "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | my $line = <$sock>; | |||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | $self->run_hook('do_request_finished', $cmd, $self->{last_host_connected}); | |||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | _debug("RESPONSE: $line"); | |||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | ▶ | unless (defined $line) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | undef $self->{sock_cache}; | |||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | return _fail("socket closed on read"); | |||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||
| 186 | # ERR <errcode> <errstr> | ||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | ▶ | if ($line =~ /^ERR\s+(\w+)\s*(\S*)/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | $self->{'lasterr'} = $1; | |||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | ▶ | $self->{'lasterrstr'} = $2 ? _unescape_url_string($2) : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | _debug("LASTERR: $1 $2"); | |||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||
| 194 | # OK <arg_len> <response> | ||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | ▶ | if ($line =~ /^OK\s+\d*\s*(\S*)/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | my $args = _decode_url_string($1); | |||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | _debug("RETURN_VARS: ", $args); | |||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | return $args; | |||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | undef $self->{sock_cache}; | |||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | _fail("invalid response from server: [$line]"); | |||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | ▶ | sub errstr { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
errstr: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | my MogileFS::Backend $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | ▶ | return unless $self->{'lasterr'}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | return join(" ", $self->{'lasterr'}, $self->{'lasterrstr'}); | |||||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | ▶ | sub errcode { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
errcode: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | my MogileFS::Backend $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | return $self->{lasterr}; | |||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | ▶ | sub last_tracker { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
last_tracker: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | return $self->{last_host_connected}; | |||||||||||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | ▶ | sub err { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
err: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | my MogileFS::Backend $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | ▶ | return $self->{lasterr} ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||
| 227 | 1 | ▶ | sub force_disconnect { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
force_disconnect: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 228 | 1 | my MogileFS::Backend $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 229 | 1 | undef $self->{sock_cache}; | |||||||||||||||||||||||||||||||||||||||||
| 230 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||
| 233 | ################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 234 | # MogileFS::Backend class methods | ||||||||||||||||||||||||||||||||||||||||||
| 235 | # | ||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||
| 237 | 1 | ▶ | sub _fail { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_fail: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 238 | 1 | croak "MogileFS::Backend: $_[0]"; | |||||||||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||
| 241 | 4 | *_debug = *MogileFS::Client::_debug; | |||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||
| 243 | 1 | ▶ | sub _connect_sock { # sock, sin, timeout | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_connect_sock: called CC=10 SCAR=27.2
| |||||||||||||||||||||||||||||||||||||||||||
| 244 | 1 | my ($sock, $sin, $timeout) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 245 | 1 | ▶ | $timeout ||= 0.25; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$timeout ||= "0.25"
MC/DC0%0/1
$timeout ||= "0.25"
$timeout
Truth table50%1/2
A
A= $timeout
| |||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||
| 247 | # make the socket non-blocking for the connection if wanted, but | ||||||||||||||||||||||||||||||||||||||||||
| 248 | # unconditionally set it back to blocking mode at the end | ||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||
| 250 | 1 | ▶ | if ($timeout) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 251 | 1 | IO::Handle::blocking($sock, 0); | |||||||||||||||||||||||||||||||||||||||||
| 252 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | IO::Handle::blocking($sock, 1); | |||||||||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||
| 256 | 1 | my $ret = connect($sock, $sin); | |||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||
| 258 | 1 | ▶ | if (!$ret && $timeout && $!==EINPROGRESS) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
not $ret and $timeout and $! == 115
not $ret and $timeout
MC/DC0%0/3
not $ret and $timeout and $! == 115
not $ret
$timeout
$! == 115
Truth table25%1/4
not(A) and B and C
A= not $retB= $timeoutC= $! == 115
| |||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||
| 260 | 1 | my $win=''; | |||||||||||||||||||||||||||||||||||||||||
| 261 | 1 | vec($win, fileno($sock), 1) = 1; | |||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||
| 263 | 1 | ▶ | if (select(undef, $win, undef, $timeout) > 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 264 | 1 | $ret = connect($sock, $sin); | |||||||||||||||||||||||||||||||||||||||||
| 265 | # EISCONN means connected & won't re-connect, so success | ||||||||||||||||||||||||||||||||||||||||||
| 266 | 1 | ▶ | $ret = 1 if !$ret && $!==EISCONN; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $ret and $! == 106
MC/DC0%0/2
not $ret and $! == 106
not $ret
$! == 106
Truth table33%1/3
not(A) and B
A= not $retB= $! == 106
| |||||||||||||||||||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||
| 270 | # turn blocking back on, as we expect to do blocking IO on our sockets | ||||||||||||||||||||||||||||||||||||||||||
| 271 | 1 | ▶ | IO::Handle::blocking($sock, 1) if $timeout; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||
| 273 | 1 | return $ret; | |||||||||||||||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||
| 276 | 1 | ▶ | sub _sock_to_host { # (host) | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_sock_to_host: called CC=8 SCAR=28.1
| |||||||||||||||||||||||||||||||||||||||||||
| 277 | 1 | my MogileFS::Backend $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 278 | 1 | my $host = shift; | |||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||
| 280 | # create a socket and try to do a non-blocking connect | ||||||||||||||||||||||||||||||||||||||||||
| 281 | 1 | my ($ip, $port) = $host =~ /^(.*):(\d+)$/; | |||||||||||||||||||||||||||||||||||||||||
| 282 | 1 | my $sock = "Sock_$host"; | |||||||||||||||||||||||||||||||||||||||||
| 283 | 1 | my $connected = 0; | |||||||||||||||||||||||||||||||||||||||||
| 284 | 1 | ▶ | my $proto = $PROTO_TCP ||= getprotobyname('tcp'); | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$MogileFS::Backend::PROTO_TCP ||= getprotobyname "tcp"
MC/DC0%0/2
$MogileFS::Backend::PROTO_TCP ||= getprotobyname "tcp"
$MogileFS::Backend::PROTO_TCP
getprotobyname "tcp"
Truth table33%1/3
A ||= B
A= $MogileFS::Backend::PROTO_TCPB= getprotobyname "tcp"
| |||||||||||||||||||||||||||||||||||||||||||
| 285 | 1 | my $sin; | |||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||
| 287 | # try preferred ips | ||||||||||||||||||||||||||||||||||||||||||
| 288 | 1 | ▶ | if ($self->{pref_ip} && (my $prefip = $self->{pref_ip}->{$ip})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"pref_ip"} and my $prefip = $self->{"pref_ip"}{$ip}
MC/DC0%0/2
$self->{"pref_ip"} and my $prefip = $self->{"pref_ip"}{$ip}
$self->{"pref_ip"}
my $prefip = $self->{"pref_ip"}{$ip}
Truth table33%1/3
A and B
A= $self->{"pref_ip"}B= my $prefip = $self->{"pref_ip"}{$ip}
| |||||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | _debug("using preferred ip $prefip over $ip"); | |||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | socket($sock, PF_INET, SOCK_STREAM, $proto); | |||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | $sin = Socket::sockaddr_in($port, Socket::inet_aton($prefip)); | |||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | ▶ | if (_connect_sock($sock, $sin, 0.1)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | $connected = 1; | |||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | $self->{last_host_connected} = "$prefip:$port"; | |||||||||||||||||||||||||||||||||||||||||
| 295 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | _debug("failed connect to preferred ip $prefip"); | |||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | close $sock; | |||||||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||
| 301 | # now try the original ip | ||||||||||||||||||||||||||||||||||||||||||
| 302 | 1 | ▶ | unless ($connected) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 303 | 1 | socket($sock, PF_INET, SOCK_STREAM, $proto); | |||||||||||||||||||||||||||||||||||||||||
| 304 | 1 | ▶ | my $aton_ip = Socket::inet_aton($ip) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 305 | or return undef; | ||||||||||||||||||||||||||||||||||||||||||
| 306 | 1 | $sin = Socket::sockaddr_in($port, $aton_ip); | |||||||||||||||||||||||||||||||||||||||||
| 307 | 1 | ▶ | return undef unless _connect_sock($sock, $sin); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | $self->{last_host_connected} = $host; | |||||||||||||||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||
| 311 | # just throw back the socket we have so far | ||||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | return $sock; | |||||||||||||||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||
| 315 | # return a new mogilefsd socket, trying different hosts until one is found, | ||||||||||||||||||||||||||||||||||||||||||
| 316 | # or undef if they're all dead | ||||||||||||||||||||||||||||||||||||||||||
| 317 | 1 | ▶ | sub _get_sock { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_sock: called CC=8 SCAR=21.8
| |||||||||||||||||||||||||||||||||||||||||||
| 318 | 1 | my MogileFS::Backend $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 319 | 1 | ▶ | return undef unless $self; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||
| 321 | 1 | my $size = scalar(@{$self->{hosts}}); | |||||||||||||||||||||||||||||||||||||||||
| 322 | 1 | ▶ | my $tries = $size > 15 ? 15 : $size; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||
| 324 | 1 | ▶ | unless (defined($self->{last_host_idx})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 325 | 1 | $self->{last_host_idx} = int(rand() * $size); | |||||||||||||||||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||
| 328 | 1 | my $now = time(); | |||||||||||||||||||||||||||||||||||||||||
| 329 | 1 | my $sock; | |||||||||||||||||||||||||||||||||||||||||
| 330 | 1 | foreach (1..$tries) { | |||||||||||||||||||||||||||||||||||||||||
| 331 | 1 | $self->{last_host_idx} = ($self->{last_host_idx}+1) % $size; | |||||||||||||||||||||||||||||||||||||||||
| 332 | 1 | my $host = $self->{hosts}->[$self->{last_host_idx}]; | |||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||||
| 334 | # try dead hosts every 5 seconds | ||||||||||||||||||||||||||||||||||||||||||
| 335 | next if $self->{host_dead}->{$host} && | ||||||||||||||||||||||||||||||||||||||||||
| 336 | 1 | ▶ | $self->{host_dead}->{$host} > $now - 5; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"host_dead"}{$host} and $self->{"host_dead"}{$host} > $now - 5
MC/DC0%0/2
$self->{"host_dead"}{$host} and $self->{"host_dead"}{$host} > $now - 5
$self->{"host_dead"}{$host}
$self->{"host_dead"}{$host} > $now - 5
Truth table33%1/3
A and B
A= $self->{"host_dead"}{$host}B= $self->{"host_dead"}{$host} > $now - 5
| |||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||
| 338 | 1 | ▶ | last if $sock = $self->_sock_to_host($host); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||
| 340 | # mark sock as dead | ||||||||||||||||||||||||||||||||||||||||||
| 341 | 1 | _debug("marking host dead: $host @ $now"); | |||||||||||||||||||||||||||||||||||||||||
| 342 | 1 | $self->{host_dead}->{$host} = $now; | |||||||||||||||||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||||
| 345 | 1 | return $sock; | |||||||||||||||||||||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | ▶ | sub _escape_url_string { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_escape_url_string: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | my $str = shift; | |||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | $str =~ s/([^a-zA-Z0-9_\,\-.\/\\\: ])/uc sprintf("%%%02x",ord($1))/eg; | |||||||||||||||||||||||||||||||||||||||||
| 351 | 0 | $str =~ tr/ /+/; | |||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | return $str; | |||||||||||||||||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||
| 355 | 0 | ▶ | sub _unescape_url_string { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_unescape_url_string: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | my $str = shift; | |||||||||||||||||||||||||||||||||||||||||
| 357 | 0 | $str =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; | |||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | $str =~ tr/+/ /; | |||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | return $str; | |||||||||||||||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||||
| 362 | 1 | ▶ | sub _encode_url_string { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_encode_url_string: called CC=2 SCAR=10.1
| |||||||||||||||||||||||||||||||||||||||||||
| 363 | 1 | my %args = @_; | |||||||||||||||||||||||||||||||||||||||||
| 364 | 1 | ▶ | return "" unless %args; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 365 | return join("&", | ||||||||||||||||||||||||||||||||||||||||||
| 366 | map { _escape_url_string($_) . '=' . | ||||||||||||||||||||||||||||||||||||||||||
| 367 | 0 | _escape_url_string($args{$_}) } | |||||||||||||||||||||||||||||||||||||||||
| 368 | 0 | grep { defined $args{$_} } keys %args | |||||||||||||||||||||||||||||||||||||||||
| 369 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 370 | } | ||||||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | ▶ | sub _decode_url_string { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_decode_url_string: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 373 | 0 | my $arg = shift; | |||||||||||||||||||||||||||||||||||||||||
| 374 | 0 | ▶ | my $buffer = ref $arg ? $arg : \$arg; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 375 | 0 | my $hashref = {}; # output hash | |||||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | my $pair; | |||||||||||||||||||||||||||||||||||||||||
| 378 | 0 | my @pairs = split(/&/, $$buffer); | |||||||||||||||||||||||||||||||||||||||||
| 379 | 0 | my ($name, $value); | |||||||||||||||||||||||||||||||||||||||||
| 380 | 0 | foreach $pair (@pairs) { | |||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | ($name, $value) = split(/=/, $pair); | |||||||||||||||||||||||||||||||||||||||||
| 382 | 0 | $value =~ tr/+/ /; | |||||||||||||||||||||||||||||||||||||||||
| 383 | 0 | $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; | |||||||||||||||||||||||||||||||||||||||||
| 384 | 0 | $name =~ tr/+/ /; | |||||||||||||||||||||||||||||||||||||||||
| 385 | 0 | $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; | |||||||||||||||||||||||||||||||||||||||||
| 386 | 0 | ▶ | $hashref->{$name} .= $hashref->{$name} ? "\0$value" : $value; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 387 | } | ||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||
| 389 | 0 | return $hashref; | |||||||||||||||||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||
| 392 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||