develooper Front page | perl.module-authors | Postings from January 2010

What's in a =?UTF-8?Q?name=3F=20=3A=29=20Advice=20on=20naming=20the=20mod?==?UTF-8?Q?ule=20i=27ve=20written=2E=2E=2E?=

Thread Next
January 21, 2010 04:03
What's in a =?UTF-8?Q?name=3F=20=3A=29=20Advice=20on=20naming=20the=20mod?==?UTF-8?Q?ule=20i=27ve=20written=2E=2E=2E?=
Message ID:
Hi all,

I'm new here so be kind :)

I've written a module that I use at home a lot which is what has brought
me to pause.

I currently call the module Debug, but obviously that's not an appropriate
name.  I've searched through the cpan, and found some relatively similar
modules, but basically this is what I've written:

Usage (obviously ignore the fact it's called 'Debug' here...)
my $dbg = Debug->new('bDebugMode'=> $bDebugMode, 'bTestMode' =>
$bTestMode, 'nVerboseMode'=>$bVerbose);

$dbg->print("Hello world");

$dbg->debug("Debugging Text");

$dbg->verbose("Text for Verbose mode");

$dbg->test("Text only for Test mode");

$dbg->error("Error Message");
Debug::new is where i've described the object attributes most completely,
so i'll include that too...

Creates a new Debug object.  Attributes can be set by passing in options
to new, or via their own get/set functions.

  bDebugMode   - Indicates whether to print debug messages
               - Default: FALSE
  bTestMode    - Indicates whether to print test messages
               - Default: FALSE
  nVerboseMode - Indicates whether to print verbose messages.  Verbose
level must
                 be greater than or equal to the message for the message
to be shown.
               - Default: FALSE
  bPrintEndl   - Indicates whether to automatically append an end of line
to each output
               - Default: TRUE
  bTimeStamp   - Indicates whether to print a timestamp at the start of
each line.
               - Default: FALSE
  sTimeStamp   - If printing a timestamp, this format string is how the
time will print
               - Default: '%H:%M:%S' (posix string)
  sErrPrefix   - If printing an error, prefix with this string.
               - Default: 'ERROR: '
  bFnNameDebug - If in debug mode, this flag indicates whether to print
the function name
               - in the prefix section of each string.
               - Default: TRUE
  bFnName      - Used to indicate if function names should always be
                 Unlike bFnNameDebug, this flag is independent of whether
debug mode is set.
               - Default: FALSE
  aStdOut      - a list of file handles to print any non error messages
               - Default: STDOUT
  aStdErr      - a list of file handles to print any error messages
               - Default: STDERR

Basically the intent of the module is to provide a way of making sure the
print output is consistent.  I wrap all my print statements through this
module, so when i enable debug mode, even the 'normal' printed lines get
the consistent formatting (by default the function name is prepended, but
it could be time, or whatever you configure in the object) to make the
output easier to read.

Born of laziness, it also appends (by default) an end of line at the end
of each print / debug / verbose / test / error call (obviously all this
goes through the print statement, which is how it all gets massaged based
on object attributes into consistent output).

Anyway, I'd be interested to know if people think that Debug::Print is an
appropriate name for this module...

I'd also be interested to know if people think this useful, or if it's
just me...  Constructive feedback is always something I'm happy to

The original intent was to stop having to go:
print "Blah\n" if ($bTestMode);
print "Blah blah\n" if ($bDebugMode); 

Now I'd just go 
$dbg->debug("Blah blah");

and it prints out if appropriate...

Hopefully I've supplied enough information :)



Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About