ASNMTAP
view release on metacpan or search on metacpan
lib/ASNMTAP/Asnmtap.pm view on Meta::CPAN
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
sub _init {
carp ('ASNMTAP::Asnmtap: _init') if ( $_[0]->{_debug} );
$_[0]->{_programUsageSuffix} = ' [-v|--verbose <LEVEL>] [-V|--version] [-h|--help] [--usage] [--dumpData]';
$_[0]->{_programHelpSuffix} = "
-v, --verbose=<LEVEL>
0: single line, minimal output
1: single line, additional information
2: multi line, configuration debug output
3: lots of detail for problem diagnosis
-V, --version
Report version
-h, --help
Display the help message
--usage
Display the short usage statement
--dumpData
Display the stringified data structures from the current object
";
push (@{ $_[0]->{_programGetOptions} }, 'verbose|v:i', 'version|V', 'help|h', 'usage', 'dumpData');
$_[0]->[ $_[0]->[0]{_getOptionsType} = @{$_[0]} ] = {};
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
sub _getOptions {
carp ('ASNMTAP::Asnmtap: _getOptions') if ( $_[0]->{_debug} );
Getopt::Long::Configure ('bundling', 'pass_through');
my %getOptionsArgv;
my $programGetOptions = $_[0]->{_programGetOptions};
my $resultGetOptions = GetOptions ( \%getOptionsArgv, @$programGetOptions );
carp ('ASNMTAP::Asnmtap: _getOptions '. "Unknown option(s): @ARGV") if ( ref $_[0] !~ /ASNMTAP::Asnmtap::Plugins/ );
$_[0]->[ $_[0]->[0]{_getOptionsArgv} = @{$_[0]} ] = {%getOptionsArgv};
$_[0]->printRevision () if ( exists $_[0]->{_getOptionsArgv}->{version} );
$_[0]->printHelp () if ( exists $_[0]->{_getOptionsArgv}->{help} );
$_[0]->printUsage ('.') if ( exists $_[0]->{_getOptionsArgv}->{usage} );
my $verbose = (exists $_[0]->{_getOptionsArgv}->{verbose}) ? $_[0]->{_getOptionsArgv}->{verbose} : 0;
$_[0]->printUsage ('Invalid verbose option: '. $verbose) unless ($verbose =~ /^[0123]$/);
$_[0]->[ $_[0]->[0]{_getOptionsValues} = @{$_[0]} ] = {};
}
# = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
sub _checkAccObjRef { unless ( ref $_[0] ) { cluck 'Syntax error: Access object reference expected'; exit $ERRORS{UNKNOWN} } }
sub _checkSubArgs0 { if ( @_ > 1 ) { cluck "Syntax error: To many arguments ". (caller 1)[3]; exit $ERRORS{UNKNOWN} } }
sub _checkSubArgs1 { if ( @_ > 2 ) { cluck "Syntax error: To many arguments ". (caller 1)[3]; exit $ERRORS{UNKNOWN} } }
sub _checkSubArgs2 { if ( @_ > 3 ) { cluck "Syntax error: To many arguments ". (caller 1)[3]; exit $ERRORS{UNKNOWN} } }
sub _checkReadOnly0 { if ( @_ > 1 ) { cluck "Syntax error: Can't change value of read-only attribute ". (caller 1)[3]; exit $ERRORS{UNKNOWN} } }
sub _checkReadOnly1 { if ( @_ > 2 ) { cluck "Syntax error: Can't change value of read-only attribute ". (caller 1)[3]; exit $ERRORS{UNKNOWN} } }
sub _checkReadOnly2 { if ( @_ > 3 ) { cluck "Syntax error: Can't change value of read-only attribute ". (caller 1)[3]; exit $ERRORS{UNKNOWN} } }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
sub _dumpValue {
require Dumpvalue;
my $dumper = Dumpvalue->new ();
print "\n->ASNMTAP::Asnmtap: Dump debug data\n\n";
$dumper->dumpValue ( $_[0] );
print "\n\n";
cluck $_[1];
exit $ERRORS{UNKNOWN};
}
# Object accessor methods - - - - - - - - - - - - - - - - - - - - - - - -
sub programName { &_checkAccObjRef ( $_[0] ); &_checkSubArgs1; $_[0]->{_programName} = $_[1] if ( defined $_[1] ); $_[0]->{_programName}; }
sub programDescription { &_checkAccObjRef ( $_[0] ); &_checkSubArgs1; $_[0]->{_programDescription} = $_[1] if ( defined $_[1] ); $_[0]->{_programDescription}; }
sub programVersion { &_checkAccObjRef ( $_[0] ); &_checkSubArgs1; $_[0]->{_programVersion} = $_[1] if ( defined $_[1] ); $_[0]->{_programVersion}; }
sub getOptionsArgv { &_checkAccObjRef ( $_[0] ); &_checkReadOnly1; ( defined $_[1] and defined $_[0]->{_getOptionsArgv}->{$_[1]} ) ? $_[0]->{_getOptionsArgv}->{$_[1]} : undef; }
sub getOptionsValue { &_checkAccObjRef ( $_[0] ); &_checkReadOnly1; ( defined $_[1] and defined $_[0]->{_getOptionsValues}->{$_[1]} ) ? $_[0]->{_getOptionsValues}->{$_[1]} : undef; }
sub getOptionsType { &_checkAccObjRef ( $_[0] ); &_checkReadOnly1; ( defined $_[1] and defined $_[0]->{_getOptionsType}->{$_[1]} ) ? $_[0]->{_getOptionsType}->{$_[1]} : undef; }
sub debug { &_checkAccObjRef ( $_[0] ); &_checkSubArgs1; $_[0]->{_debug} = $_[1] if ( defined $_[1] and $_[1] =~ /^[01]$/ ); $_[0]->{_debug}; }
# Class accessor methods - - - - - - - - - - - - - - - - - - - - - - - -
sub dumpData {
&_checkAccObjRef ( $_[0] ); &_checkSubArgs1;
if ( defined $_[1] or $_[0]->{_debug} ) {
use Data::Dumper;
print "\n". ref ($_[0]) .": Now we'll dump data\n\n", Dumper ( $_[0] ), "\n\n";
}
}
# Utility methods - - - - - - - - - - - - - - - - - - - - - - - - - - - -
sub printRevision {
&_checkAccObjRef ( $_[0] ); &_checkSubArgs1;
print "\nThis is program: ", $_[0]->{_programName}, " (", $_[0]->{_programDescription}, ") v", $_[0]->{_programVersion}, "
Copyright (c) $COPYRIGHT ASNMTAP, Author: Alex Peeters [alex.peeters\@citap.be]
";
exit ( (ref $_[0]) =~ /^ASNMTAP::Asnmtap::Plugins/ ? $ERRORS{UNKNOWN} : 0 ) unless ( defined $_[1] );
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
sub printUsage {
&_checkAccObjRef ( $_[0] ); &_checkSubArgs1;
print 'Usage: ', $_[0]->{_programName};
( run in 1.470 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )