| 1 | # | ||||||||||
| 2 | # Package Definition | ||||||||||
| 3 | # | ||||||||||
| 4 | |||||||||||
| 5 | package Text::UberText::Log; | ||||||||||
| 6 | |||||||||||
| 7 | # | ||||||||||
| 8 | # Compiler Directives | ||||||||||
| 9 | # | ||||||||||
| 10 | |||||||||||
| 11 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | # | ||||||||||
| 15 | # Includes | ||||||||||
| 16 | # | ||||||||||
| 17 | |||||||||||
| 18 | 2 | ▶ | use Text::Wrap; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 19 | |||||||||||
| 20 | # | ||||||||||
| 21 | # Global Variables | ||||||||||
| 22 | # | ||||||||||
| 23 | |||||||||||
| 24 | 2 | ▶ | use vars qw/$VERSION /; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 25 | |||||||||||
| 26 | 2 | $VERSION=0.95; | |||||||||
| 27 | |||||||||||
| 28 | 2 | $Text::Wrap::columns=72; | |||||||||
| 29 | |||||||||||
| 30 | # | ||||||||||
| 31 | # Methods | ||||||||||
| 32 | # | ||||||||||
| 33 | |||||||||||
| 34 | sub new | ||||||||||
| 35 | 0 | ▶ | { | ||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 36 | 0 | my ($class)=shift; | |||||||||
| 37 | 0 | my ($object); | |||||||||
| 38 | 0 | $object={}; | |||||||||
| 39 | 0 | bless ($object,$class); | |||||||||
| 40 | 0 | $object->_init(@_); | |||||||||
| 41 | 0 | return $object; | |||||||||
| 42 | } | ||||||||||
| 43 | |||||||||||
| 44 | sub write | ||||||||||
| 45 | 0 | ▶ | { | ||||||||
|
Subroutine
write: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 46 | 0 | my ($self)=shift; | |||||||||
| 47 | 0 | ▶ | if (@_) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | { | ||||||||||
| 49 | 0 | my ($module,$message,$line,$severity)=@_; | |||||||||
| 50 | 0 | $self->{log}->[$self->{last}]->{module}=$module; | |||||||||
| 51 | 0 | $self->{log}->[$self->{last}]->{message}=$message; | |||||||||
| 52 | 0 | $self->{log}->[$self->{last}]->{line}=$line; | |||||||||
| 53 | 0 | $self->{log}->[$self->{last}]->{severity}=$severity; | |||||||||
| 54 | 0 | $self->{last}++; | |||||||||
| 55 | } | ||||||||||
| 56 | 0 | return; | |||||||||
| 57 | } | ||||||||||
| 58 | |||||||||||
| 59 | sub list | ||||||||||
| 60 | 0 | ▶ | { | ||||||||
|
Subroutine
list: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 61 | 0 | my ($self)=shift; | |||||||||
| 62 | 0 | my ($fmt)="%s.%s: %s at line %d\n"; | |||||||||
| 63 | 0 | ▶ | if (@{$self->{log}}) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 64 | { | ||||||||||
| 65 | 0 | my ($entry); | |||||||||
| 66 | 0 | foreach $entry (@{$self->{log}}) | |||||||||
| 67 | { | ||||||||||
| 68 | printf($fmt,$entry->{module},$entry->{severity}, | ||||||||||
| 69 | 0 | $entry->{message},$entry->{line}); | |||||||||
| 70 | } | ||||||||||
| 71 | } | ||||||||||
| 72 | 0 | return; | |||||||||
| 73 | } | ||||||||||
| 74 | |||||||||||
| 75 | sub report | ||||||||||
| 76 | 0 | ▶ | { | ||||||||
|
Subroutine
report: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 77 | 0 | my ($self)=shift; | |||||||||
| 78 | 0 | ▶ | if (@{$self->{log}}) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 79 | { | ||||||||||
| 80 | 0 | my ($entry); | |||||||||
| 81 | 0 | print("\n"); | |||||||||
| 82 | 0 | foreach $entry (@{$self->{log}}) | |||||||||
| 83 | { | ||||||||||
| 84 | 0 | print($entry->{module}.":".$entry->{line},"\n"); | |||||||||
| 85 | print(wrap(" "," ", | ||||||||||
| 86 | 0 | $entry->{severity}.":".$entry->{message}),"\n"); | |||||||||
| 87 | } | ||||||||||
| 88 | } | ||||||||||
| 89 | 0 | return; | |||||||||
| 90 | } | ||||||||||
| 91 | |||||||||||
| 92 | # | ||||||||||
| 93 | # Hidden Methods | ||||||||||
| 94 | # | ||||||||||
| 95 | |||||||||||
| 96 | sub _init | ||||||||||
| 97 | 0 | ▶ | { | ||||||||
|
Subroutine
_init: not called CC=1 SCAR=6.9
| |||||||||||
| 98 | 0 | my ($self)=shift; | |||||||||
| 99 | 0 | $self->{log}=[]; | |||||||||
| 100 | 0 | $self->{last}=0; | |||||||||
| 101 | 0 | return; | |||||||||
| 102 | } | ||||||||||
| 103 | |||||||||||
| 104 | |||||||||||
| 105 | # | ||||||||||
| 106 | # Exit Block | ||||||||||
| 107 | # | ||||||||||
| 108 | 2 | 1; | |||||||||
| 109 | |||||||||||
| 110 | # | ||||||||||
| 111 | # POD Documentation | ||||||||||
| 112 | # | ||||||||||
| 113 | |||||||||||
| 114 | =head1 NAME | ||||||||||
| 115 | |||||||||||
| 116 | Text::UberText::Log - Record of UberText processing | ||||||||||
| 117 | |||||||||||
| 118 | =head1 SYNOPSIS | ||||||||||
| 119 | |||||||||||
| 120 | $uber=Text::UberText->new(); | ||||||||||
| 121 | $log=$uber->log(); | ||||||||||
| 122 | $log->write("Dispatch","Object load failure",,"ERROR"); | ||||||||||
| 123 | $log->list(); | ||||||||||
| 124 | |||||||||||
| 125 | =head1 DESCRIPTION | ||||||||||
| 126 | |||||||||||
| 127 | Text::UberText::Log is used to debug the parsing of UberText documents. The | ||||||||||
| 128 | Parser, the Dispatch table, and other modules record informational or warning | ||||||||||
| 129 | messages to the log. | ||||||||||
| 130 | |||||||||||
| 131 | =head1 OBJECT METHODS | ||||||||||
| 132 | |||||||||||
| 133 | =over 4 | ||||||||||
| 134 | |||||||||||
| 135 | =item $log->write($module,$message,$linenumber,$severity) | ||||||||||
| 136 | |||||||||||
| 137 | Writes a message to the log object. Module generically refers to which | ||||||||||
| 138 | UberText module is reporting the error, but it can also be more generic or | ||||||||||
| 139 | specific to suit the needs of the implementor. Message is a verbose | ||||||||||
| 140 | description of the event. Linenumber indicates at what line of the document | ||||||||||
| 141 | the error occured (if it occured during parsing). Severity refers to | ||||||||||
| 142 | the level of importance of the message, and could be set to either "DEBUG", | ||||||||||
| 143 | "INFO", or "ERROR". | ||||||||||
| 144 | |||||||||||
| 145 | =item $log->list($severity) | ||||||||||
| 146 | |||||||||||
| 147 | Lists all log messages matching the severity level specified, or lists all | ||||||||||
| 148 | messages if no severity level is specified. | ||||||||||
| 149 | |||||||||||
| 150 | =back | ||||||||||
| 151 | |||||||||||
| 152 | =head1 BUGS/CAVEATS | ||||||||||
| 153 | |||||||||||
| 154 | This is the simplest module in the UberText distribution. | ||||||||||
| 155 | |||||||||||
| 156 | =head1 AUTHOR | ||||||||||
| 157 | |||||||||||
| 158 | Chris Josephes E<lt>cpj1@visi.comE<gt> | ||||||||||
| 159 | |||||||||||
| 160 | =head1 SEE ALSO | ||||||||||
| 161 | |||||||||||
| 162 | L<Text::UberText> | ||||||||||
| 163 | |||||||||||
| 164 | =head1 COPYRIGHT | ||||||||||
| 165 | |||||||||||
| 166 | Copyright 2002, Chris Josephes. All rights reserved. | ||||||||||
| 167 | This module is free software. It may be used, redistributed, | ||||||||||
| 168 | and/or modified under the same terms as Perl itself. | ||||||||||
| 169 | ~ | ||||||||||