Usage/Sub version 0.02
$Revision: 1.3 $
$Date: 2002/02/24 05:39:28 $
======================

****************************************************************************
WARNING: This module is considered in alpha stage. The name and the
         interface are subject to change.
****************************************************************************


NAME
    Usage::Sub - Issueing subroutine/method usage


SYNOPSIS
      use Usage::Sub;

      sub turn_on {
          @_ >= 2 or usage 'NAME, COLOR [, INTENTSITY]';
          # process goes on
      }


DESCRIPTION
    Usage::Sub provides functions to issueing the usage of subroutines or
    methods from inside the stub. Some people like to check the parameters
    of the routine. For example,

      # turn_on(NAME, COLOR [, INTENSITY])
      sub turn_on {
          @_ >= 2 or die "usage: turn_on(NAME, COLOR [, INTENSITY])\n";
          # the process goes on
      }

    With usage() function (exported by default), you can achieve the same
    result (and more) without having to remember the subroutine name.

      use Usage::Sub;

      sub turn_on {
          @_ >= 2 or usage 'NAME, COLOR [, INTENTSITY]';
          # process goes on
      }

    The usage() function makes use of the caller() built-in function to
    determine the subroutine name. When turn_on() is called with
    inappropriate parameters, usage() will terminate the program with
    backtrace information and prints error message like,

          usage: turn_on(NAME, COLOR [, INTENTSITY])

    If turn_on() is a method, a prefix can be added to indicate it as object
    method or class method call.

      sub turn_on {
          @_ >= 3 or usage 'NAME, COLOR [, INTENTSITY]', '$light';
          # process goes on
      }

    The error message will be then,

          usage: $light->turn_on(NAME, COLOR [, INTENTSITY])

    or

          usage: Light::My::Fire->turn_on(NAME, COLOR [, INTENTSITY])

    should it be a class method call.

    The warn_hard() and warn_soft() functions are similiar to usage(), but
    they don't die. Instead, as the their names suggest, they only warn the
    message out and returning undef. This can be handy for the subroutine to
    print the error message and return immediately in one step.

      sub turn_off {
          @_ >= 2 or return warn_hard('NAME', '$light');
          # process goes on
      }

    The difference between the two is that warn_soft() only works when $^W
    holds true, while warn_hard() always works regardless of the value of
    $^W.


BUGS

    It refuses to work if one of the usage functions is called not from
    subroutines or methods, for example, the main space.

        #!perl
        usage();

    This will result in error message such as,

        Usage::Sub::usage() must be called from a method or subroutine

    The bug comes if the usage() is called from the eval context. It
    continues to work since the fourth element of what caller (with "1"
    argument) returns contains something, as documented in perldoc -f
    caller.


INSTALLATION

To install this module type the following:

   perl Makefile.PL
   make
   make test
   make install


AUTHOR
    Hasanuddin Tamir <hasant@trabas.com>


COPYRIGHT
    Copyright (C) 2002 Trabas. All rights reserved.

    This program is free software. You may freely use it, modify and/or
    distribute it under the same term as Perl itself.


AVAILABILITY

    http://san.port5.com/0/perl/modules/Usage-Sub-0.02.tar.gz

