Getopt-Simple-1.52000755001750001750 011434663766 12731 5ustar00ronron000000000000Getopt-Simple-1.52/Build.PL000444001750001750 114511434663766 14363 0ustar00ronron000000000000use Module::Build; my $class = Module::Build->subclass(code => <<'EOF'); sub find_test_files { my $self = shift; my $files = $self->SUPER::find_test_files(@_); return [ grep {!/test\.pl$/} @$files ]; } sub ACTION_test { my $self = shift; $self->SUPER::ACTION_test(@_); $self->run_perl_script('test.pl', ['-Mblib='.$self->blib]); } EOF $class -> new ( module_name => 'Getopt::Simple', license => 'artistic', dist_author => 'Ron Savage ', build_requires => { Test::More => 0, Test::Pod => 0, }, requires => { Getopt::Long => 0, }, ) -> create_build_script(); Getopt-Simple-1.52/CHANGES000444001750001750 414211434663766 14062 0ustar00ronron000000000000Revision history for Perl extension Getopt::Simple. 1.52 Sun Feb 21 12:55:13 2010 - Remove text 'All rights reserved' (for Debian licensing). - Remove POD heads 'Required Modules' and 'Changes'. 1.51 Wed Feb 10 14:02:06 2010 - MANIFEST.SKIP updated to exclude MYMETA.yml. Add MYMETA.yml. 1.50 Fri Nov 13 13:20:00 2009 - Run dos2unix - Rename Changes.txt to CHANGES 1.49 Sat Mar 22 11:31:00 2008 - Patch from JJARVINEN for RT#33299 so that an option value of zero overrides the default 1.48 Sun Nov 07 14:30:00 2004 - Add sub pad() to simplify printing of fixed width fields. Original patch: Ricardo Signes. Since this is the only change, there is no need to upgrade 1.47 Tue Jul 20 20:43:00 2004 - Change Makefile.PL to coexist with Module::Build - Document parameters properly - Test against Getopt::Long V 2.34 - Add t/pod.t to test all PODs 1.46 Sun Mar 23 11:29:00 2003 - No source code changes in this version - Patch to stop shipping blib/ directory in Unix distros, because the PAUSE indexer takes this directory to indicate a binary distro, which means it does not index the module, and this in turn means the module is not listed in the CPAN daily update list, etc. 1.45 Sun May 12 13:12:11 2002 - Clean up licence and email stuff in all modules, scripts and other docs. Upgrading is not necessary 1.44 4-Oct-99 -------------- o Change my email address o Make a *.zip compatible with PPM 1.43 26-May-99 -------------- o Ensure POD survives buggy pod2man o Ship Readme.txt, output by pod2text 1.42 15-Apr-99 -------------- o Add stuff required to generate valid PPM files to Makefile.PL o Test using makePPD.bat and patchPPD.pl o See http://savage.net.au/Perl.html for these 2 1.41 30-May-99 -------------- o Recreated by h2xs 1.18 1.40 10-Nov-98 -------------- o Change width of help report. Restructure tests. 1.30 11-Dec-97 -------------- o Change 'Help' to 'verbose'. Make all hash keys lowercase. 1.20 3-Dec-97 ------------- o Add 'Help' on a per-switch basis. 1.10 13-Oct-97 -------------- o Add arrays of switches (eg '=s@'). 1.00 19-Aug-97 -------------- o Initial version. Getopt-Simple-1.52/META.yml000444001750001750 106011434663766 14334 0ustar00ronron000000000000--- abstract: 'Provide a simple wrapper around Getopt::Long.' author: - 'Ron Savage ' build_requires: Test::More: 0 Test::Pod: 0 configure_requires: Module::Build: 0.36 generated_by: 'Module::Build version 0.3607' license: artistic meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 name: Getopt-Simple provides: Getopt::Simple: file: lib/Getopt/Simple.pm version: 1.52 requires: Getopt::Long: 0 resources: license: http://www.perlfoundation.org/artistic_license_1_0 version: 1.52 Getopt-Simple-1.52/README000444001750001750 313611434663766 13751 0ustar00ronron000000000000README file for Getopt::Simple. Warning: WinZip 8.1 and 9.0 both contain an 'accidental' bug which stops them recognizing POSIX-style directory structures in valid tar files. You are better off using a reliable tool such as InfoZip: ftp://ftp.info-zip.org/pub/infozip/ 1 Installing from a Unix-like distro ------------------------------------ shell>gunzip Getopt-Simple-1.47.tgz shell>tar mxvf Getopt-Simple-1.47.tar On Unix-like systems, assuming you have installed Module::Build V 0.25+: shell>perl Build.PL shell>./Build shell>./Build test shell>./Build install On MS Windows-like systems, assuming you have installed Module::Build V 0.25+: shell>perl Build.PL shell>perl Build shell>perl Build test shell>perl Build install Alternately, without Module::Build, you do this: Note: 'make' on MS Windows-like systems may be called 'nmake' or 'dmake'. shell>perl Makefile.PL shell>make shell>make test shell>su (for Unix-like systems) shell>make install shell>exit (for Unix-like systems) On all systems: Run Simple.pm through you favourite pod2html translator. If you are using my fancy-pom2.pl, with its 'default.css' file installed in /apache2/htdocs/css/, you'd do: shell>perl fancy-pom2.pl html -css Simple.pm > /apache2/htdocs/Simple.html or perhaps something like: shell>perl fancy-pom2.pl html -css Simple.pm > /perl/html/site/lib/Getopt/Simple.html 2 Installing from an ActiveState distro --------------------------------------- shell>unzip Getopt-Simple-1.47.zip shell>ppm install --location=. Getopt-Simple shell>del Getopt-Simple-1.47.ppd shell>del PPM-Getopt-Simple-1.47.tar.gz Getopt-Simple-1.52/MANIFEST000444001750001750 23211434663766 14174 0ustar00ronron000000000000Build.PL Changelog.ini CHANGES lib/Getopt/Simple.pm Makefile.PL MANIFEST This list of files META.yml README t/pod.t t/test.t t/zero.pl t/zero.t test.pl Getopt-Simple-1.52/Makefile.PL000444001750001750 117111434663766 15040 0ustar00ronron000000000000use ExtUtils::MakeMaker; # See lib/ExtUtils/MakeMaker.pm for details of how to influence # the contents of the Makefile that is written. WriteMakefile ( ($] ge '5.005') ? ( 'AUTHOR' => 'Ron Savage (ron@savage.net.au)', 'ABSTRACT' => 'A simple-to-use interface to Getopt::Long', ) : (), clean => { FILES => 'blib/* Makefile MANIFEST Getopt-Simple-*' }, dist => { COMPRESS => 'gzip', SUFFIX => 'gz' }, DISTNAME => 'Getopt-Simple', NAME => 'Getopt::Simple', PL_FILES => {}, PREREQ_PM => { Getopt::Long => 0, Test::More => 0, Test::Pod => 0, }, VERSION_FROM => 'lib/Getopt/Simple.pm' ); Getopt-Simple-1.52/Changelog.ini000444001750001750 520411434663766 15457 0ustar00ronron000000000000[Module] Name=Getopt::Simple Changelog.Creator=Module::Metadata::Changes V 1.08 Changelog.Parser=Config::IniFiles V 2.57 [V 1.52] Date=2010-02-21T12:55:13 Comments= <perl testSimple.pl -q -u User -p Pass -l 333.222.111.000 -ara A -ara B # # Tabs: # 4 spaces || die. # # Version: # 1.00 20-Aug-97 # # Author: # Ron Savage # 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 Getopt::Simple qw($switch); my($option); # -------------------------------------------------------------------------- sub init { my($default) = { help => { type => '', env => '-', default => '', order => 1, }, quiet => { type => '', env => '-', default => '', order => 2, }, username => { type => '=s', env => '$USER', default => $ENV{'USER'} || 'RonSavage', verbose => 'Specify the username on the remote machine', order => 3, }, password => { type => '=s', env => '-', default => 'password', verbose => 'Specify the password on the remote machine', order => 4, }, remoteIP => { type => '=s', env => '$REMOTEHOST', default => $ENV{'REMOTEHOST'} || 'UnixBox', order => 5, }, localIP => { type => '=s', env => '$HOST', default => $ENV{'HOST'} || '127.0.0.1', order => 6, }, home => { type => '=s', env => '$HOME', default => $ENV{'HOME'} || 'C:', verbose => 'Specify the home directory on the local machine', order => 7, }, remoteHome => { type => '=s', env => '-', default => '/users/home/dir', verbose => 'Specify the home directory on the remote machine', order => 8, }, ara => { type => '=s@', env => '-', default => [qw/X Y Z/], order => 9, }, }; $option = Getopt::Simple -> new(); if (! $option -> getOptions($default, "Usage: testSimple.pl [options]") ) { exit(-1); # Failure. } } # End of init. # -------------------------------------------------------------------------- &init(); print "Report 1. The current value of each option: \n"; $option -> dumpOptions(); print "Report 2. The current value of some options: \n"; print "username: $option->{'switch'}{'username'}. \n"; print "password: $option->{'switch'}{'password'}. \n"; print "remoteIP: $$switch{'remoteIP'}. \n"; print "localIP: $$switch{'localIP'}. \n"; print "ara[0]: $$switch{'ara'}[0]. \n" if ($$switch{'ara'}[0]); # Test long $switch -> {'switchName'} rather than short $$switch{'switchName'}. # Use '->' inside double quotes, but safely use ' -> ' outside... print "ara[1]: $switch->{'ara'}[1]. \n" if ($switch -> {'ara'}[1]); print "ara[2]: $switch->{'ara'}[2]. \n" if ($switch -> {'ara'}[2]); print "\n"; print "Report 3. The help text: \n"; $option -> helpOptions(); # Success. exit(0); Getopt-Simple-1.52/t000755001750001750 011434663766 13174 5ustar00ronron000000000000Getopt-Simple-1.52/t/test.t000444001750001750 13311434663766 14452 0ustar00ronron000000000000use Test::More tests => 1; # ------------------------ BEGIN{ use_ok('Getopt::Simple'); } Getopt-Simple-1.52/t/zero.t000444001750001750 26711434663766 14462 0ustar00ronron000000000000use strict; use warnings; use Test::More tests => 1; # ----------------- my($result) = `perl t/zero.pl -p 0`; ok($result == 0, 'Successfully used 0 to override default value 1'); Getopt-Simple-1.52/t/zero.pl000444001750001750 47211434663766 14630 0ustar00ronron000000000000use lib './lib'; use strict; use warnings; use Getopt::Simple; # ----------------- my($opt) = Getopt::Simple -> new(); $opt->getOptions( { env => '-', purge => { type => "=i", default => 1, order => 1, } }, "$0 [options]", 1, 1); print $$opt{'switch'}{'purge'}; Getopt-Simple-1.52/t/pod.t000444001750001750 20411434663766 14254 0ustar00ronron000000000000use Test::More; eval "use Test::Pod 1.00"; plan skip_all => "Test::Pod 1.00 required for testing POD" if $@; all_pod_files_ok(); Getopt-Simple-1.52/lib000755001750001750 011434663766 13477 5ustar00ronron000000000000Getopt-Simple-1.52/lib/Getopt000755001750001750 011434663766 14741 5ustar00ronron000000000000Getopt-Simple-1.52/lib/Getopt/Simple.pm000444001750001750 2372511434663766 16716 0ustar00ronron000000000000package Getopt::Simple; # Name: # Getopt::Simple. # # Documentation: # POD-style documentation is at the end. Extract it with pod2html.*. # # Tabs: # 4 spaces || die. # # Author: # Ron Savage # 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 - 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 is a pure Perl module. The C 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 object. This is the class's contructor. Usage: Getopt::Simple -> new(). This method does not take any parameters. =head1 The C function C prints all your option's keys and their current values. C does not return anything. =head1 The C function The C 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 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 function C prints nicely formatted help text. C 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 was written by Ron Savage Iron@savage.net.auE> 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