Hello Monks, I'm faced with what looks like a classical OOP problem: I have a bunch of modules which, by design, offer the same set of functions to the outside, but conceptually with different implementations. In practice, however, a large percentage of the modules have identical implementation for most functions. In OOP, I would therefore do it like this:

  1. Define a base class which implements defaults for all functions
  2. Derive my modules from the base and override only those few functions which are different (in most modules, this will be only one function)
Unfortunately I can not use this approach here (the modules are part of an existing framework and I can for example not make real objects out of them, i.e. no "bless" etc.). So I came up with the following solution:
  1. Define a "parent module" which contains default implementations for all functions
  2. In each module, I "use" the parent module. For the functions which are specific to the respective module, I write an implementation of the function. For those which are supposed to use the default, I use a forwarding function.
The forwarding functions look like this:
sub somefunc { &ParentModule::somefunc }
Since the majority of function definitions are forwarders, I tried to improve like this: I define a file "Includes.pl", which contains those most common forwarding definitions, and in those of my modules, which need these, I do a
require 'Includes.pl';
So far, this seems to work, but I'm not that happy with this solution. Maybe there is a more elegant way to do this? It is important, however, that an alternative solution does not involve invoking AUTOLOAD in my modules, because this would also cause problems in the current context. Any ideas?

-- 
Ronald Fischer <ynnor@mm.st>

In reply to Forwarding functions to a different module 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.