Misc.pm - miscellaneous functions I find useful
Prints out useful diagnostic information when entering a function. The first argument is the filehandle to print to, the second is the arguments to the function it is called from.
Try calling it like this from class methods: Misc::debug_start($debug_fh,
@_[ 1 .. $#_ ]) if defined $debug
and $debug;
Prints out useful diagnostic information right before exiting a function. Assumes that the function will exit on the next line. Pass it the filehandle to print to, and the return value of the function.
Return an array containing filename, function, and line information about each function currently on the stack.
Exit by passing the elements of the passed array to die(),
if
the last element in the passed array does not end with a newline (or no
arguments are passed), also print out a stack trace after printing the
other passed arguments.
Takes a format string in which the following strings are treated specially:
the package name
the filename name
the line
the subroutine name
the package name and the subroutine name (package::subroutine)
You can escape a %C
string by %%C.
Returns the string with the %C
sequences transformed.
I often use this to at the start of my functions like this:
@_ == 1 or @_ == 2 Misc::bad_args("1 or 2", scalar @_);
to perform a small sanity check on the number of arguments passed.