This file is indexed.

/usr/share/perl5/Getopt/Simple.pm is in libgetopt-simple-perl 1.52-5.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
package Getopt::Simple;

# Name:
#	Getopt::Simple.
#
# Documentation:
#	POD-style documentation is at the end. Extract it with pod2html.*.
#
# Tabs:
#	4 spaces || die.
#
# Author:
#	Ron Savage <ron@savage.net.au>
#	Home page: http://savage.net.au/index.html
#
# Licence:
#	Australian copyright (c) 1999-2002 Ron Savage.
#
#	All Programs of mine are 'OSI Certified Open Source Software';
#	you can redistribute them and/or modify them under the terms of
#	The Artistic License, a copy of which is available at:
#	http://www.opensource.org/licenses/index.html

use strict;
no strict 'refs';
use vars qw($fieldWidth $switch @ISA @EXPORT @EXPORT_OK);

use Getopt::Long;

require Exporter;

@ISA = qw(Exporter);

# Items to export into callers namespace by default. Note: do not export
# names by default without a very good reason. Use EXPORT_OK instead.
# Do not simply export all your public functions/methods/constants.

@EXPORT      = qw();

@EXPORT_OK   = qw($switch);	# An alias for $$self{'switch'}.

$fieldWidth  = 25;

our $VERSION = '1.52';

# Preloaded methods go here.
# --------------------------------------------------------------------------

sub byOrder
{
	my($self) = @_;

	$$self{'default'}{$a}{'order'} <=> $$self{'default'}{$b}{'order'};
}

# --------------------------------------------------------------------------

sub dumpOptions
{
	my($self) = @_;

	print $self -> pad('Option'), "Value\n";

	for (sort byOrder keys(%{$$self{'switch'} }) )
	{
		if (ref($$self{'switch'}{$_}) eq 'ARRAY')
		{
			print $self -> pad("-$_"), '(', join(', ', @{$$self{'switch'}{$_} }), ")\n";
		}
		else
		{
			print $self -> pad("-$_"), "$$self{'switch'}{$_}\n";
		}
	}

	print "\n";

}	# End of dumpOptions.

# --------------------------------------------------------------------------
# Return:
#	0 -> Error.
#	1 -> Ok.

sub getOptions
{
	push(@_, 0) if ($#_ == 2);	# Default for $ignoreCase is 0.
	push(@_, 1) if ($#_ == 3);	# Default for $helpThenExit is 1.

	my($self, $default, $helpText, $ignoreCase, $helpThenExit) = @_;

	$$self{'default'}	= $default;
	$$self{'helpText'}	= $helpText;

	Getopt::Long::Configure($ignoreCase ? 'ignore_case' : 'no_ignore_case');

	for (keys(%{$$self{'default'} }) )
	{
		push(@{$$self{'type'} }, "$_$$self{'default'}{$_}{'type'}");
	}

	my($result) = GetOptions($$self{'switch'}, @{$$self{'type'} });

	if ($$self{'switch'}{'help'})
	{
		$self -> helpOptions();
		exit(0) if ($helpThenExit);
	}

	for (keys(%{$$self{'default'} }) )
	{
		if (ref($$self{'switch'}{$_}) eq 'ARRAY')
		{
			$$self{'switch'}{$_} = [split(/\s+/, $$self{'default'}{$_}{'default'})] if (! defined $$self{'switch'}{$_});
		}
		else
		{
			$$self{'switch'}{$_} = $$self{'default'}{$_}{'default'} if (! defined $$self{'switch'}{$_});
		}
	}

	$result;

}	# End of getOptions.

# --------------------------------------------------------------------------

sub helpOptions
{
	my($self) = @_;

	print "$$self{'helpText'}\n" if ($$self{'helpText'});

	print $self -> pad('Option'), $self -> pad('Environment var'), "Default\n";

	for (sort byOrder keys(%{$$self{'default'} }) )
	{
		print $self -> pad("-$_"), $self -> pad("$$self{'default'}{$_}{'env'}");

		if (ref($$self{'default'}{$_}{'default'}) eq 'ARRAY')
		{
			print '(', join(', ', @{$$self{'default'}{$_}{'default'} }), ")\n";
		}
		else
		{
			print "$$self{'default'}{$_}{'default'}\n";
		}

		print "\t$$self{'default'}{$_}{'verbose'}\n"
			if (defined($$self{'default'}{$_}{'verbose'}) &&
				$$self {'default'}{$_}{'verbose'} ne '');
	}

	print "\n";

}	# End of helpOptions.

#-------------------------------------------------------------------

sub new
{
	my($class)			= @_;
	$class				= ref($class) || $class;
	my($self)			= {};
	$$self{'default'}	= {};
	$$self{'helpText'}	= '';
	$$self{'switch'}	= {};
	$switch				= $$self{'switch'};	 # An alias for $$self{'switch'}.
	$$self{'type'}		= [];

	return bless $self, $class;

}	# End of new.

# --------------------------------------------------------------------------

sub pad
{
	my($self, $field) = @_;

	sprintf "%-${fieldWidth}s", $field;

}	# End of pad.
# --------------------------------------------------------------------------

# Autoload methods go after =cut, and are processed by the autosplit program.

1;

__END__

=head1 NAME

C<Getopt::Simple> - Provide a simple wrapper around Getopt::Long.

=head1 SYNOPSIS

	use Getopt::Simple;

	# Or ...
	# use Getopt::Simple qw($switch);

	my($options) =
	{
	help =>
		{
		type    => '',
		env     => '-',
		default => '',
#		verbose => '',      # Not needed on every key.
		order   => 1,
		},
	username =>
		{
		type    => '=s',    # As per Getopt::Long.
		env     => '$USER', # Help text.
		default => $ENV{'USER'} || 'RonSavage', # In case $USER is undef.
		verbose => 'Specify the username on the remote machine',
		order   => 3,       # Help text sort order.
		},
	password =>
		{
		type    => '=s',
		env     => '-',
		default => 'password',
		verbose => 'Specify the password on the remote machine',
		order   => 4,
		},
	};

	my($option) = Getopt::Simple -> new();

	if (! $option -> getOptions($options, "Usage: testSimple.pl [options]") )
	{
		exit(-1);	# Failure.
	}

	print "username: $$option{'switch'}{'username'}. \n";
	print "password: $$option{'switch'}{'password'}. \n";

	# Or, after 'use Getopt::Simple qw($switch);' ...
	# print "username: $$switch{'username'}. \n";
	# print "password: $$switch{'password'}. \n";

=head1 DESCRIPTION

C<Getopt::Simple> is a pure Perl module.

The C<Getopt::Simple> module provides a simple way of specifying:

=over 4

=item *

Command line switches

=item *

Type information for switch values

=item *

Default values for the switches

=item *

Help text per switch

=back

=head1 Distributions

This module is available both as a Unix-style distro (*.tgz) and an
ActiveState-style distro (*.ppd). The latter is shipped in a *.zip file.

See http://savage.net.au/Perl-modules.html for details.

See http://savage.net.au/Perl-modules/html/installing-a-module.html for
help on unpacking and installing each type of distro.

=head1 Constructor and initialization

new(...) returns a C<Getopt::Simple> object.

This is the class's contructor.

Usage: Getopt::Simple -> new().

This method does not take any parameters.

=head1 The C<dumpOptions()> function

C<dumpOptions()> prints all your option's keys and their current values.

C<dumpOptions()> does not return anything.

=head1 The C<getOptions()> function

The C<getOptions()> function takes 4 parameters:

=over 4

=item *

A hash ref defining the command line switches

The structure of this hash ref is defined in the next section.

This parameter is mandatory.

=item *

A string to display as a help text heading

This parameter is mandatory.

=item *

A Boolean. 0 = (Default) Use case-sensitive switch names. 1 = Ignore case

This parameter is optional.

=item *

A Boolean. 0 = Return after displaying help. 1 = (Default) Terminate with exit(0)
after displaying help

This parameter is optional.

=back

C<getOptions()> returns 0 for failure and 1 for success.

=head1 The hash ref of command line switches

=over 4

=item *

Each key in the hash ref is the name of a command line switch

=item *

Each key points to a hash ref which defines the nature of that command line switch

The keys and values of this nested hash ref are as follows.

=over 4

=item *

default => 'Some value'

This key, value pair is mandatory.

This is the default value for this switch.

Examples:

	default => '/users/home/dir'
	default => $ENV{'REMOTEHOST'} || '127.0.0.1'

=item *

env => '-' || 'Some short help text'

This key, value pair is mandatory.

This is help test, to indicate that the calling program can use an environment
variable to set the default value of this switch.

Use '-' to indicate that no environment variable is used.

Examples:

	env => '-'
	env => '$REMOTEHOST'

Note the use of ' to indicate we want the $ to appear in the output.

=item *

type => 'Types as per Getopt::Long'

This key, value pair is mandatory.

This is the type of the command line switch, as defined by Getopt::Long.

Examples:

	type => '=s'
	type => '=s@',

=item *

verbose => 'Some long help text'

This key, value pair is optional.

This is long, explanatory help text which is displayed below the help containing
the three columns of text: switch name, env value, default value.

Examples:

	verbose => 'Specify the username on the remote machine',
	verbose => 'Specify the home directory on the remote machine'

=item *

order => \d+

This key, value pair is mandatory.

This is the sort order used to force the help text to display the switches in
a specific order down the page.

Examples:

	order => 1
	order => 9

=back

=back

=head1 The C<helpOptions()> function

C<helpOptions()> prints nicely formatted help text.

C<helpOptions()> does not return anything.

=head1 The $$classRef{'switch'} hash reference

Command line option values are accessed in your code by dereferencing
the hash reference $$classRef{'switch'}. Two examples are given above,
under synopsis.

Alternately, you can use the hash reference $switch. See below.

=head1 The $switch hash reference

Command line option values are accessed in your code by dereferencing
the hash reference $switch. Two examples are given above,
under synopsis.

Alternately, you can use the hash reference $$classRef{'switch'}. See above.

=head1 WARNING re Perl bug

As always, be aware that these 2 lines mean the same thing, sometimes:

=over 4

=item *

$self -> {'thing'}

=item *

$self->{'thing'}

=back

The problem is the spaces around the ->. Inside double quotes, "...", the
first space stops the dereference taking place. Outside double quotes the
scanner correctly associates the $self token with the {'thing'} token.

I regard this as a bug.

=head1 AUTHOR

C<Getopt::Simple> was written by Ron Savage I<E<lt>ron@savage.net.auE<gt>> in 1997.

=head1 LICENCE

Australian copyright (c) 1997-2002 Ron Savage.

	All Programs of mine are 'OSI Certified Open Source Software';
	you can redistribute them and/or modify them under the terms of
	The Artistic License, a copy of which is available at:
	http://www.opensource.org/licenses/index.html