The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Tie::Trace - easy print debugging with tie

VERSION

Version 0.01

SYNOPSIS

    use Tie::Trace;
 
    my %hash;
    tie %hash, "Tie::Trace::Hash";
 
    $hash{hoge} = 'hogehoge'; # warn Hash => Key: hoge, Value: hogehgoe
 
    my @array;
    tie @aray, "Tie::Trace::Array";
    push @array, "array";    # warn Array => Point: 0, Value: array
 
    my $scalar;
    tie $scalar, "Tie::Trace::Scalar";
    $scalar = "scalar";      # warn Scalar => Value: scalar

DESCRIPTION

This is usefull for print debugging. Using tie mechanism, you can see sotred value for the specified variable.

If the stored value is scalar/array/hash ref, this can check recursively.

for example;

 tie %hash, "Tie::Trace::Hash";
 
 $hash{foo} = {a => 1, b => 2}; # warn ...
 $hash{foo}->{a} = 2            # warn ...

But This won't care blessed reference or tied value.

OPTIONS

key => [values/regexs]
 tie %hash, "Tie::Trace::Hash", key => [qw/foo bar/];

It is for hash. You can spedify key name/regex for checking. Not specified/matched keys are ignored for warning.

for example;

 tie %hash, "Tie::Trace::Hash", key => [qw/foo bar/, qr/x/];
 
 $hash{foo} = 1 # warn ...
 $hash{bar} = 1 # warn ...
 $hash{var} = 1 # *no* warnings
 $hash{_x_} = 1 # warn ...
value => [contents/regexs]
 tie %hash, "Tie::Trace::Hash", value => [qw/foo bar/];

You can spedify value's content/regex for checking. Not specified/matched are ignored for warning.

for example;

 tie %hash, "Tie::Trace::Hash", key => [qw/foo bar/, qr/\)/];
 
 $hash{a} = 'foo'  # warn ...
 $hash{b} = 'foo1' # *no* warnings
 $hash{c} = 'bar'  # warn ...
 $hash{d} = ':-)'  # warn ...
use => [qw/hash array scalar/]
 tie %hash, "Tie::Trace::Hash", use => [qw/array/];

It specify check type. As default, all type will be checked.

for example;

 tie %hash, "Tie::Trace::Hash", use => [qw/array/];
 
 $hash{foo} = 1         # *no* warnings
 $hash{bar} = 1         # *no* warnings
 $hash{var} = []        # *no* warnings
 push @{$hash{var}} = 1 # warn ...
debug => 'dumper'/coderef
 tie %hash, "Tie::Trace::Hash", debug => 'dumper'
 tie %hash, "Tie::Trace::Hash", debug => sub{my($self, @v) = @_; return @v }

It specify value representation. As default, just print value as scalar. You can use "dumper" or coderef. "dumper" make value show with Data::Dumper::Dumper. When you specify your coderef, its first argument is tied value and second argument is value, it should modify it and return it.

r => 0/1
 tie %hash, "Tie::Trace::Hash", r => 0;

If r is 0, this won't check recusively. 1 is default.

AUTHOR

Ktat, <atusi at pure.ne.jp>

BUGS

Please report any bugs or feature requests to bug-tie-debug at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Tie-Trace. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc Tie::Trace

You can also look for information at:

COPYRIGHT & LICENSE

Copyright 2006 Ktat, all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.