| 1 | package Net::OpenSSH::ShellQuoter::Chain; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | |||
| 6 | use Net::OpenSSH::ShellQuoter; | ||
| 7 | |||
| 8 | sub chain { | ||
| 9 | my $class = shift; | ||
| 10 | my @quoters = map Net::OpenSSH::ShellQuoter->quoter($_), reverse @_; | ||
| 11 | my $self = \@quoters; | ||
| 12 | bless $self, $class; | ||
| 13 | $self; | ||
| 14 | } | ||
| 15 | |||
| 16 | sub quote { | ||
| 17 | my ($self, $arg) = @_; | ||
| 18 | $arg = $_->quote($arg) for @$self; | ||
| 19 | $arg; | ||
| 20 | } | ||
| 21 | |||
| 22 | sub quote_glob { | ||
| 23 | my ($self, $arg) = @_; | ||
| 24 | if (@$self) { | ||
| 25 | $arg = $self->[0]->quote_glob($arg); | ||
| 26 | $arg = $self->[$_]->quote($arg) for 1..$#$self; | ||
| 27 | } | ||
| 28 | $arg | ||
| 29 | } | ||
| 30 | |||
| 31 | sub shell_fragments { | ||
| 32 | my $self = shift; | ||
| 33 | @$self or return (wantarray ? () : ''); | ||
| 34 | $self->[-1]->shell_fragments(@_) | ||
| 35 | } | ||
| 36 | |||
| 37 | |||
| 38 | 1; |