Data::CTable::Script - CTable virtual subclass to support shell scripts
## Call from a shell script: use Data::CTable::Script; exit !Data::CTable::Script->script(); ## But more likely, you'll want to subclass first: use Data::CTable::MyScript; exit !Data::CTable::MyScript->script();
This is an OO implementation of the outermost structure and utlility routines that would be needed by most any perl/shell script that wants to use Data::CTable functionality.
See Data::CTable::Lister for a sample subclass that uses this superstructure to implement a command-line tool that makes a table containing file listings and then lets the user manipulate it using various command-line options and then output it in various interesting ways.
See Data::CTable for the superclass.
See the Data::CTable home page:
Chris Thorman <email@example.com>
Copyright (c) 1995-2002 Chris Thorman. All rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
$Class->usage() ## Don't subclass $Class->usage_message($ScriptName) ## Subclass this
usage() figures out the name of the script being called and passes it to usage_message (designed to be sublcassed), which can the print the message including the name of the script.
Specification for command-line option parsing for the script. Meant to be subclassed.
Should return a hash mapping GetOpt::Long-style specifications to default values. This base class implementation returns the following spec entries. Subclasses could replace these entirely or add to them:
## Common options "help" => 0 , "verbose" => 0 , ## Which fields are included in output "fields=s" => , ## Sorting "sort=s" => , ## Output method "output=s" => ,
In the above specs "=s" means a string argument, and  means multiple values are allowed and will be collected in an array, whose initial contents are empty. 0 means the option defaults to off; a default of foo => 1 would allow the --nofoo switch to turn off the foo option.
Class method: main entry point for the script. Parses options, presents usage(), instantiates an object and lets it do its work. Returns a Boolean success value. (A perl script should exit() the opposite of this value: i.e. exit(0) means success.)
Main entry point for the script. Instantiates an object and lets it do its work. Returns a reference to a scalar which will be printed before the script exits. (Pass \ '' for no output).
Internal method to process command-line options using GetOpt::Long and a few enhancements, most importantly: any multi-valued field is post-processed to treat any values separated by commas or spaces as multiple values.