Usage.pm now in beta-release 
Author Message
 Usage.pm now in beta-release

This module provides full usage functionality. One line
defines the types and ranges expected for the arguments to
a function, and prints out a full, useful error message
giving all the details known about the function and error
if called incorrectly. I've included some predefined tests
(hooks are provided for adding in further checks), including
an OPEN_HANDLE test the automatically corrects the most common
error of passing file handles without the package name.

The Usage module is available in directory
        ftp://ftp.icnet.uk/icrf-public/biu/perlmods/
together with the example below and a list of changes since
the alpha release in case anyone used that.
(files {Usage.pm,Usage.pm.changes,usageExample})

Here's an example:

#!/usr/local/bin/perl
#file: usageExample
package A_Pack;
use Usage;

%USAGE_ALIAS = (
'BOOLEAN'=> ['ANYTHING',"Could be anything, but it's evaluated as a boolean."],
'EXTRA_INT' => ['OPT(6)_INTEGER(>=,1)','An optional positive integer (defaulted to 6)'],
);

sub a_test {
    setUsage('OPEN_HANDLE','INTEGER(>,1)','BOOLEAN','EXTRA_INT');&checkUsage;

    print "The handle was passed as $handle\n";
    if ($boolean) {
        print "The boolean was true, and the extra integer was $extra_int\n";
    } else {
        print "The boolean was false, and the extra integer was $extra_int\n";
    }
    print $handle $int + $extra_int,"\n";

Quote:
}

package main;
open(H,">/tmp/temp.test");
A_Pack::a_test(H,2,1,10);
A_Pack::a_test(H,2,1);
A_Pack::a_test(G,2);
__END__

which produces:

The handle was passed as main::H
The boolean was true, and the extra integer was 10
The handle was passed as main::H
The boolean was true, and the extra integer was 6
Use of uninitialized value at Usage.pm line 678.

Usage error at line 28 in file usageExample:
    Incorrect number of arguments passed to function 'a_test',
    passed 2 arguments, but expected 3 or 4 arguments.

Usage: a_test(OPEN_HANDLE,INTEGER>1,BOOLEAN[,EXTRA_INT])
  OPEN_HANDLE - Some sort of handle that is open. Tested using "fileno".
  INTEGER>1 - An integer (optional +/- with digits) which is > 1
  BOOLEAN - Could be anything, but it's evaluated as a boolean.
  EXTRA_INT - An optional positive integer (defaulted to 6)

Stack was:
        Usage::checkUsage called at usageExample line 11
        A_Pack::a_test called at usageExample line 28
--

If you only have a hammer, you tend to see every problem as a nail.
                -- Maslow



Sat, 17 May 1997 20:04:32 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. DbiGetProcs Oracle 7.2 Invalid Floating Point Operation

2. serious compiler error - typed constants

3. Edit mode after post

4. Usage.pm beta2 release

5. Usage.pm alpha release

6. Looking for latest perl5 beta release

7. ANNOUCE: VMS::Queue 0.03 (Beta release)

8. ANNOUNCE: Text::Vpp 0.1 BETA release

9. magic(1) - file(1) in perl, BETA release 2, Part05/06

10. magic(1) - file(1) in perl, BETA release 2, Part03/06

11. magic(1) - file(1) in perl, BETA release 2, Part06/06

12. magic(1) - file(1) in perl, BETA release 2, Part01/06

 

 
Powered by phpBB® Forum Software