1package Net::OpenSSH::ShellQuoter::csh; 2 3use strict; 4use warnings; 5use Carp; 6 7# Fixme: copied from POSIX 8 9sub new { __PACKAGE__ } 10 11my $noquote_class = q(.\\w/\\-@,:); 12my $glob_class = q(*?\\[\\],{}:!^~); 13my $escape_inside_single_quotes_class = q(\!\n); 14 15sub _single_quote { 16 my $arg = shift; 17 $arg =~ s/([$escape_inside_single_quotes_class])/\\$1/go; 18 "'$arg'" 19} 20 21sub quote { 22 shift; 23 my $quoted = join '', 24 map { ( m|\A'\z| ? "\\'" : 25 m|\A'| ? "\"$_\"" : 26 m|\A[$noquote_class]*\z|o ? $_ : 27 _single_quote($_) ) 28 } split /(')/o, $_[0]; 29 length $quoted ? $quoted : "''"; 30} 31 32 33sub quote_glob { 34 shift; 35 my $arg = shift; 36 my @parts; 37 while ((pos $arg ||0) < length $arg) { 38 if ($arg =~ m|\G('+)|gc) { 39 push @parts, (length($1) > 1 ? "\"$1\"" : "\\'"); 40 } 41 elsif ($arg =~ m|\G([$noquote_class$glob_class]+)|gco) { 42 push @parts, $1; 43 } 44 elsif ($arg =~ m|\G(\\[$glob_class\\])|gco) { 45 push @parts, $1; 46 } 47 elsif ($arg =~ m|\G([^$glob_class\\']+)|gco) { 48 push @parts, _single_quote($1); 49 } 50 else { 51 require Data::Dumper; 52 $arg =~ m|\G(.+)|gc; 53 die "Internal error: unquotable string:\n". Data::Dumper::Dumper($1) ."\n"; 54 } 55 } 56 my $quoted = join('', @parts); 57 length $quoted ? $quoted : "''"; 58} 59 60my %fragments = ( stdin_discard => '</dev/null', 61 stdout_discard => '>/dev/null', 62 stdout_and_stderr_discard => '>&/dev/null' ); 63 64sub shell_fragments { 65 shift; 66 my @f = grep defined, @fragments{@_}; 67 wantarray ? @f : join(' ', @f); 68} 69 701; 71