http://www.perlmonks.org?node_id=954455
hv has asked for the wisdom of the Perl Monks concerning the following question:

For a work problem I encountered yesterday, it occurred to me that it'd be trivial to solve with the right helper module. I can't work out if that module is easy, hard or impossible to write - or has already been written.

I'm slightly fuzzy on the details, but I imagine it looking something like this:

% cat myprog use Data::Annotate; # 'Tie::Annotate'? sub adder { return $_[0] + $_[1] } my($foo, $baz) = (2, 5); annotate($foo, 'foo'); my $bar = adder($foo, $baz); say "bar is ", $bar; say "bar is annotated as ", annotation($bar); say "bar is derived from ", derivation($bar); # not sure if that should also attempt to show derivation of the # components; maybe it should take a maxdepth argument: my $etc = $bar + $foo; say "etc is annotated as ", annotation($etc); say "etc is derived from ", derivation($etc, depth => 3); % perl myprog bar is 7 bar is annotated as foo + 5 bar is derived from foo + 5 at myprog line 2 main::adder(2, 5) called at myprog line 5 etc is annotated as (foo + 5) + foo etc is derived from (foo + 5) + foo at myprog line 11 (foo + 5) at myprog line 2 main::adder(2, 5) called at myprog line 5 foo annotated at myprog line 4 %

An obvious difficulty is how to construct the annotation string for various ops, but I'd be happy enough if it said "i_add(i_add(foo, 5), foo)" instead.

I'd welcome your thoughts.

Hugo