| 1 | package Data::Phrasebook::Debug; | ||||||||||||||||||||||||||||
| 2 | 13 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 13 | ▶ | use warnings FATAL => 'all'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 13 | ▶ | use Carp qw( croak ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 13 | ▶ | use vars qw($VERSION); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 13 | $VERSION = '0.35'; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | =head1 NAME | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | Data::Phrasebook::Debug - Phrasebook debugging. | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | use Data::Phrasebook; | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | my $q = Data::Phrasebook->new( | ||||||||||||||||||||||||||||
| 18 | class => 'Plain', | ||||||||||||||||||||||||||||
| 19 | loader => 'Text', | ||||||||||||||||||||||||||||
| 20 | file => 'phrases.txt', | ||||||||||||||||||||||||||||
| 21 | debug => 2, | ||||||||||||||||||||||||||||
| 22 | ); | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | my $r = Phrasebook->new( file => 'phrases.txt', debug => 3 ); | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | $r->debug(4); | ||||||||||||||||||||||||||||
| 27 | $r->store(3,"Start"); | ||||||||||||||||||||||||||||
| 28 | my @log = $r->retrieve(2); | ||||||||||||||||||||||||||||
| 29 | $r->clear(); | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | This module enables debug logging for phrasebook classes. It simply stores | ||||||||||||||||||||||||||||
| 34 | all interaction with the phrasebook, which can then be interrogated. Do not | ||||||||||||||||||||||||||||
| 35 | call directly, but via the class object. | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | There is a single storage for all levels of the Data::Phrasebook heirarchy. | ||||||||||||||||||||||||||||
| 38 | This then enables storage and retrieval to be performed by the user. There | ||||||||||||||||||||||||||||
| 39 | are several different levels of debugging, detailed as follows: | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 1 - Errors | ||||||||||||||||||||||||||||
| 42 | 2 - Warnings | ||||||||||||||||||||||||||||
| 43 | 3 - Information | ||||||||||||||||||||||||||||
| 44 | 4 - Variable Debugging | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | The first three are simple strings that are recorded during the processing. | ||||||||||||||||||||||||||||
| 47 | However, the latter is specifically for dumping the contents of significant | ||||||||||||||||||||||||||||
| 48 | variables. | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | Through the use of the debug() method, the debugging can be switched on and | ||||||||||||||||||||||||||||
| 51 | off at significant points. The clear() method will clear the current trail of | ||||||||||||||||||||||||||||
| 52 | debugging information. | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | =cut | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 13 | my @debug; | |||||||||||||||||||||||||||
| 57 | 13 | my $debug = 0; | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | =head1 METHODS | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | =head2 debug | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | Accessor to debugging flag. | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | =cut | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 336 | ▶ | sub debug { | ||||||||||||||||||||||||||
|
Subroutine
debug: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 68 | 336 | my $self = shift; | |||||||||||||||||||||||||||
| 69 | 336 | ▶ | return @_ ? $debug = shift : $debug; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | =head2 clear | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | Clear the currently stored debugging information. | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | =cut | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 1 | ▶ | sub clear { | ||||||||||||||||||||||||||
|
Subroutine
clear: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 79 | 1 | return @debug = (); | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | =head2 store | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | Store debugging information. | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | =cut | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 31 | ▶ | sub store { | ||||||||||||||||||||||||||
|
Subroutine
store: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 89 | 31 | ▶ | return unless($debug); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 31 | my ($self, $id, @args) = @_; | |||||||||||||||||||||||||||
| 92 | 31 | ▶ | return if(!$id || $debug < $id); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $id or $debug < $id
MC/DC100%2/2
not $id or $debug < $id
not $id
$debug < $id
Truth table100%3/3
not(A) or B
A= not $idB= $debug < $id
| |||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 29 | push @debug, [$id, join(' ',@args)]; | |||||||||||||||||||||||||||
| 95 | 29 | return; | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | =head2 retrieve | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | Retrieve debugging information. | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | =cut | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 6 | ▶ | sub retrieve { | ||||||||||||||||||||||||||
|
Subroutine
retrieve: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 105 | 6 | my $self = shift; | |||||||||||||||||||||||||||
| 106 | 6 | ▶ | my $id = shift || 1; | ||||||||||||||||||||||||||
|
Condition100%2/2
shift() || 1
MC/DC100%1/1
shift() || 1
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 6 | return grep {$_->[0] <= $id} @debug; | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | =head2 dumper | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | Uses 'on demand' call to Data::Dumper::Dumper(). | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | =cut | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 4 | ▶ | sub dumper { | ||||||||||||||||||||||||||
|
Subroutine
dumper: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||||||||||
| 118 | 4 | my $self = shift; | |||||||||||||||||||||||||||
| 119 | 4 | my $dump = 'Data::Dumper'; | |||||||||||||||||||||||||||
| 120 | 4 | ▶ | if(eval { require $dump }) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 121 | 0 | $dump->import; | |||||||||||||||||||||||||||
| 122 | 0 | return Dumper(@_); | |||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | 4 | return ''; | |||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 13 | 1; | |||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | __END__ | ||||||||||||||||||||||||||||