Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

This method isn't exactly recommended. Look carefully at the other methods mentioned above (possibly except the B::Deparse method, which is likely at least as fragile as this).

I ran into a problem like this a while back where I wanted to write a custom function profiler that used DBD::SQLite to store the profile data. It didn't work very well, but it was fun and it's no trouble for me to cut and paste the code in here. (I ripped off ideas from Memoize directly.)

I think this can easily be adapted to what you're trying to do.

use strict; use warnings; for my $package (qw(testpackage)) { my $st_name = "main::" . $package . "::"; my $symbol_table = do { no strict 'refs'; *{$st_name}{HASH}; }; while( my ($k, $v) = each %$symbol_table ) { if( $package->can($k) ) { my $st_fname = $st_name . $k; my $fref = do { no strict 'refs'; *{$st_fname}{CODE}; # from Memoize.pm :: _make_cref() }; next unless $fref and ref $fref eq "CODE"; next if defined prototype $fref; # I'm ignoring prototypes my $newf = sub { my ($r, @r); warn "<beginfunc name=\"$k\">\n"; if( wantarray ) { @r = $fref->(@_); } else { $r = $fref->(@_); } warn "</endfunc>\n"; return $r unless wantarray; @r; }; do { no strict 'refs'; local($^W) = 0; # ``Subroutine $install_name red +efined at ...'' *{$st_fname} = $newf; # also from Memoize.pm :: memoiz +e() } } } } testpackage->f1(); testpackage->f2(); package testpackage; use strict; sub f1 { print "f1!\n"; } sub f2 { print "f2!\n"; }

-Paul


In reply to Re: Rewriting sub code on import to add logging by jettero
in thread Rewriting sub code on import to add logging by gryphon

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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others drinking their drinks and smoking their pipes about the Monastery: (5)
    As of 2020-11-24 04:47 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found

      Notices?