NAME

Devel::CodeObserver - Code tracer

SYNOPSIS

    my $tracer = Devel::CodeObserver->new();
    my ($retval, $trace_data) = $tracer->call(sub { $dat->{foo}{bar} eq 200 });

DESCRIPTION

This module call the CodeRef, and fetch the Perl5 VM's temporary values.

METHODS

my $tracer = Devel::CodeObserver->new();

Create new instance.

$tracer->call($code: CodeRef) : (Scalar, Devel::CodeObserver::Result)

Call the $code and get the tracing result.

Devel::CodeObserver::Result's METHODS

$result->dump_pairs() : ArrayRef[ArrayRef[Str]]

Returns the pair of the dump result. Return value's each element contains ArrayRef. Each element contains 2 values. First is the B::Deparse'd code. Second is the Dumper()'ed value.

EXAMPLES

Here is the concrete example.

    use 5.014000;
    use Devel::CodeObserver;
    use Data::Dumper;

    my $dat = {
        x => {
            y => 0,
        },
        z => {
            m => [
                +{
                    n => 3
                }
            ]
        }
    };

    my $tracer = Devel::CodeObserver->new();
    my ($retval, $result) = $tracer->call(sub { $dat->{z}->{m}[0]{n} eq 4 ? 1 : 0 });
    print "RETVAL: $retval\n";
    for my $pair (@{$result->dump_pairs}) {
        my ($code, $val) = @$pair;
        print "$code => $val\n";
    }

Output is here:

    RETVAL: 0
    $$dat{'z'}{'m'}[0]{'n'} => 3
    $$dat{'z'}{'m'}[0] => {'n' => 3}
    $$dat{'z'}{'m'} => [{'n' => 3}]
    $$dat{'z'} => {'m' => [{'n' => 3}]}
    $dat => {'z' => {'m' => [{'n' => 3}]},'x' => {'y' => 0}}

Devel::CodeObserver fetches the temporary values and return it.

BUGS

LIST CONTEXT

There is no list context support. I don't want to implement this, for now. But you can send me a patch.

METHOD CALL

This version can't handles following form:

    my $tracer = Devel::CodeObserver->new();
    $tracer->call(sub { defined($foo->bar()) });

Because B::Deparse::pp_entersub thinks next object is the `method_named` or LISTOP. But B::Tap's b_tap_push_sv is SVOP!!!

I should fix this issue, but I have no time to fix this.

Patches welcome.