Why? What about your usage requires you to call a subroutine with goto?

Well, I wanted to spare you these tedious details, because I didn't consider them important to know, but here we go:

The module these functions are in is a mediation layer to a logging module (Log::Log4perl actually). Originally, the client modules used, for instance, Log4perl functions such as DEBUG(...) or ERROR(...) to generate the logs.

This system is now about to be modified in that DEBUG, ERROR etc. should first invoke some of our own code to do some preliminary work, and then pass on the DEBUG, ERROR etc. of the Log4perl module. In addition, my own version of these routines to do first some special processing, then some general processing (which is common to all type of traces), and then pass control to Log4perl. Basically, the information flow is as follows:

  1. User calls DEBUG(), ERROR(), INFO() etc., invoking my own DEBUG/ERROR/INFO routines.
  2. My DEBUG does some actions specific to the debug case.
  3. Next, the general code (common for DEBUG, ERROR etc.) is executed.
  4. Finally, Log::Log4perl::DEBUG/ERROR/INFO etc. is run
If I would do this with normal function calls, i.e.
package MyLogging; ... sub DEBUG { ... general(\Log::Log4perl::DEBUG,@_); } sub general { my $logger=shift; ... &$logger(@_); }
the Log4perl logging routines would report MyLogging::general as caller, instead of the original call site of DEBUG().

Maybe there is a callback mechanism in Log4perl which I could use; the documentation of Log4perl is pretty big and I thought that my problem is so easy that I could do it simply by using (kind of):

package MyLogging; ... sub DEBUG { ... unshift @_,\Log::Log4perl::DEBUG; goto &general; } sub general { my $logger=shift; ... goto &$logger; }

Actually, it *does* work that way, and I believe that since these functions are small and co-operate closely, it is also easy to understand. Still, I am not absolutely happy with the solution either. If I find time, I should maybe take a few hours to wade through the Log4perl docs to get ideas for other solutions.

-- 
Ronald Fischer <ynnor@mm.st>

In reply to Re^4: goto &sub and local question by rovf
in thread goto &sub and local question by rovf

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.