13 Aug 2006 17:38:11 UTC
- Distribution: Debug
- Module version: 1.00
- Source (raw)
- Browse (raw)
- How to Contribute
- Testers (0 / 406 / 0)
- KwaliteeBus factor: 0
- % Coverage
- License: unknown
- Activity24 month
- Download (3.58KB)
- MetaCPAN Explorer
- Subscribe to distribution
- This version
- Latest version++ed by:1 non-PAUSE userATG Ondřej Vostal
Debug::Message - Eases the use of debug print with level, indentation and color.
use Debug::Message; use Log::Dispatch; use Log::Dispatch::Screen; my $dispatcher = Log::Dispatch->new; $dispatcher->add( Log::Dispatch::Screen->new( name => 'screen', min_level => '0' )); my $info = Debug::Message->new(1); $info->add_dispatcher($dispatcher); $info->print("print"); $info->yellow("warn"); $info->red("err"); $info->printcn("error message", 'bold red'); my $critical = Debug::Message->new(5); $critical->add_dispatcher($dispatcher); $critical->redn("err");
For disabling the debugging simply do not attach any dispatchers.
$critical->disable; # Will detach the attached backend
There was no module for simple debug messages supporting debug/verbosity levels and indentation. So this is the one, that is supposed to take this place.
This module is an art of frontend to Log::Dispatch as Log::Dispatch itself supports levels, but no colors and the function's calling is tedious.
There are some methods defined. Each outputs a different color, optionally it can add a newline after the messaage. They dispatch the messages to all added dispatchers, but generaly only one will be needed as the Log::Dispatch itself can have more backends.
In theory the use is simple. You have to create some Debug::Message objects. Each of these with different importance level. You connect them to the same Log::Dispatch.
Then you set the min_level of Log::Dispatch according to the command line or what ever. Only those messages, wich have enough high level (larger or equal to the Log::Dispatche's one) are outputed. For more complicated scenarios refer to Log::Dispatch(3).
use Debug::Message; my $debug = Debug::Message->new( $importance );
Will constuct and return new instance of Debug::Message with importance level set to $importance. The level is a number in range from 0 to 7.
All functions output is effected by the indentation level. The print() function will output an uncolored string. The COLOR fuctions output a colorizes string. The COLOR can be one of blue, magenta, yellow, red, green. The FUNCTIONn (printn, yellown, etc.) add a trailing newline to the messgage. And finaly the printc() function colorizes its message according to $colorspecs.
Is a string to send to connected dispatcher modules (Log::Dispatch(3)).
Is color according to Term::ANSIColor(3) man page.
Adds an output module to the object.
Unsets the dispatcher thus disables the debugging. Returns the former dispatcher.
Assigns a level $level and returns a new value. If $level is omited nothing is set and the old value is returned
Increases level by $number. If $number is omited the function behaves as if it was one. The new level value is returned.
Decreases level by $number. If $number is omited the function behaves as if it was one. The new value of level is returned.
test and retreve the user's ideas
somehow connect with a preprocessor to remove the debug-related calls in working environment
The best experience is to copy the initial setup from the synopsis. It saves a lot of writing. Or from here; the more complicated one.
### Set-up debuggung facilities use Debug::Message; use Log::Dispatch; use Log::Dispatch::Screen; our $Verbosity_Level = '0'; my $dispatcher = Log::Dispatch->new; $dispatcher->add( Log::Dispatch::Screen->new( name => 'screen', min_level => $Verbosity_Level )); my $info = Debug::Message->new(2); $info->add_dispatcher($dispatcher); my $data = Debug::Message->new(0); $data->add_dispatcher($dispatcher); my $warning = Debug::Message->new(4); $warning->add_dispatcher($dispatcher);
No known. The new found please report on <firstname.lastname@example.org>
Some of the ideas evolved: Colors insted of semantics in function names. Initial release 0.51.
Continued writing after a long pause. Rewritten much of the code.
I began writing with many nice ideals on mind.
1 POD Error
The following errors were encountered while parsing the POD:
- Around line 367:
'=item' outside of any '=over'
=over without closing =back
Module Install Instructions
To install Debug::Message, copy and paste the appropriate command in to your terminal.
perl -MCPAN -e shell install Debug::Message
For more information on module installation, please visit the detailed CPAN module installation guide.