| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Data::Phrasebook::Debug; | 
| 2 | 13 |  |  | 13 |  | 81 | use strict; | 
|  | 13 |  |  |  |  | 25 |  | 
|  | 13 |  |  |  |  | 466 |  | 
| 3 | 13 |  |  | 13 |  | 65 | use warnings FATAL => 'all'; | 
|  | 13 |  |  |  |  | 23 |  | 
|  | 13 |  |  |  |  | 461 |  | 
| 4 | 13 |  |  | 13 |  | 68 | use Carp qw( croak ); | 
|  | 13 |  |  |  |  | 26 |  | 
|  | 13 |  |  |  |  | 952 |  | 
| 5 |  |  |  |  |  |  |  | 
| 6 | 13 |  |  | 13 |  | 78 | use vars qw($VERSION); | 
|  | 13 |  |  |  |  | 29 |  | 
|  | 13 |  |  |  |  | 4868 |  | 
| 7 |  |  |  |  |  |  | $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 |  |  |  |  |  |  | my @debug; | 
| 57 |  |  |  |  |  |  | my $debug = 0; | 
| 58 |  |  |  |  |  |  |  | 
| 59 |  |  |  |  |  |  | =head1 METHODS | 
| 60 |  |  |  |  |  |  |  | 
| 61 |  |  |  |  |  |  | =head2 debug | 
| 62 |  |  |  |  |  |  |  | 
| 63 |  |  |  |  |  |  | Accessor to debugging flag. | 
| 64 |  |  |  |  |  |  |  | 
| 65 |  |  |  |  |  |  | =cut | 
| 66 |  |  |  |  |  |  |  | 
| 67 |  |  |  |  |  |  | sub debug { | 
| 68 | 336 |  |  | 336 | 1 | 1591 | my $self = shift; | 
| 69 | 336 | 100 |  |  |  | 1622 | return @_ ? $debug = shift : $debug; | 
| 70 |  |  |  |  |  |  | } | 
| 71 |  |  |  |  |  |  |  | 
| 72 |  |  |  |  |  |  | =head2 clear | 
| 73 |  |  |  |  |  |  |  | 
| 74 |  |  |  |  |  |  | Clear the currently stored debugging information. | 
| 75 |  |  |  |  |  |  |  | 
| 76 |  |  |  |  |  |  | =cut | 
| 77 |  |  |  |  |  |  |  | 
| 78 |  |  |  |  |  |  | sub clear { | 
| 79 | 1 |  |  | 1 | 1 | 362 | return @debug = (); | 
| 80 |  |  |  |  |  |  | } | 
| 81 |  |  |  |  |  |  |  | 
| 82 |  |  |  |  |  |  | =head2 store | 
| 83 |  |  |  |  |  |  |  | 
| 84 |  |  |  |  |  |  | Store debugging information. | 
| 85 |  |  |  |  |  |  |  | 
| 86 |  |  |  |  |  |  | =cut | 
| 87 |  |  |  |  |  |  |  | 
| 88 |  |  |  |  |  |  | sub store { | 
| 89 | 31 | 50 |  | 31 | 1 | 694 | return  unless($debug); | 
| 90 |  |  |  |  |  |  |  | 
| 91 | 31 |  |  |  |  | 64 | my ($self, $id, @args) = @_; | 
| 92 | 31 | 100 | 100 |  |  | 131 | return  if(!$id || $debug < $id); | 
| 93 |  |  |  |  |  |  |  | 
| 94 | 29 |  |  |  |  | 122 | push @debug, [$id, join(' ',@args)]; | 
| 95 | 29 |  |  |  |  | 80 | return; | 
| 96 |  |  |  |  |  |  | } | 
| 97 |  |  |  |  |  |  |  | 
| 98 |  |  |  |  |  |  | =head2 retrieve | 
| 99 |  |  |  |  |  |  |  | 
| 100 |  |  |  |  |  |  | Retrieve debugging information. | 
| 101 |  |  |  |  |  |  |  | 
| 102 |  |  |  |  |  |  | =cut | 
| 103 |  |  |  |  |  |  |  | 
| 104 |  |  |  |  |  |  | sub retrieve { | 
| 105 | 6 |  |  | 6 | 1 | 2737 | my $self = shift; | 
| 106 | 6 |  | 100 |  |  | 18 | my $id   = shift || 1; | 
| 107 |  |  |  |  |  |  |  | 
| 108 | 6 |  |  |  |  | 13 | return grep {$_->[0] <= $id} @debug; | 
|  | 116 |  |  |  |  | 246 |  | 
| 109 |  |  |  |  |  |  | } | 
| 110 |  |  |  |  |  |  |  | 
| 111 |  |  |  |  |  |  | =head2 dumper | 
| 112 |  |  |  |  |  |  |  | 
| 113 |  |  |  |  |  |  | Uses 'on demand' call to Data::Dumper::Dumper(). | 
| 114 |  |  |  |  |  |  |  | 
| 115 |  |  |  |  |  |  | =cut | 
| 116 |  |  |  |  |  |  |  | 
| 117 |  |  |  |  |  |  | sub dumper { | 
| 118 | 4 |  |  | 4 | 1 | 9 | my $self = shift; | 
| 119 | 4 |  |  |  |  | 4 | my $dump = 'Data::Dumper'; | 
| 120 | 4 | 50 |  |  |  | 6 | if(eval { require $dump }) { | 
|  | 4 |  |  |  |  | 945 |  | 
| 121 | 0 |  |  |  |  | 0 | $dump->import; | 
| 122 | 0 |  |  |  |  | 0 | return Dumper(@_); | 
| 123 |  |  |  |  |  |  | } | 
| 124 | 4 |  |  |  |  | 24 | return ''; | 
| 125 |  |  |  |  |  |  | } | 
| 126 |  |  |  |  |  |  |  | 
| 127 |  |  |  |  |  |  | 1; | 
| 128 |  |  |  |  |  |  |  | 
| 129 |  |  |  |  |  |  | __END__ |