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::PrettyPipe::Arg - An argument to an IPC::PrettyPipe::Cmd command

SYNOPSIS

  use IPC::PrettyPipe::Arg;

  # standard constructor
  $arg = IPC::PrettyPipe::Arg->new( name  => $name,
                                    value => $value, %attr );

  # concise constructors
  $arg = IPC::PrettyPipe::Arg->new( $name );
  $arg = IPC::PrettyPipe::Arg->new( [ $name, $value ] );

  # perform value substitution
  $arg->valsubst( $pattern, $rep );

  # return a rendered argument
  $arg->render;

DESCRIPTION

IPC::PrettyPipe::Arg objects are containers for arguments to commands in an IPC::PrettyPipe::Cmd object.

METHODS

new
  # named parameters; may provide additional attributes
  $arg = IPC::PrettyPipe::Arg->new( \%attr );

  # concise interface
  $arg = IPC::PrettyPipe::Arg->new( $name );             # switch arg
  $arg = IPC::PrettyPipe::Arg->new( [ $name, $value ] ); # arg w/ value

The available attributes are:

name

Required. The name of the argument.

value

The value of the argument. If an argument is a switch, no value is required.

pfx

A string prefix to be applied to the argument name before being rendered. This is often - or --.

A prefix is not required (the argument name may already have it). This attribute is useful when creating arguments from hashes where the keys do not contain a prefix.

sep

A string to insert between the argument name and value when rendering. In some cases arguments must be a single string where the name and value are separated with an = character; in other cases they are treated as separate entities. If sep is undef it indicates that they are treated as separate entitites. It defaults to undef.

pfx
  $current_value = $self->pfx;
  $self->pfx( $new_value );

Get or set the value of the pfx attribute.

sep
  $current_value = $self->sep;
  $self->sep( $new_value );

Get or set the value of the sep attribute.

has_blank_value
  $bool = $self->has_blank_value

Returns true if the value is the empty string.

render
  @rendered_arg = $arg->render;

Render the argument. If the argument's sep attribute is defined, render returns a string which looks like:

  $pfx . $name . $sep . $value

If sep is not defined, it returns an array ref which looks like

  $pfx . $name, $value
valmatch
  $bool = $arg->valmatch( $pattern );

Returns true if the argument has a value and it matches the passed regular expression.

valsubst
  $arg->valsubst( $pattern, $rep );

If the argument has a value, perform the equivalent to

  $value =~ s/$pattern/$rep/;

COPYRIGHT & LICENSE

Copyright 2014 Smithsonian Astrophysical Observatory

This software is released under the GNU General Public License. You may find a copy at

   http://www.fsf.org/copyleft/gpl.html

AUTHOR

Diab Jerius <djerius@cfa.harvard.edu>