From: Dietmar Maurer Date: Tue, 25 Oct 2011 11:08:09 +0000 (+0200) Subject: use Text::ParseWords for split_args X-Git-Url: https://git.proxmox.com/?p=pve-common.git;a=commitdiff_plain;h=e38bcd35974e03b8056daf3e7ce6c5f230b8da5d;ds=sidebyside use Text::ParseWords for split_args --- diff --git a/data/PVE/Tools.pm b/data/PVE/Tools.pm index 5cd8460..1daf1a2 100644 --- a/data/PVE/Tools.pm +++ b/data/PVE/Tools.pm @@ -13,6 +13,7 @@ use base 'Exporter'; use URI::Escape; use Encode; use Digest::SHA1; +use Text::ParseWords; our @EXPORT_OK = qw( lock_file @@ -709,30 +710,11 @@ sub shellquote { return $str; } -# a clumsy way to split an shell argument string into an array, -# we simply pass it to the cli (exec call) -# fixme: use Text::ParseWords::shellwords() ? +# split an shell argument string into an array, sub split_args { my ($str) = @_; - my $args = []; - - return $args if !$str; - - my $cmd = 'perl -e \'foreach my $a (@ARGV) { print "$a\n"; } \' -- ' . $str; - - eval { - run_command($cmd, outfunc => sub { - my $data = shift; - push @$args, $data; - }); - }; - - my $err = $@; - - die "unable to parse args: $str\n" if $err; - - return $args; + return $str ? [ Text::ParseWords::shellwords($str) ] : []; } 1;