Data::Phrasebook::Debug - Phrasebook debugging.


Data-Phrasebook documentation Contained in the Data-Phrasebook distribution.

Index


Code Index:

NAME

Top

Data::Phrasebook::Debug - Phrasebook debugging.

SYNOPSIS

Top

    use Data::Phrasebook;

    my $q = Data::Phrasebook->new(
        class  => 'Plain',
        loader => 'Text',
        file   => 'phrases.txt',
        debug  => 2,
    );

    my $r = Phrasebook->new( file  => 'phrases.txt', debug => 3 );

    $r->debug(4);
    $r->store(3,"Start");
    my @log = $r->retrieve(2);
    $r->clear();

DESCRIPTION

Top

This module enables debug logging for phrasebook classes. It simply stores all interaction with the phrasebook, which can then be interrogated. Do not call directly, but via the class object.

There is a single storage for all levels of the Data::Phrasebook heirarchy. This then enables storage and retrieval to be performed by the user. There are several different levels of debugging, detailed as follows:

  1 - Errors
  2 - Warnings
  3 - Information
  4 - Variable Debugging

The first three are simple strings that are recorded during the processing. However, the latter is specifically for dumping the contents of significant variables.

Through the use of the debug() method, the debugging can be switched on and off at significant points. The clear() method will clear the current trail of debugging information.

METHODS

Top

debug

Accessor to debugging flag.

clear

Clear the currently stored debugging information.

store

Store debugging information.

retrieve

Retrieve debugging information.

dumper

Uses 'on demand' call to Data::Dumper::Dumper().

SEE ALSO

Top

Data::Phrasebook.

SUPPORT

Top

Please see the README file.

AUTHOR

Top

  Barbie, <barbie@cpan.org>
  for Miss Barbell Productions <http://www.missbarbell.co.uk>.

COPYRIGHT AND LICENSE

Top


Data-Phrasebook documentation Contained in the Data-Phrasebook distribution.
package Data::Phrasebook::Debug;
use strict;
use warnings FATAL => 'all';
use Carp qw( croak );

use vars qw($VERSION);
$VERSION = '0.31';

my @debug;
my $debug = 0;

sub debug {
    my $self = shift;
    return @_ ? $debug = shift : $debug;
}

sub clear {
    return @debug = ();
}

sub store {
    return  unless($debug);

    my ($self, $id, @args) = @_;
    return  if(!$id || $debug < $id);

    push @debug, [$id, join(' ',@args)];
	return;
}

sub retrieve {
    my $self = shift;
    my $id   = shift || 1;

    return grep {$_->[0] <= $id} @debug;
}

sub dumper {
    my $self = shift;
    my $dump = 'Data::Dumper';
    if(eval { require $dump }) {
        $dump->import;
		return Dumper(@_);
	}
	return '';
}

1;

__END__