| 1 | package WWW::Domain::Registry::Joker::Loggish; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | # $CNsys: lib/WWW/Domain/Registry/Joker/Loggish.pm 2375 2008-10-17 10:25:08Z roam $ | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use 5.006; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use Log::Dispatch; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use Log::Dispatch::Screen; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 2 | our $VERSION = '0.02'; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | =head1 NAME | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | WWW::Domain::Registry::Joker::Loggish - a simple logging helper | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | use WWW::Domain::Registry::Joker::Loggish; | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | @ISA = qw/WWW::Domain::Registry::Joker::Loggish/; | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | $self = WWW::Domain::Registry::Joker::Loggish::new($proto, | ||||||||||||||||||||||||||||
| 25 | 'debug' => 1); | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | $self->debug('Diagnostics for the masses'); | ||||||||||||||||||||||||||||
| 28 | $self->error('Nobody loves me!'); | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | $self->log('notice', 'Something important is about to happen'); | ||||||||||||||||||||||||||||
| 31 | $self->log('debug', 'Nobody ever bothers to read those...'); | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | The C<WWW::Domain::Registry::Joker::Loggish> class provides a simple | ||||||||||||||||||||||||||||
| 36 | logging interface, implemented using the C<Log::Dispatch> module. | ||||||||||||||||||||||||||||
| 37 | It is meant to serve as a parent class providing the C<log()>, C<debug()>, | ||||||||||||||||||||||||||||
| 38 | and C<error()> methods so that other classes do not have to worry about | ||||||||||||||||||||||||||||
| 39 | implementing them. | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | =head1 METHODS | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | The C<WWW::Domain::Registry::Joker::Loggish> class provides the following | ||||||||||||||||||||||||||||
| 44 | methods: | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | =over 4 | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | =item * new ( PARAMS ) | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | Create a new C<WWW::Domain::Registry::Joker::Loggish> object with | ||||||||||||||||||||||||||||
| 51 | the specified parameters: | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | =over 4 | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | =item * debug | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | A boolean flag for the output of diagnostic messages - should the C<debug()> | ||||||||||||||||||||||||||||
| 58 | method actually display the message passed or simply ignore it. | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | =item * log | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | The C<Log::Dispatch> object to use for the output; if not passed, | ||||||||||||||||||||||||||||
| 63 | a new object will be created at first use - see the C<logger()> method | ||||||||||||||||||||||||||||
| 64 | below. | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | =back | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | =cut | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | sub new($ %) | ||||||||||||||||||||||||||||
| 71 | { | ||||||||||||||||||||||||||||
| 72 | 0 | ▶ | my ($proto, %param) = @_; | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 73 | 0 | ▶ | my $class = ref $proto || $proto; | ||||||||||||||||||||||||||
|
Condition0%0/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||||||||||
| 74 | 0 | my $self; | |||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 0 | $self = { | |||||||||||||||||||||||||||
| 77 | 'debug' => 0, | ||||||||||||||||||||||||||||
| 78 | 'log' => undef, | ||||||||||||||||||||||||||||
| 79 | %param, | ||||||||||||||||||||||||||||
| 80 | }; | ||||||||||||||||||||||||||||
| 81 | 0 | bless $self, $class; | |||||||||||||||||||||||||||
| 82 | 0 | return $self; | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | =item * logger ( [OBJECT] ) | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | Get or set the C<Log::Dispatch> object used for the actual logging. | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | If no object is specified and no logging object has been set yet, this | ||||||||||||||||||||||||||||
| 90 | method will create a C<Log::Dispatch> object and a C<Log::Dispatch::Screen> | ||||||||||||||||||||||||||||
| 91 | destination set to output to the standard error stream. If tis does not | ||||||||||||||||||||||||||||
| 92 | suit the needs of the application, it should invoke the C<logger()> method | ||||||||||||||||||||||||||||
| 93 | and pass its own C<Log::Dispatch> handler. This may also be done at | ||||||||||||||||||||||||||||
| 94 | object creation time by passing the C<log> parameter to the C<new()> | ||||||||||||||||||||||||||||
| 95 | method. | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | =cut | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | sub logger($ $) | ||||||||||||||||||||||||||||
| 100 | { | ||||||||||||||||||||||||||||
| 101 | 0 | ▶ | my ($self, $log) = @_; | ||||||||||||||||||||||||||
|
Subroutine
logger: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 0 | ▶ | if (defined($log)) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 104 | 0 | ▶ | if (index(ref($log), '::') == -1 || | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
index(ref $log, "::") == -1 or not $log->isa("Log::Dispatch")
MC/DC0%0/2
index(ref $log, "::") == -1 or not $log->isa("Log::Dispatch")
index(ref $log, "::") == -1
not $log->isa("Log::Dispatch")
Truth table0%0/3
A or not(B)
A= index(ref $log, "::") == -1B= not $log->isa("Log::Dispatch")
| |||||||||||||||||||||||||||||
| 105 | !$log->isa('Log::Dispatch')) { | ||||||||||||||||||||||||||||
| 106 | 0 | die("Not a Log::Dispatch object: '".ref($log)."'"); | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | 0 | $self->{'log'} = $log; | |||||||||||||||||||||||||||
| 109 | } elsif (!defined($self->{'log'})) { | ||||||||||||||||||||||||||||
| 110 | 0 | $log = new Log::Dispatch(); | |||||||||||||||||||||||||||
| 111 | $log->add(new Log::Dispatch::Screen('name' => 'STDERR', | ||||||||||||||||||||||||||||
| 112 | 0 | ▶ | 'min_level' => ($self->{'debug'}? 'debug': 'info'))); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 113 | 0 | $self->{'log'} = $log; | |||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | 0 | return $self->{'log'}; | |||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | =item * log ( LEVEL, MESSAGE ) | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | Log the specified message at the specified level. | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | This method invokes the C<logger()> method, so that a C<Log::Dispatch> | ||||||||||||||||||||||||||||
| 123 | object will be created automatically at first use if none has been | ||||||||||||||||||||||||||||
| 124 | specified. | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | =cut | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | sub log($ $ $) | ||||||||||||||||||||||||||||
| 129 | { | ||||||||||||||||||||||||||||
| 130 | 0 | ▶ | my ($self, $level, $msg) = @_; | ||||||||||||||||||||||||||
|
Subroutine
log: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 0 | $self->logger()->log('level' => $level, 'message' => "$msg\n"); | |||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | =item * debug ( MESSAGE ) | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | Log a message with a priority of 'debug' using the C<log()> method. | ||||||||||||||||||||||||||||
| 138 | Note that whether the message will actually be logged or not will | ||||||||||||||||||||||||||||
| 139 | depend on the setting of the C<debug> property at object creation time. | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | =cut | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | sub debug($ $) | ||||||||||||||||||||||||||||
| 144 | { | ||||||||||||||||||||||||||||
| 145 | 0 | ▶ | my ($self, $msg) = @_; | ||||||||||||||||||||||||||
|
Subroutine
debug: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | 0 | $self->log('debug', $msg); | |||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | =item * error ( MESSAGE ) | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | Log a message with a priority of 'error' using the C<log()> method. | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | =cut | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | sub error($ $) | ||||||||||||||||||||||||||||
| 157 | { | ||||||||||||||||||||||||||||
| 158 | 0 | ▶ | my ($self, $msg) = @_; | ||||||||||||||||||||||||||
|
Subroutine
error: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | 0 | $self->log('error', $msg); | |||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | =back | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | L<Log::Dispatch> | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | =head1 BUGS | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | =over 4 | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | =item * | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | Maybe there ought to be a way to toggle the display of diagnostic | ||||||||||||||||||||||||||||
| 176 | messages after the object has been created. | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | =back | ||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | =head1 HISTORY | ||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | The C<WWW::Domain::Registry::Joker::Loggish> class was written by | ||||||||||||||||||||||||||||
| 183 | Peter Pentchev in 2007. | ||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | Peter Pentchev, E<lt>roam@ringlet.netE<gt> | ||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | Copyright (C) 2007 by Peter Pentchev | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | This library is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||
| 194 | it under the same terms as Perl itself, either Perl version 5.8.8 or, | ||||||||||||||||||||||||||||
| 195 | at your option, any later version of Perl 5 you may have available. | ||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | =cut | ||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | 2 | 1; | |||||||||||||||||||||||||||