The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Paraniod::Debug - Trace message support for paranoid programs

MODULE VERSION

$Id: Debug.pm,v 0.8 2008/02/27 17:57:52 acorliss Exp $

SYNOPSIS

  use Paranoid::Debug;

  PDEBUG = 1;
  PDPREFIX = sub { scalar localtime };
  pdebug("starting program", 1);
  foo();

  sub foo {
    pIn();
    pdebug("entering foo()", 2);
    pOut();
  }

  perror("error msg");

  psetDebug(@ARGV);

REQUIREMENTS

Paranoid

DESCRIPTION

The purpose of this module is to provide a barely useful framework to produce debugging output. With this module you can assign a level of detail to pdebug statements, and they'll only be displayed when PDEBUG is set to that level or higher. This allows you to have your program produce varying levels of debugging output.

Using the pIn and pOut functions at the beginning and end of each function will cause debugging output to be indented appropriately so you can visually see the level of recursion.

NOTE: This module provides a function called perror which conflicts with a similar function provided by the POSIX module. If you use this module you should avoid using or importing POSIX's version of this function.

NOTE: All modules within the Paranoid framework use this module. Their debug levels range from 9 and up. You should use 1 - 8 for your own modules or code.

VARIABLES

PDEBUG

PDEBUG is initially 0, but can be set to any positive integer. The higher the number the higher the level of pdebug statements are printed.

PDPREFIX

PDPREFIX is set, by default to a subroutine that produces the standard prefix for debug messages:

  [PID - ILEVEL] Subroutine:

FUNCTIONS

perror

  perror("error msg");

This function prints the passed message to STDERR.

pdebug

  pdebug("debug statement", 3);

This function is called with one mandatory argument (the string to be printed), and an optional integer. This integer is compared against PDEBUG and the debug statement is printed if PDEBUG is equal to it or higher.

The return value is always the debug statement itself. This allows for a single statement to produce debug output and set variables. For instance:

  Paranoid::ERROR = pdebug("Something bad happened!", 3);

pIn

  pIn();

This function causes all subsequent pdebug messages to be indented by one additional space.

pOut

  pOut();

This function causes all subsequent pdebug messages to be indented by one less space.

psetDebug

  psetDebug(@ARGV);

This function extracts all ^-v+$ arguments from the passed list and counts the number of 'v's that result, and sets PDEBUG to that count. You would typically use this by passing @ARGV for command-line programs.

HISTORY

None as of yet.

AUTHOR/COPYRIGHT

(c) 2005 Arthur Corliss (corliss@digitalmages.com)