blib/lib/ShellQuote/Any.pm

filter: Statementstmt 97.3% 36 / 37 Branchbran 71.4% 10 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 10 / 10 Podpod 100% 1 / 1 totaltotal 91.9% 57 / 62 CC 8 SCAR 8.0
CC
8
Cov
90%
_q
3.2
shell_quote
3.0
_require
3.0
CRAP 2.2
↑ Summary
1 package ShellQuote::Any;
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 2 our $VERSION = '0.04';
6  
7 2 ▶sub import {
Subroutine import: called CC=1 SCAR=0.0
8 2 my $caller = caller;
9  
10 2 ▶ no strict 'refs'; ## no critic
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 *{"${caller}::shell_quote"} = \&shell_quote;
12 }
13  
14 2 ▶sub shell_quote {
Subroutine shell_quote: called CC=3 SCAR=11.0
Pod documented
15 2 my ($cmd, $os) = @_;
16  
17 2 ▶ if ($os) {
Branch: 1 branch
BranchTrueFalseTotal
if ($os) { } 1 1 2
18 1 _require($os);
19 1 ▶ return _is_win32($os) ? _win32_quote($cmd) : _bourne_quote($cmd);
Branch: 1 branch
BranchTrueFalseTotal
_is_win32($os) ? : 1 0 1
20 }
21 else {
22 1 _q()->($cmd);
23 }
24 }
25  
26 2 my $Q;
27 1 ▶sub _q {
Subroutine _q: called CC=3 SCAR=11.8
28 1 ▶ return $Q if $Q;
Branch: 1 branch
BranchTrueFalseTotal
if $Q 0 1 1
29  
30 1 _require($^O);
31  
32 1 ▶ if ( _is_win32($^O) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_win32($^O)) { } 0 1 1
33 0 $Q = \&_win32_quote;
34 }
35 else {
36 1 $Q = \&_bourne_quote;
37 }
38  
39 1 return $Q;
40 }
41  
42 my %K;
43 2 ▶sub _require {
Subroutine _require: called CC=3 SCAR=11.0
44 2 my ($os) = @_;
45  
46 2 ▶ return $K{$os} if $K{$os};
Branch: 1 branch
BranchTrueFalseTotal
if $K{$os} 0 2 2
47  
48 2 ▶ my $klass = _is_win32($os) ? 'Win32/ShellQuote.pm' : 'String/ShellQuote.pm';
Branch: 1 branch
BranchTrueFalseTotal
_is_win32($os) ? : 1 1 2
49 2 $K{$os} = $klass;
50  
51 2 require "$klass"; ## no critic
52 }
53  
54 1 ▶sub _win32_quote {
Subroutine _win32_quote: called CC=1 SCAR=0.0
55 1 my ($cmd) = @_;
56 1 Win32::ShellQuote::cmd_escape(join ' ', @$cmd);
57 }
58  
59 1 ▶sub _bourne_quote {
Subroutine _bourne_quote: called CC=1 SCAR=0.0
60 1 my ($cmd) = @_;
61 1 String::ShellQuote::shell_quote(@$cmd);
62 }
63  
64 4 ▶sub _is_win32 {
Subroutine _is_win32: called CC=2 SCAR=6.9
65 4 my ($os) = @_;
66  
67 4 ▶ return $os =~ m!^(?:MS)?Win(?:32)?$!i ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$os =~ /^(?:MS)?Win(?:32)?$/i ? : 2 2 4
68 }
69  
70 2 1;
71  
72 __END__
↑ Summary