Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages

  
 
  

home | help
Commandable::InvocatioUser Contributed Perl DocumentCommandable::Invocation(3)

NAME
       "Commandable::Invocation" - represents one invocation of	a CLI command

SYNOPSIS
	  my %commands = (
	     exit  => sub { exit },
	     print => sub { print $_[0]->peek_remaining	},
	     ...
	  );

	  while(1) {
	     my	$inv = Commmandable::Invocation->new( scalar <STDIN> );

	     $commands{	$inv->pull_token }->( $inv );
	  }

DESCRIPTION
       Instances of this class represent the text of a single invocation of a
       CLI command, allowing it	to be incrementally parsed and broken into
       individual tokens during	dispatch and invocation.

   Tokens
       When parsing for	the next token,	strings	quoted using quote marks ("")
       will be retained	as a single token. Otherwise, tokens are split on
       (non-preserved) whitespace.

       Quote marks and backslashes may be escaped using	"\" characters.

CONSTRUCTOR
   new
	  $inv = Commandable::Invocation->new( $text )

       Constructs a new	instance, initialised to contain the given text
       string.

   new_from_tokens
	  $inv = Commandable::Invocation->new_from_tokens( @tokens )

       Since version 0.03.

       Constructs a new	instance, initialised to contain text from the given
       tokens, such that subsequent calls to "pull_token" will yield the given
       list of tokens. This may	be handy for constructing instances from @ARGV
       or similar cases	where text has already been parsed and split into
       tokens.

METHODS
   peek_token
	  $token = $inv->peek_token

       Looks at, but does not remove, the next token in	the text string.
       Subsequent calls	to this	method will yield the same string, as will the
       next call to "pull_token".

   pull_token
	  $token = $inv->pull_token

       Removes the next	token from the text string and returns it.

   peek_remaining
	  $text	= $inv->peek_remaining

       Since version 0.04.

       Returns the entire unparsed content of the rest of the text string.

   putback_tokens
	  $inv->putback_tokens(	@tokens	)

       Since version 0.02.

       Prepends	text back onto the stored text string such that	subsequent
       calls to	"pull_token" will yield	the given list of tokens once more.
       This takes care to quote	tokens with spaces inside, and escape any
       embedded	backslashes or quote marks.

       This method is intended to be used, for example,	around a commandline
       option parser which handles mixed options and arguments,	to put back
       the non-option positional arguments after the options have been parsed
       and removed from	it.

AUTHOR
       Paul Evans <leonerd@leonerd.org.uk>

perl v5.32.1			  2021-02-28	    Commandable::Invocation(3)

NAME | SYNOPSIS | DESCRIPTION | CONSTRUCTOR | METHODS | AUTHOR

Want to link to this manual page? Use this URL:
<https://www.freebsd.org/cgi/man.cgi?query=Commandable::Invocation&sektion=3&manpath=FreeBSD+13.0-RELEASE+and+Ports>

home | help