| 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
| |||||||||||
| 18 | 1 | _require($os); | |||||||||
| 19 | 1 | ▶ | return _is_win32($os) ? _win32_quote($cmd) : _bourne_quote($cmd); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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
| |||||||||||
| 29 | |||||||||||
| 30 | 1 | _require($^O); | |||||||||
| 31 | |||||||||||
| 32 | 1 | ▶ | if ( _is_win32($^O) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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
| |||||||||||
| 47 | |||||||||||
| 48 | 2 | ▶ | my $klass = _is_win32($os) ? 'Win32/ShellQuote.pm' : 'String/ShellQuote.pm'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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
| |||||||||||
| 68 | } | ||||||||||
| 69 | |||||||||||
| 70 | 2 | 1; | |||||||||
| 71 | |||||||||||
| 72 | __END__ | ||||||||||