MySimple.pod 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. =head1 NAME
  2. C<Getopt::MySimple> - Provide a simple wrapper around Getopt::Long.
  3. =head NOTE
  4. Based on GetOpt::Simple, with some (here undocumented) modifications
  5. to fit texi2hml needs.
  6. =head1 SYNOPSIS
  7. use Getopt::MySimple;
  8. # Or ...
  9. # use Getopt::MySimple qw($opt);
  10. my($options) =
  11. {
  12. 'help' =>
  13. {
  14. 'type' => '',
  15. 'default' => '',
  16. # 'verbose' => '', # Not needed on every key.
  17. },
  18. 'username' =>
  19. {
  20. 'type' => '=s', # As per Getopt::Long.
  21. 'default' => $ENV{'USER'} || 'RonSavage', # In case $USER is undef.
  22. 'verbose' => 'Specify the username on the remote machine',
  23. },
  24. 'password' =>
  25. {
  26. 'type' => '=s',
  27. 'default' => 'password',
  28. 'verbose' => 'Specify the password on the remote machine',
  29. },
  30. };
  31. my($option) = new Getopt::MySimple;
  32. if (! $option -> getOptions($options, "Usage: testMySimple.pl [options]") )
  33. {
  34. exit(-1); # Failure.
  35. }
  36. print "username: $option->{'opt'}{'username'}. \n";
  37. print "password: $option->{'opt'}{'password'}. \n";
  38. # Or, after 'use Getopt::MySimple qw($opt);' ...
  39. # print "username: $opt->{'username'}. \n";
  40. # print "password: $opt->{'password'}. \n";
  41. =head1 DESCRIPTION
  42. The C<Getopt::MySimple> module provides a simple way of specifying:
  43. =over 4
  44. =item *
  45. Command line options
  46. =item *
  47. Type information for option values
  48. =item *
  49. Default values for the options
  50. =item *
  51. Help text per option
  52. =back
  53. =head1 The C<getOptions()> function
  54. The C<getOptions()> function takes 4 parameters:
  55. =over 4
  56. =item *
  57. A hash defining the command line options
  58. =item *
  59. A string to display as a help text heading
  60. =item *
  61. A Boolean. 0 = (Default) Use case-sensitive option names. 1 = Ignore case
  62. =item *
  63. A Boolean. 0 = Return after displaying help. 1 = (Default) Terminate with exit(0)
  64. after displaying help
  65. =back
  66. =head1 The $classRef -> {'opt'} hash reference
  67. Command line option values are accessed in your code by dereferencing
  68. the hash reference $classRef -> {'opt'}. Two examples are given above,
  69. under synopsis.
  70. Alternately, you can use the hash reference $opt. See below.
  71. =head1 The $opt hash reference
  72. Command line option values are accessed in your code by dereferencing
  73. the hash reference $opt. Two examples are given above,
  74. under synopsis.
  75. Alternately, you can use the hash reference $classRef -> {'opt'}. See above.
  76. =head1 The C<dumpOptions()> function
  77. C<dumpOptions()> prints all your option's keys and their current values.
  78. =head1 The C<helpOptions()> function
  79. C<helpOptions()> prints nicely formatted help text.
  80. =head1 WARNING re Perl bug
  81. As always, be aware that these 2 lines mean the same thing, sometimes:
  82. =over 4
  83. =item *
  84. $self -> {'thing'}
  85. =item *
  86. $self->{'thing'}
  87. =back
  88. The problem is the spaces around the ->. Inside double quotes, "...", the
  89. first space stops the dereference taking place. Outside double quotes the
  90. scanner correctly associates the $self token with the {'thing'} token.
  91. I regard this as a bug.
  92. =head1 REQUIRED MODULES
  93. =over 4
  94. =item *
  95. Exporter
  96. =item *
  97. Getopt::Long
  98. =back
  99. =head1 RETURN VALUES
  100. =over 4
  101. =item *
  102. C<dumpOptions()> returns nothing
  103. =item *
  104. C<helpOptions()> returns nothing
  105. =item *
  106. C<getOptions()> returns 0 for failure and 1 for success
  107. =back
  108. =head1 AUTHOR
  109. C<Getopt::MySimple> was written by Ron Savage I<E<lt>rpsavage@ozemail.com.auE<gt>> in 1997.
  110. Modifications for texi2html by Olaf Bachmann
  111. I<E<lt>obachman@mathtematik.uni-kl.deE<gt>> in 2000.
  112. =head1 LICENCE
  113. This program is free software; you can redistribute it and/or modify it under
  114. the same terms as Perl itself.