File Coverage

blib/lib/ShellQuote/Any/Tiny.pm
Criterion Covered Total %
statement 13 17 76.4
branch 3 6 50.0
condition 1 3 33.3
subroutine 3 3 100.0
pod 1 1 100.0
total 21 30 70.0


line stmt bran cond sub pod time code
1             package ShellQuote::Any::Tiny;
2              
3             our $DATE = '2017-09-19'; # DATE
4             our $VERSION = '0.006'; # VERSION
5              
6 1     1   47493 use strict;
  1         3  
  1         31  
7             #use warnings;
8              
9 1     1   5 use Exporter qw(import);
  1         2  
  1         265  
10             our @EXPORT_OK = qw(shell_quote);
11             our $OS;
12              
13             sub shell_quote {
14 10     10 1 58592 my $arg = shift;
15              
16 10   33     64 my $os = $OS || $^O;
17              
18 10 50       33 if ($os eq 'MSWin32') {
19 0 0       0 if ($arg =~ /\A\w+\z/) {
20 0         0 return $arg;
21             }
22             # escape backslash that is followed by a backslash, or the last
23             # backslash
24 0         0 $arg =~ s/(\\(?!.*\\)|\\(?=\\)|")/\\$1/g;
25 0         0 return qq("$arg");
26             } else {
27 10 100       56 if ($arg =~ /\A\w+\z/) {
28 1         8 return $arg;
29             }
30 9         24 $arg =~ s/'/'"'"'/g;
31 9         36 return "'$arg'";
32             }
33             }
34              
35             1;
36             # ABSTRACT: Escape string for the Unix/Windows shell
37              
38             __END__