The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

Name

IPC::Run3::Shell::CLIWrapper - Perl extension for wrapping arbitrary command-line tools

Synopsis

use IPC::Run3::Shell::CLIWrapper;

my $git = IPC::Run3::Shell::CLIWrapper->new({chomp=>1}, 'git');
my @log = $git->log('--oneline');

my $perl = IPC::Run3::Shell::CLIWrapper
    ->new( { opt_char=>'-' }, 'perl' );
my $foo = $perl->( [ l => undef, e => q{ print for @ARGV } ],
    '--', 'Hello', 'World!' );

use JSON::PP qw/decode_json/;
my $s3api = IPC::Run3::Shell::CLIWrapper->new( { fail_on_stderr => 1,
    stdout_filter => sub { $_=decode_json($_) } },
    qw/ aws --profile MyProfile --output json s3api /);
my $buckets = $s3api->list_buckets;

Description

This module wraps IPC::Run3::Shell in a layer that translates method calls and their arguments to the command-line arguments of system commands.

new

The arguments to the constructor are the same as to "make_cmd" in IPC::Run3::Shell, with the addition of the following options, which can be placed in hashref(s) at the beginning of the argument list:

opt_char

The string to prefix to option names, defaults to "--". Other common values are "-" and perhaps "/" on Windows.

val_sep

The separator between an option name and its value; if set to undef (the default), then the name and value are two separate items in the argument list.

under2dash

Boolean to enable or disable the conversion of underscores to dashes in option names and method names. Option values and plain strings remain unchanged. Default is true.

Argument Lists

The name of the method is the first item in the generated argument list. You may also call the object of this class as a code reference, which behaves exactly the same as a method call except no method name is added as the first item of the argument list. This can be useful if you want to start with options, or you want to call commands that have the same names as the methods of this class (new, AUTOLOAD, and DESTROY) or the built-ins of the UNIVERSAL class, such as can.

The arguments to the method call (or code reference) are translated as follows:

Array references

These must have an even number of items, and every two items represent a pair of an option name and its value. If the value is undef, it is omitted from the generated argument list. See also the options described in "new".

Other values (strings, hash references, etc.)

Act the same as arguments to IPC::Run3::Shell. This means that hash references can be passed as the last item(s) in the list to set options.

Author, Copyright, and License

Copyright (c) 2020 Hauke Daempfling (haukex@zero-g.net).

This library is free software; you can redistribute it and/or modify it under the same terms as Perl 5 itself.

For more information see the Perl Artistic License, which should have been distributed with your copy of Perl. Try the command "perldoc perlartistic" or see http://perldoc.perl.org/perlartistic.html.