GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Commandable::Invocation(3) User Contributed Perl Documentation Commandable::Invocation(3)

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

   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 );
   }

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.

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.

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

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

   $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.

   $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".

   $token = $inv->pull_token

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

   $text = $inv->peek_remaining

Since version 0.04.

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

   $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.

Paul Evans <leonerd@leonerd.org.uk>
2022-04-07 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.