Any/_Base.pm

filter: Statementstmt 56.1% 137 / 244 Branchbran 25.4% 32 / 126 Conditioncond 31.8% 21 / 66 MC/DCmcdc 2.7% 1 / 37 Subroutinesub 65.0% 26 / 40 Podpod 0.0% 0 / 2 totaltotal 42.1% 217 / 515 CC 94 SCAR 37.6
CC
94
Cov
44%
_quote_args
272.0
_encode_data
42.0
_decode_data
42.0
CRAP 43.0
« Any/Test/Backend/Remote.pm ↑ Summary Any/POSIXShellQuoter.pm »
1 package Net::SSH::Any::_Base;
2  
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 4 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use Encode ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 4 ▶use Net::SSH::Any::Constants qw(SSHA_BACKEND_ERROR SSHA_LOCAL_IO_ERROR SSHA_UNIMPLEMENTED_ERROR SSHA_ENCODING_ERROR);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 4 ▶use Net::SSH::Any::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 4 our @CARP_NOT = qw(Net::SSH::Any::Util);
14  
15 3 ▶sub _new {
Subroutine _new: called CC=9 SCAR=24.0
16 3 my ($class, $opts) = @_;
17 3 my $os = delete $opts->{os};
18  
19 3 my (%remote_cmd, %local_cmd, %remote_extra_args, %local_extra_args);
20 3 for (keys %$opts) {
21 9 ▶ /^remote_(.*)_cmd$/ and $remote_cmd{$1} = $opts->{$_};
Branch: 1 branch
BranchTrueFalseTotal
/^remote_(.*)_cmd$/ and $remote_cmd{$1} = $opts->{$_} 0 9 9
22 9 ▶ /^local_(.*)_cmd$/ and $local_cmd{$1} = $opts->{$_};
Branch: 1 branch
BranchTrueFalseTotal
/^local_(.*)_cmd$/ and $local_cmd{$1} = $opts->{$_} 0 9 9
23 9 ▶ /^remote_(.*)_extra_args$/ and $remote_extra_args{$1} = $opts->{$_};
Branch: 1 branch
BranchTrueFalseTotal
/^remote_(.*)_extra_args$/ and $remote_extra_args{$1} = $opts->{$_} 0 9 9
24 9 ▶ /^local_(.*)_extra_args$/ and $local_extra_args{$1} = $opts->{$_};
Branch: 1 branch
BranchTrueFalseTotal
/^local_(.*)_extra_args$/ and $local_extra_args{$1} = $opts->{$_} 0 9 9
25 }
26  
27 3 my $relaxed_command_lookup = delete $opts->{relaxed_command_lookup};
28  
29 3 my $self = { os => $os,
30 error => 0,
31 error_prefix => [],
32 backend_log => [],
33 remote_cmd => \%remote_cmd,
34 local_cmd => \%local_cmd,
35 remote_extra_args => \%remote_extra_args,
36 local_extra_args => \%local_extra_args,
37 relaxed_cmd_lookup => $relaxed_command_lookup,
38 };
39  
40 3 ▶ my $encoding = $self->{encoding} = delete $opts->{encoding} // 'utf8';
Condition50%1/2
delete $opts->{"encoding"} // "utf8"
l!l
03
MC/DC0%0/1
delete $opts->{"encoding"} // "utf8"
delete $opts->{"encoding"}
Truth table50%1/2
A
A= delete $opts->{"encoding"}
Aresult
11
00
41 3 ▶ $self->{stream_encoding} = delete $opts->{stream_encoding} // $encoding;
Condition33%1/3
delete $opts->{"stream_encoding"} // $encoding
l!l&&r!l&&!r
030
MC/DC0%0/2
delete $opts->{"stream_encoding"} // $encoding
delete $opts->{"stream_encoding"} $encoding
Truth table33%1/3
A // B
A= delete $opts->{"stream_encoding"}B= $encoding
ABresult
1X1
011
000
42 3 ▶ $self->{argument_encoding} = delete $opts->{argument_encoding} // $encoding;
Condition33%1/3
delete $opts->{"argument_encoding"} // $encoding
l!l&&r!l&&!r
030
MC/DC0%0/2
delete $opts->{"argument_encoding"} // $encoding
delete $opts->{"argument_encoding"} $encoding
Truth table33%1/3
A // B
A= delete $opts->{"argument_encoding"}B= $encoding
ABresult
1X1
011
000
43  
44 3 bless $self, $class;
45 3 $self;
46 }
47  
48 3 ▶sub _log_error_and_reset_backend {
Subroutine _log_error_and_reset_backend: called CC=1 SCAR=0.0
49 3 my $self = shift;
50 3 push @{$self->{backend_log}}, "$self->{backend}: [".($self->{error}+0)."] $self->{error}";
51 3 $self->{error} = 0;
52 3 delete $self->{backend};
53 3 delete $self->{backend_module};
54 ()
55 3 }
56  
57 3 ▶sub _load_backend_module {
Subroutine _load_backend_module: called CC=6 SCAR=22.8
58 3 my ($self, $class, $backend, $required_version) = @_;
59 3 ▶ $backend =~ /^\w+$/ or croak "Bad backend name '$backend' for class '$class'";
Branch: 1 branch
BranchTrueFalseTotal
$backend =~ /^\w+$/ or croak("Bad backend name '${backend}' for class '${class}'") 3 0 3
60 3 $self->{backend} = $backend;
61 3 my $module = $self->{backend_module} = "${class}::Backend::${backend}";
62  
63 3 local ($@, $SIG{__DIE__});
64 3 ▶ my $ok = eval <<EOE;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
65 no strict;
66 no warnings;
67 require $module;
68 1;
69 EOE
70 3 ▶ if ($ok) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ok) { } 3 0 3
71 3 ▶ if ($required_version) {
Branch: 1 branch
BranchTrueFalseTotal
if ($required_version) { } 0 3 3
72 0 ▶ if ($module->can('_backend_api_version')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($module->can('_backend_api_version')) { } 0 0 0
73 0 my $version = $module->_backend_api_version;
74 0 ▶ if ($version >= $required_version) {
Branch: 1 branch
BranchTrueFalseTotal
if ($version >= $required_version) { } 0 0 0
75 0 return 1;
76 }
77 else {
78 0 $self->_set_error(SSHA_BACKEND_ERROR,
79 "backend API version $version is too old ($required_version required)");
80 }
81 }
82 else {
83 0 $self->_set_error(SSHA_BACKEND_ERROR, 'method _backend_api_version missing');
84 }
85 }
86 else {
87 3 return 1;
88 }
89 }
90 else {
91 0 $self->_set_error(SSHA_BACKEND_ERROR, "unable to load module '$module'", $@);
92 }
93  
94 0 $self->_log_error_and_reset_backend;
95 ()
96 0 }
97  
98 3 ▶sub error { shift->{error} }
Subroutine error: called CC=1 SCAR=0.0
Pod undocumented
99  
100 0 ▶sub die_on_error {
Subroutine die_on_error: not called CC=2 SCAR=17.9
Pod undocumented
101 0 my $self = shift;
102 0 ▶ $self->{error} and croak(join(': ', @_, "$self->{error}"));
Branch: 1 branch
BranchTrueFalseTotal
$self->{"error"} and croak(join(": ", @_, qq[$self->{"error"}])) 0 0 0
103 0 1;
104 }
105  
106 6 ▶sub _set_error {
Subroutine _set_error: called CC=7 SCAR=22.0
107 6 my $self = shift;
108 6 ▶ my $code = shift || 0;
Condition50%1/2
shift() || 0
l!l
60
MC/DC0%0/1
shift() || 0
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
109 6 ▶ my @msg = grep { defined && length } @_;
Condition33%1/3
defined $_ && length $_
!ll&&!rl&&r
006
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table33%1/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
110 6 ▶ @msg = "Unknown error $code" unless @msg;
Branch: 1 branch
BranchTrueFalseTotal
unless @msg 0 6 6
111 my $error = $self->{error} = ( $code
112 6 ▶ ? Scalar::Util::dualvar($code, join(': ', @{$self->{error_prefix}}, @msg))
Branch: 1 branch
BranchTrueFalseTotal
$code ? : 6 0 6
113 : 0 );
114 6 ▶ $debug and $debug & 1 and _debug "set_error($code - $error)";
Branch: 1 branch
BranchTrueFalseTotal
$Net::SSH::Any::_Base::debug and $Net::SSH::Any::_Base::debug & 1 and _debug("set_error($code - $error)") 0 6 6
Condition33%1/3
$Net::SSH::Any::_Base::debug and $Net::SSH::Any::_Base::debug & 1
!ll&&!rl&&r
600
MC/DC0%0/2
$Net::SSH::Any::_Base::debug and $Net::SSH::Any::_Base::debug & 1
$Net::SSH::Any::_Base::debug $Net::SSH::Any::_Base::debug & 1
Truth table33%1/3
A and B
A= $Net::SSH::Any::_Base::debugB= $Net::SSH::Any::_Base::debug & 1
ABresult
0X0
100
111
115 6 return $error
116 }
117  
118 2 ▶sub _or_set_error {
Subroutine _or_set_error: called CC=2 SCAR=7.2
119 2 my $self = shift;
120 2 ▶ $self->{error} or $self->_set_error(@_);
Branch: 1 branch
BranchTrueFalseTotal
$self->{"error"} or $self->_set_error(@_) 0 2 2
121 }
122  
123 0 ▶sub _or_check_error_after_eval {
Subroutine _or_check_error_after_eval: not called CC=3 SCAR=24.8
124 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
125 0 my ($any, $code) = @_;
126 0 ▶ unless ($any->{error}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($any->{"error"}) 0 0 0
127 0 my $err = $@;
128 0 $err =~ s/(.*) at .* line \d+.$/$1/;
129 0 $any->_set_error($code, $err);
130 }
131 0 return 0;
132 }
133 1
134 0 }
135  
136 0 ▶sub _open_file {
Subroutine _open_file: not called CC=3 SCAR=24.8
137 0 my ($self, $def_mode, $name_or_args) = @_;
138 0 ▶ my ($mode, @args) = (ref $name_or_args
Branch: 1 branch
BranchTrueFalseTotal
ref $name_or_args ? : 0 0 0
139 ? @$name_or_args
140 : ($def_mode, $name_or_args));
141 0 ▶ if (open my $fh, $mode, @args) {
Branch: 1 branch
BranchTrueFalseTotal
if (open my $fh, $mode, @args) 0 0 0
142 0 return $fh;
143 }
144 0 $self->_set_error(SSHA_LOCAL_IO_ERROR, "Unable to open file '@args': $!");
145 0 return undef;
146 }
147  
148 4 my %loaded;
149 3 ▶sub _load_module {
Subroutine _load_module: called CC=3 SCAR=15.1
150 3 my ($self, $module) = @_;
151 3 ▶ $loaded{$module} ||= eval "require $module; 1" and return 1;
Branch: 1 branch
BranchTrueFalseTotal
$loaded{$module} ||= eval "require $module; 1" and return 1 3 0 3
Condition33%1/3
$loaded{$module} ||= eval "require $module; 1"
l!l&&r!l&&!r
030
MC/DC0%0/2
$loaded{$module} ||= eval "require $module; 1"
$loaded{$module} eval "require $module; 1"
Truth table33%1/3
A ||= B
A= $loaded{$module}B= eval "require $module; 1"
ABresult
1X1
011
000
152 0 $self->_set_error(SSHA_UNIMPLEMENTED_ERROR, "Unable to load perl module $module");
153 0 return;
154 }
155  
156 3 ▶sub _load_os {
Subroutine _load_os: called CC=4 SCAR=14.6
157 3 my $self = shift;
158 3 ▶ my $os = $self->{os} //= ($^O =~ /^mswin/i ? 'MSWin' : 'POSIX');
Branch: 1 branch
BranchTrueFalseTotal
$^O =~ /^mswin/i ? : 0 3 3
Condition50%1/2
$self->{"os"} //= $^O =~ /^mswin/i ? "MSWin" : "POSIX"
l!l
03
MC/DC0%0/1
$self->{"os"} //= $^O =~ /^mswin/i ? "MSWin" : "POSIX"
$self->{"os"}
Truth table50%1/2
A
A= $self->{"os"}
Aresult
11
00
159 3 my $os_module = "Net::SSH::Any::OS::$os";
160 3 ▶ $self->_load_module($os_module) or return;
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_module($os_module) or return 3 0 3
161 3 $self->{os_module} = $os_module;
162 }
163  
164 3 ▶sub _find_cmd_by_friend {
Subroutine _find_cmd_by_friend: called CC=4 SCAR=13.9
165 3 my ($any, $name, $friend) = @_;
166 3 ▶ if (defined $friend) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $friend) 1 2 3
167 1 my $up = File::Spec->updir;
168 1 my ($drive, $dir) = File::Spec->splitpath($friend);
169 1 my $base = File::Spec->catpath($drive, $dir);
170 1 for my $path (File::Spec->join($base, $name),
171 map File::Spec->join($base, $up, $_, $name), qw(bin sbin libexec) ) {
172 4 my $cmd = $any->_os_validate_cmd($path);
173 4 ▶ return $cmd if defined $cmd;
Branch: 1 branch
BranchTrueFalseTotal
if defined $cmd 0 4 4
174 }
175 }
176 ()
177 3 }
178  
179 3 ▶sub _find_cmd_in_path {
Subroutine _find_cmd_in_path: called CC=3 SCAR=11.1
180 3 my ($any, $name) = @_;
181 3 for my $path (File::Spec->path) {
182 30 my $cmd = $any->_os_validate_cmd(File::Spec->join($path, $name));
183 30 ▶ return $cmd if defined $cmd;
Branch: 1 branch
BranchTrueFalseTotal
if defined $cmd 0 30 30
184 }
185 ()
186 3 }
187  
188 3 ▶sub _find_cmd {
Subroutine _find_cmd: called CC=10 SCAR=27.5
189 3 my $any = shift;
190 3 ▶ my $opts = (ref $_[0] ? shift : {});
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 3 0 3
191 3 my ($name, $friend, $app, $default) = @_;
192 3 my $safe_name = $name;
193 3 $safe_name =~ s/\W/_/g;
194 3 ▶ my $cmd = ( $any->{local_cmd}{$safe_name} //
Condition33%5/15
(((($any->{"local_cmd"}{$safe_name} // $any->_find_cmd_by_friend($name, $friend)) // $any->_find_cmd_in_path($name)) // $any->_find_helper_cmd($name)) // $any->_os_find_cmd_by_app($name, $app)) // $any->_os_validate_cmd($default)
l!l&&r!l&&!r
003
((($any->{"local_cmd"}{$safe_name} // $any->_find_cmd_by_friend($name, $friend)) // $any->_find_cmd_in_path($name)) // $any->_find_helper_cmd($name)) // $any->_os_find_cmd_by_app($name, $app)
l!l&&r!l&&!r
003
(($any->{"local_cmd"}{$safe_name} // $any->_find_cmd_by_friend($name, $friend)) // $any->_find_cmd_in_path($name)) // $any->_find_helper_cmd($name)
l!l&&r!l&&!r
003
($any->{"local_cmd"}{$safe_name} // $any->_find_cmd_by_friend($name, $friend)) // $any->_find_cmd_in_path($name)
l!l&&r!l&&!r
003
$any->{"local_cmd"}{$safe_name} // $any->_find_cmd_by_friend($name, $friend)
l!l&&r!l&&!r
003
MC/DC0%0/6
(((($any->{"local_cmd"}{$safe_name} // $any->_find_cmd_by_friend($name, $friend)) // $any->_find_cmd_in_path($name)) // $any->_find_helper_cmd($name)) // $any->_os_find_cmd_by_app($name, $app)) // $any->_os_validate_cmd($default)
$any->{"local_cmd"}{$safe_name} $any->_find_cmd_by_friend($name, $friend) $any->_find_cmd_in_path($name) $any->_find_helper_cmd($name) $any->_os_find_cmd_by_app($name, $app) $any->_os_validate_cmd($default)
Truth table14%1/7
A // B // C // D // E // F
A= $any->{"local_cmd"}{$safe_name}B= $any->_find_cmd_by_friend($name, $friend)C= $any->_find_cmd_in_path($name)D= $any->_find_helper_cmd($name)E= $any->_os_find_cmd_by_app($name, $app)F= $any->_os_validate_cmd($default)
ABCDEFresult
1XXXXX1
01XXXX1
001XXX1
0001XX1
00001X1
0000011
0000000
195 $any->_find_cmd_by_friend($name, $friend) //
196 $any->_find_cmd_in_path($name) //
197 $any->_find_helper_cmd($name) //
198 $any->_os_find_cmd_by_app($name, $app) //
199 $any->_os_validate_cmd($default) );
200 3 ▶ return $cmd if defined $cmd;
Branch: 1 branch
BranchTrueFalseTotal
if defined $cmd 0 3 3
201 3 ▶ return $name if $opts->{relaxed} or $any->{relaxed_cmd_lookup};
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"relaxed"} or $any->{"relaxed_cmd_lookup"} 1 2 3
Condition66%2/3
$opts->{"relaxed"} or $any->{"relaxed_cmd_lookup"}
l!l&&r!l&&!r
102
MC/DC50%1/2
$opts->{"relaxed"} or $any->{"relaxed_cmd_lookup"}
$opts->{"relaxed"} $any->{"relaxed_cmd_lookup"}
Truth table66%2/3
A or B
A= $opts->{"relaxed"}B= $any->{"relaxed_cmd_lookup"}
ABresult
1X1
011
000
202 2 $any->_or_set_error(SSHA_BACKEND_ERROR, "Unable to find command '$name'");
203 ()
204 2 }
205  
206 3 ▶sub _find_helper_cmd {
Subroutine _find_helper_cmd: called CC=8 SCAR=23.7
207 3 my ($any, $name) = @_;
208 3 ▶ $debug and $debug & 1024 and _debug "looking for helper $name";
Branch: 1 branch
BranchTrueFalseTotal
$Net::SSH::Any::_Base::debug and $Net::SSH::Any::_Base::debug & 1024 and _debug("looking for helper $name") 0 3 3
Condition33%1/3
$Net::SSH::Any::_Base::debug and $Net::SSH::Any::_Base::debug & 1024
!ll&&!rl&&r
300
MC/DC0%0/2
$Net::SSH::Any::_Base::debug and $Net::SSH::Any::_Base::debug & 1024
$Net::SSH::Any::_Base::debug $Net::SSH::Any::_Base::debug & 1024
Truth table33%1/3
A and B
A= $Net::SSH::Any::_Base::debugB= $Net::SSH::Any::_Base::debug & 1024
ABresult
0X0
100
111
209 3 ▶ my $module = my $last = $any->{backend_module} // return;
Condition50%1/2
$any->{"backend_module"} // (return)
l!l
30
MC/DC0%0/1
$any->{"backend_module"} // (return)
$any->{"backend_module"}
Truth table50%1/2
A
A= $any->{"backend_module"}
Aresult
11
00
210 3 ▶ $last =~ s/.*::// or return;
Branch: 1 branch
BranchTrueFalseTotal
$last =~ s/.*::// or return 3 0 3
211 3 $module =~ s{::}{/}g;
212 3 ▶ $debug and $debug & 1024 and _debug "module as \$INC key is ", $module, ".pm";
Branch: 1 branch
BranchTrueFalseTotal
$Net::SSH::Any::_Base::debug and $Net::SSH::Any::_Base::debug & 1024 and _debug("module as \$INC key is ", $module, ".pm") 0 3 3
Condition33%1/3
$Net::SSH::Any::_Base::debug and $Net::SSH::Any::_Base::debug & 1024
!ll&&!rl&&r
300
MC/DC0%0/2
$Net::SSH::Any::_Base::debug and $Net::SSH::Any::_Base::debug & 1024
$Net::SSH::Any::_Base::debug $Net::SSH::Any::_Base::debug & 1024
Truth table33%1/3
A and B
A= $Net::SSH::Any::_Base::debugB= $Net::SSH::Any::_Base::debug & 1024
ABresult
0X0
100
111
213 3 ▶ my $file_pm = $INC{"$module.pm"} // return;
Condition50%1/2
$INC{"$module.pm"} // (return)
l!l
30
MC/DC0%0/1
$INC{"$module.pm"} // (return)
$INC{"$module.pm"}
Truth table50%1/2
A
A= $INC{"$module.pm"}
Aresult
11
00
214 3 my ($drive, $dir) = File::Spec->splitpath(File::Spec->rel2abs($file_pm));
215 3 my $path = File::Spec->catpath($drive, $dir, $last, 'Helpers', $name);
216 3 $any->_os_validate_cmd($path);
217 }
218  
219 0 ▶sub _find_local_extra_args {
Subroutine _find_local_extra_args: not called CC=3 SCAR=24.8
220 0 my ($any, $name, $opts, @default) = @_;
221 0 my $safe_name = $name;
222 0 $safe_name =~ s/\W/_/g;
223 my $extra = ( $opts->{"local_${safe_name}_extra_args"} //
224 0 ▶ $any->{local_extra_args}{$safe_name} //
Condition0%0/5
($$opts{"local_${safe_name}_extra_args"} // $any->{"local_extra_args"}{$safe_name}) // \@default
l!l
00
$$opts{"local_${safe_name}_extra_args"} // $any->{"local_extra_args"}{$safe_name}
l!l&&r!l&&!r
000
MC/DC0%0/2
($$opts{"local_${safe_name}_extra_args"} // $any->{"local_extra_args"}{$safe_name}) // \@default
$$opts{"local_${safe_name}_extra_args"} $any->{"local_extra_args"}{$safe_name}
Truth table0%0/3
A // B
A= $$opts{"local_${safe_name}_extra_args"}B= $any->{"local_extra_args"}{$safe_name}
ABresult
1X1
011
000
225 \@default );
226 0 [_array_or_scalar_to_list $extra]
227 }
228  
229 4 my %posix_shell = map { $_ => 1 } qw(POSIX bash sh ksh ash dash pdksh mksh lksh zsh fizsh posh);
230  
231 0 ▶sub _new_quoter {
Subroutine _new_quoter: not called CC=4 SCAR=30.0
232 0 my ($any, $shell) = @_;
233 0 ▶ if ($posix_shell{$shell}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($posix_shell{$shell}) { } 0 0 0
234 0 ▶ $any->_load_module('Net::SSH::Any::POSIXShellQuoter') or return;
Branch: 1 branch
BranchTrueFalseTotal
$any->_load_module("Net::SSH::Any::POSIXShellQuoter") or return 0 0 0
235 0 return 'Net::SSH::Any::POSIXShellQuoter';
236 }
237 else {
238 0 ▶ $any->_load_module('Net::OpenSSH::ShellQuoter') or return;
Branch: 1 branch
BranchTrueFalseTotal
$any->_load_module("Net::OpenSSH::ShellQuoter") or return 0 0 0
239 0 return Net::OpenSSH::ShellQuoter->quoter($shell);
240 }
241 }
242  
243 0 ▶sub _quoter {
Subroutine _quoter: not called CC=2 SCAR=17.9
244 0 my ($any, $shell) = @_;
245 0 ▶ defined $shell or croak "shell argument is undef";
Branch: 1 branch
BranchTrueFalseTotal
defined $shell or croak("shell argument is undef") 0 0 0
246 0 return $any->_new_quoter($shell);
247 }
248  
249 0 ▶sub _quote_args {
Subroutine _quote_args: not called CC=16 SCAR=56.1
250 0 my $any = shift;
251 0 my $opts = shift;
252 0 ▶ ref $opts eq 'HASH' or die "internal error";
Branch: 1 branch
BranchTrueFalseTotal
ref $opts eq "HASH" or die "internal error" 0 0 0
253 0 my $quote = delete $opts->{quote_args};
254 0 my $glob_quoting = delete $opts->{glob_quoting};
255 0 my $argument_encoding = $any->_delete_argument_encoding($opts);
256 0 ▶ $quote = (@_ > 1) unless defined $quote;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $quote 0 0 0
257  
258 0 my @quoted;
259 0 ▶ if ($quote) {
Branch: 1 branch
BranchTrueFalseTotal
if ($quote) { } 0 0 0
260 0 ▶ my $shell = delete $opts->{remote_shell} // delete $opts->{shell};
Condition0%0/3
delete $opts->{"remote_shell"} // delete $opts->{"shell"}
l!l&&r!l&&!r
000
MC/DC0%0/2
delete $opts->{"remote_shell"} // delete $opts->{"shell"}
delete $opts->{"remote_shell"} delete $opts->{"shell"}
Truth table0%0/3
A // B
A= delete $opts->{"remote_shell"}B= delete $opts->{"shell"}
ABresult
1X1
011
000
261 0 ▶ my $quoter = $any->_quoter($shell) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $quoter = $any->_quoter($shell) or return 0 0 0
262 0 ▶ my $quote_method = ($glob_quoting ? 'quote_glob' : 'quote');
Branch: 1 branch
BranchTrueFalseTotal
$glob_quoting ? : 0 0 0
263  
264 # foo => $quoter
265 # \foo => $quoter_glob
266 # \\foo => no quoting at all and disable extended quoting as it is not safe
267 0 for (@_) {
268 0 ▶ if (ref $_) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_) { } 0 0 0
269 0 ▶ if (ref $_ eq 'SCALAR') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $_ eq 'SCALAR') { } 0 0 0
elsif (ref $_ eq 'REF' and ref $$_ eq 'SCALAR') { } 0 0 0
270 0 push @quoted, $quoter->quote_glob($$_);
271 }
272 ▶ elsif (ref $_ eq 'REF' and ref $$_ eq 'SCALAR') {
Condition0%0/3
ref $_ eq "REF" and ref $$_ eq "SCALAR"
!ll&&!rl&&r
000
MC/DC0%0/2
ref $_ eq "REF" and ref $$_ eq "SCALAR"
ref $_ eq "REF" ref $$_ eq "SCALAR"
Truth table0%0/3
A and B
A= ref $_ eq "REF"B= ref $$_ eq "SCALAR"
ABresult
0X0
100
111
273 0 push @quoted, $$$_;
274 }
275 else {
276 0 croak "invalid reference in remote command argument list"
277 }
278 }
279 else {
280 0 push @quoted, $quoter->$quote_method($_);
281 }
282 }
283 }
284 else {
285 0 ▶ croak "reference found in argument list when argument quoting is disabled" if (grep ref, @_);
Branch: 1 branch
BranchTrueFalseTotal
if grep ref($_), @_ 0 0 0
286 0 @quoted = @_;
287 }
288 0 $any->_encode_args($argument_encoding, @quoted);
289 0 ▶ $debug and $debug & 1024 and _debug("command+args: @quoted");
Branch: 1 branch
BranchTrueFalseTotal
$Net::SSH::Any::_Base::debug and $Net::SSH::Any::_Base::debug & 1024 and _debug("command+args: @quoted") 0 0 0
Condition0%0/3
$Net::SSH::Any::_Base::debug and $Net::SSH::Any::_Base::debug & 1024
!ll&&!rl&&r
000
MC/DC0%0/2
$Net::SSH::Any::_Base::debug and $Net::SSH::Any::_Base::debug & 1024
$Net::SSH::Any::_Base::debug $Net::SSH::Any::_Base::debug & 1024
Truth table0%0/3
A and B
A= $Net::SSH::Any::_Base::debugB= $Net::SSH::Any::_Base::debug & 1024
ABresult
0X0
100
111
290 0 ▶ wantarray ? @quoted : join(" ", @quoted);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
291 }
292  
293 0 ▶sub _delete_argument_encoding {
Subroutine _delete_argument_encoding: not called CC=1 SCAR=6.9
294 0 my ($any, $opts) = @_;
295 _first_defined(delete $opts->{argument_encoding},
296 delete $opts->{encoding},
297 $any->{argument_encoding})
298 0 }
299  
300 0 ▶sub _delete_stream_encoding {
Subroutine _delete_stream_encoding: not called CC=1 SCAR=6.9
301 0 my ($any, $opts) = @_;
302 _first_defined(delete $opts->{stream_encoding},
303 $opts->{encoding},
304 $any->{stream_encoding})
305 0 }
306  
307 0 ▶sub _find_encoding {
Subroutine _find_encoding: not called CC=2 SCAR=17.9
308 0 my ($any, $encoding, $data) = @_;
309 0 ▶ my $enc = Encode::find_encoding($encoding)
Branch: 1 branch
BranchTrueFalseTotal
my $enc = &Encode::find_encoding($encoding) or $any->_or_set_error(7, "bad encoding '${encoding}'") 0 0 0
310 or $any->_or_set_error(SSHA_ENCODING_ERROR, "bad encoding '$encoding'");
311 0 return $enc
312 }
313  
314 0 ▶sub _encode_data {
Subroutine _encode_data: not called CC=6 SCAR=37.4
315 0 my $any = shift;
316 0 my $encoding = shift;
317 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
318 0 ▶ my $enc = $any->_find_encoding($encoding) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $enc = $any->_find_encoding($encoding) or return 0 0 0
319 0 local $any->{error_prefix} = [@{$any->{error_prefix}}, "data encoding failed"];
320 0 local ($@, $SIG{__DIE__});
321 0 ▶ eval { defined and $_ = $enc->encode($_, Encode::FB_CROAK()) for @_ };
Branch: 1 branch
BranchTrueFalseTotal
defined $_ and $_ = $enc->encode($_, 1) 0 0 0
322 0 ▶ $any->_or_check_error_after_eval(SSHA_ENCODING_ERROR) or return;
Branch: 1 branch
BranchTrueFalseTotal
$any->_or_check_error_after_eval(7) or return 0 0 0
323 }
324 1
325 0 }
326  
327 0 ▶sub _decode_data {
Subroutine _decode_data: not called CC=6 SCAR=37.4
328 0 my $any = shift;
329 0 my $encoding = shift;
330 0 ▶ my $enc = $any->_find_encoding($encoding) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $enc = $any->_find_encoding($encoding) or return 0 0 0
331 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
332 0 local ($@, $SIG{__DIE__});
333 0 ▶ eval { defined and $_ = $enc->decode($_, Encode::FB_CROAK()) for @_ };
Branch: 1 branch
BranchTrueFalseTotal
defined $_ and $_ = $enc->decode($_, 1) 0 0 0
334 0 ▶ $any->_or_check_error_after_eval(SSHA_ENCODING_ERROR) or return;
Branch: 1 branch
BranchTrueFalseTotal
$any->_or_check_error_after_eval(7) or return 0 0 0
335 }
336 0 1;
337 }
338  
339 0 ▶sub _encode_args {
Subroutine _encode_args: not called CC=3 SCAR=24.8
340 0 ▶ if (@_ > 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 2) 0 0 0
341 0 my $any = shift;
342 0 my $encoding = shift;
343 0 local $any->{error_prefix} = [@{$any->{error_prefix}}, "argument encoding failed"];
344 0 ▶ if (my $enc = $any->_find_encoding($encoding)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $enc = $any->_find_encoding($encoding)) 0 0 0
345 0 $any->_encode_data($enc, @_);
346 }
347 0 return !$any->{_error};
348 }
349 0 1;
350 }
351  
352 # transparently delegate method calls to backend and os packages:
353 21 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: called CC=2 SCAR=7.0
354 21 our $AUTOLOAD;
355 21 my ($name) = $AUTOLOAD =~ /([^:]*)$/;
356 21 my $sub;
357 4 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
358 21 ▶ if (my ($os_name) = $name =~ /^_os_(.*)/) {
Branch: 1 branch
BranchTrueFalseTotal
if (my($os_name) = $name =~ /^_os_(.*)/) { } 10 11 21
359 51 ▶ $sub = sub {
Subroutine __ANON__: called CC=4 SCAR=14.9
360 51 ▶ my $os = $_[0]->{os_module} //= $_[0]->_load_os or return;
Branch: 1 branch
BranchTrueFalseTotal
my $os = ($_[0]{"os_module"} //= $_[0]->_load_os) or return 51 0 51
Condition66%2/3
$_[0]{"os_module"} //= $_[0]->_load_os
l!l&&r!l&&!r
4830
MC/DC0%0/2
$_[0]{"os_module"} //= $_[0]->_load_os
$_[0]{"os_module"} $_[0]->_load_os
Truth table66%2/3
A //= B
A= $_[0]{"os_module"}B= $_[0]->_load_os
ABresult
1X1
011
000
361 51 ▶ my $method = $os->can($os_name)
Branch: 1 branch
BranchTrueFalseTotal
my $method = $os->can($os_name) or croak("method '${os_name}' not defined in OS '${os}'") 51 0 51
362 or croak "method '$os_name' not defined in OS '$os'";
363 51 goto &$method;
364 10 };
365 }
366 else {
367 12 ▶ $sub = sub {
Subroutine __ANON__: called CC=3 SCAR=11.1
368 12 ▶ my $module = $_[0]->{backend_module} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $module = $_[0]{"backend_module"} or return 9 3 12
369 9 ▶ my $method = $module->can($name)
Branch: 1 branch
BranchTrueFalseTotal
my $method = $module->can($name) or croak("method '${name}' not defined in backend '${module}'") 9 0 9
370 or croak "method '$name' not defined in backend '$module'";
371 9 goto &$method;
372 11 };
373 }
374 21 *{$AUTOLOAD} = $sub;
375 21 goto &$sub;
376 }
377  
378 0 ▶sub DESTROY {
Subroutine DESTROY: not called CC=3 SCAR=24.8
379 0 my $self = shift;
380 0 my $module = $self->{backend_module};
381 0 ▶ if (defined $module) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $module) 0 0 0
382 0 my $sub = $module->can('DESTROY');
383 0 ▶ $sub->($self) if $sub;
Branch: 1 branch
BranchTrueFalseTotal
if $sub 0 0 0
384 }
385 }
386  
387 4 1;
« Any/Test/Backend/Remote.pm ↑ Summary Any/POSIXShellQuoter.pm »