OpenSSH/ShellQuoter/fish.pm untested

filter: Statementstmt 0.0% 0 / 38 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 71 CC 10 SCAR 35.8
CC
10
Cov
0%
quote_glob
72.0
quote
6.0
shell_fragments
6.0
CRAP 35.9
1 package Net::OpenSSH::ShellQuoter::fish;
2  
3 use strict;
4 use warnings;
5 use Carp;
6  
7 sub new { __PACKAGE__ }
8  
9 my $noquote_class = '.\\w/\\-@,:';
10 my $glob_class = '*?\\[\\],\\{\\}:!^~';
11  
12 sub quote {
13 my $quoted = $_[1];
14 return $quoted if $quoted =~ /\A[$noquote_class]+\z/o;
15 $quoted =~ s/([\'\\])/\\$1/g;
16 "'$quoted'"
17 }
18  
19 sub quote_glob {
20 shift;
21 my $arg = shift;
22 my @parts;
23 while ((pos $arg || 0) < length $arg) {
24 if ($arg =~ m|\G('+)|gc) {
25 push @parts, (length($1) > 1 ? "\"$1\"" : "\\'");
26 }
27 elsif ($arg =~ m|\G([$noquote_class$glob_class]+)|gco) {
28 push @parts, $1;
29 }
30 elsif ($arg =~ m|\G(\\[$glob_class\\])|gco) {
31 push @parts, $1;
32 }
33 elsif ($arg =~ m|\G\\|gc) {
34 push @parts, '\\\\'
35 }
36 elsif ($arg =~ m|\G([^$glob_class\\']+)|gco) {
37 push @parts, "'$1'";
38 }
39 else {
40 require Data::Dumper;
41 $arg =~ m|\G(.+)|gc;
42 die "Internal error: unquotable string:\n". Data::Dumper::Dumper($1) ."\n";
43 }
44 }
45 my $quoted = join('', @parts);
46 length $quoted ? $quoted : "''";
47 }
48  
49 my %fragments = ( stdin_discard => '</dev/null',
50 stdout_discard => '>/dev/null',
51 stderr_discard => '2>/dev/null',
52 stdout_and_stderr_discard => '>/dev/null 2>&1',
53 stderr_to_stdout => '2>&1' );
54  
55 sub shell_fragments {
56 shift;
57 my @f = grep defined, @fragments{@_};
58 wantarray ? @f : join(' ', @f);
59 }
60  
61 1;