File Coverage

blib/lib/ShellQuote/Any.pm
Criterion Covered Total %
statement 33 34 97.0
branch 10 14 71.4
condition n/a
subroutine 10 10 100.0
pod 1 1 100.0
total 54 59 91.5


line stmt bran cond sub pod time code
1             package ShellQuote::Any;
2 2     2   26392 use strict;
  2         2  
  2         46  
3 2     2   6 use warnings;
  2         2  
  2         79  
4              
5             our $VERSION = '0.03';
6              
7             sub import {
8 2     2   13 my $caller = caller;
9              
10 2     2   8 no strict 'refs'; ## no critic
  2         4  
  2         639  
11 2         3 *{"${caller}::shell_quote"} = \&shell_quote;
  2         1017  
12             }
13              
14             sub shell_quote {
15 2     2 1 436 my ($cmd, $os) = @_;
16              
17 2 100       5 if ($os) {
18 1         3 _require($os);
19 1 50       1293 return _is_win32($os) ? _win32_quote($cmd) : _bourne_quote($cmd);
20             }
21             else {
22 1         2 _q()->($cmd);
23             }
24             }
25              
26             my $Q;
27             sub _q {
28 1 50   1   2 return $Q if $Q;
29              
30 1         3 _require($^O);
31              
32 1 50       595 if ( _is_win32($^O) ) {
33 0         0 $Q = \&_win32_quote;
34             }
35             else {
36 1         3 $Q = \&_bourne_quote;
37             }
38              
39 1         2 return $Q;
40             }
41              
42             my %K;
43             sub _require {
44 2     2   3 my ($os) = @_;
45              
46 2 50       5 return $K{$os} if $K{$os};
47              
48 2 100       3 my $klass = _is_win32($os) ? 'Win32/ShellQuote.pm' : 'String/ShellQuote.pm';
49 2         3 $K{$os} = $klass;
50              
51 2         817 require "$klass"; ## no critic
52             }
53              
54             sub _win32_quote {
55 1     1   3 my ($cmd) = @_;
56 1         6 Win32::ShellQuote::cmd_escape(join ' ', @$cmd);
57             }
58              
59             sub _bourne_quote {
60 1     1   1 my ($cmd) = @_;
61 1         3 String::ShellQuote::shell_quote(@$cmd);
62             }
63              
64             sub _is_win32 {
65 4     4   6 my ($os) = @_;
66              
67 4 100       24 return $os =~ m!^(?:MS)?Win(?:32)?$!i ? 1 : 0;
68             }
69              
70             1;
71              
72             __END__