Just another Perl shrine | |
PerlMonks |
Re: Tool to record subroutine calls & return valuesby stevieb (Canon) |
on Apr 09, 2017 at 18:48 UTC ( [id://1187532]=note: print w/replies, xml ) | Need Help?? |
Not the most versatile option, but thought I'd throw it out there. I wrote Wrap::Sub quite a while ago as a learning experience that can do this kind of thing. It works by running code before the actual sub is called where you can access the incoming parameters then do work before the actual sub is called, then runs another chunk of code after the real sub is called, where the return value(s) of the sub are received (which again, you can do more work on if desired). You must list all of the subs you want to wrap (if subs in other packages are desired, specify the full package name of the sub (eg 'Foo::Bar::sub_name').
Output:
Of course, the formatting of the output isn't very creative, but that's simple to fix to your liking within the pre and post subs (which are simple code references, so you can define them anywhere, not necessarily within the init call). Note that you can also wrap all subs within a module in one pass as well: my $module_subs = $ws->wrap('My::Module');, so you can selectively wrap entire modules in a loop as opposed to individual subs like I did in the above example.
In Section
Seekers of Perl Wisdom
|
|