NAME ^

library/Getopt/Long.pir - parse long and short command line options

SYNOPSIS ^

  # get the relevant sub
  load_bytecode "Getopt/Long.pbc"
  .local pmc get_options
  find_global get_options, "Getopt::Long", "get_options" 

  # Assemble option specification
  .local pmc opt_spec
  opt_spec = new ResizableStringArray
  push opt_spec, "bool"
  push opt_spec, "string=s"
  push opt_spec, "integer=i"

  # the program name is the first element in argv
  .local string program_name
  program_name = shift argv

  # Make a copy of argv, because this can easier be handled in get_options()
  .local pmc argv_clone
  argv_clone = clone argv

  # Parse the command line params
  .local pmc opt
  ( opt ) = get_options( argv_clone, opt_spec )

  .local int is_defined
  is_defined = defined opt["bool"]

  .local int integer
  integer = opt["integer"]

  .local string s
  s = opt["string"]

DESCRIPTION ^

This Parrot library can be used for parsing command line options. The subroutine get_options() is exported into the namespace 'Getopt::Long'.

SUBROUTINES ^

get_options in Getopt::Long ^

This should work like the Perl5 module Getopt::Long. Takes an array of options and an array of specifications.

A Hash PMC is returned.

TODO ^

- Remove need to clone argument vector - Make it work for all cases, short options, long options and bundling. - Recognise type of return value: string, integer, binary, array, hash. - Get started on error reporting. - Provide more options

AUTHOR ^

Bernhard Schmalhofer - Bernhard.Schmalhofer@gmx.de

SEE ALSO ^

The Perl5 module Getopt::Long. examples/library/getopt_demo.pir

COPYRIGHT ^

Copyright (C) 2003-2005 The Perl Foundation. All rights reserved. This program is free software. It is subject to the same license as The Parrot Interpreter.


parrot