A quick search on CPAN brought me to Devel::CallTrace, which ties into the Perl debugger mechanism, but doesn't provide arguments and return values (although the code seems short enough that I guess it could probably be extended). Then there's Debug::Trace, which works by simply wrapping the requested subs with code that prints their arguments and return values:

$ cat foo.pl #!/usr/bin/env perl use warnings; use strict; sub foo { bar($_[0] x 3)."-".quz(ord($_[0])) } sub bar { $_[0].length($_[0]) } sub quz { $_[0].$_[0] } print foo($_), "\n" for 'a'..'b'; $ perl -MDebug::Trace=foo,bar,quz foo.pl TRACE: main::foo("a") called at foo.pl line 11 package main TRACE: main::bar("aaa") called at foo.pl line 5 sub main::foo TRACE: main::bar() returned: "aaa3" TRACE: main::quz(97) called at foo.pl line 5 sub main::foo TRACE: main::quz() returned: 9797 TRACE: main::foo() returned: ("aaa3-9797") aaa3-9797 TRACE: main::foo("b") called at foo.pl line 11 package main TRACE: main::bar("bbb") called at foo.pl line 5 sub main::foo TRACE: main::bar() returned: "bbb3" TRACE: main::quz(98) called at foo.pl line 5 sub main::foo TRACE: main::quz() returned: 9898 TRACE: main::foo() returned: ("bbb3-9898") bbb3-9898

At the bottom of the Devel::CallTrace doc, there are a few more references to other modules.

Update: Minor updates to wording.


In reply to Re: Tool to record subroutine calls & return values by haukex
in thread Tool to record subroutine calls & return values by Yary

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.