blib/lib/Debug/Message.pm untested

filter: Statementstmt 0.0% 0 / 21 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod n/a totaltotal 0.0% 0 / 27 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 # Copyright (c) 2006 Ondrej Vostal
2 #
3 # All rights reserved. This program is free software; you can
4 # redistribute it and/or modify it under the same terms as Perl
5 # itself.
6  
7 package Debug::Message;
8  
9 =head1 NAME
10  
11 Debug::Message - Eases the use of debug print with level, indentation and color.
12  
13 =head1 SYNOPSIS
14  
15 use Debug::Message;
16 use Log::Dispatch;
17 use Log::Dispatch::Screen;
18  
19 my $dispatcher = Log::Dispatch->new;
20 $dispatcher->add( Log::Dispatch::Screen->new( name => 'screen',
21 min_level => '0' ));
22  
23 my $info = Debug::Message->new(1);
24 $info->add_dispatcher($dispatcher);
25 $info->print("print");
26 $info->yellow("warn");
27 $info->red("err");
28 $info->printcn("error message", 'bold red');
29  
30 my $critical = Debug::Message->new(5);
31 $critical->add_dispatcher($dispatcher);
32 $critical->redn("err");
33  
34 For disabling the debugging simply do not attach any dispatchers.
35  
36 $critical->disable; # Will detach the attached backend
37  
38 =head1 DESCRIPTION
39  
40 There was no module for simple debug messages supporting debug/verbosity levels
41 and indentation. So this is the one, that is supposed to take this
42 place.
43  
44 This module is an art of frontend to Log::Dispatch as Log::Dispatch
45 itself supports levels, but no colors and the function's calling is
46 tedious.
47  
48 There are some methods defined. Each outputs a different color,
49 optionally it can add a newline after the messaage. They dispatch the
50 messages to all added dispatchers, but generaly only one will be
51 needed as the Log::Dispatch itself can have more backends.
52  
53 =head1 DETAILS
54  
55 In theory the use is simple. You have to create some Debug::Message
56 objects. Each of these with different importance level. You connect
57 them to the same Log::Dispatch.
58  
59 Then you set the min_level of Log::Dispatch according to the command
60 line or what ever. Only those messages, wich have enough high level
61 (larger or equal to the Log::Dispatche's one) are outputed. For more
62 complicated scenarios refer to Log::Dispatch(3).
63  
64 =cut
65  
66 use strict;
67 use warnings;
68 use Carp;
69 use Params::Validate qw(:all);
70 Params::Validate::validation_options( on_fail => sub { confess $_[0] } );
71 use Term::ANSIColor;
72 use SelfLoader;
73  
74 our $VERSION = '1.00';
75  
76 __DATA__