Devel::CodeObserver - Code tracer
my $tracer = Devel::CodeObserver->new(); my ($retval, $trace_data) = $tracer->call(sub { $dat->{foo}{bar} eq 200 });
This module call the CodeRef, and fetch the Perl5 VM's temporary values.
my $tracer = Devel::CodeObserver->new();
Create new instance.
$tracer->call($code: CodeRef) : (Scalar, Devel::CodeObserver::Result)
Call the $code and get the tracing result.
$code
$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.
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.
There is no list context support. I don't want to implement this, for now. But you can send me a patch.
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.
To install B::Tap, copy and paste the appropriate command in to your terminal.
cpanm
cpanm B::Tap
CPAN shell
perl -MCPAN -e shell install B::Tap
For more information on module installation, please visit the detailed CPAN module installation guide.