dimar has asked for the wisdom of the Perl Monks concerning the following question:
OVERVIEW:
I have an application where I am attempting to use a simple
mechanism for inclusion (hereinafter 'inheritance' (used in a non-OOP,
non technical sense))
of 'text blurbs' based on perl modules. The problem is how
to persist the notion of 'inheritance' even after the perl code
has been run or 'auto-generated'. The details are as follows. A code sample is below.
PROBLEM1:
How do you obviate the need to reproduce text blurbs in multiple
places, when what you *really* want to do is inherit those text blurbs
from a single, centralized source.
SOLUTION1:
Naive Inheritance solves Problem1. Simply define a MainModule
that serves as a repository for all centralized text blurbs.
Then include them from that MainModule whenever and wherever
necessary.
PROBLEM2:
Naive Inheritance does not work with this particular application,
because sometimes the perl source is 'auto-generated' and
'auto-republished'. This means that, from time to time, an
identity transformation is applied to (for example) CustomerModule.pm, and
the entire module code is 'refreshed' via automated process.
This 'refresh' operation causes the inherited text blurbs to
be 'flattened' into their plain text equivalents. This breaks
the intended benefits of using inheritance.
QUESTION1:
What is a solution to fix Problem2 (the problem of Naive Inheritance) in which the variable values are replaced with their plain-text equivalent?
In order to illustrate the question, a simple example follows
(portions omitted for space):
When the above code is run in 'output' context, we obviously want the 'StandardHeader' and 'StandardFooter' portions replaced with their plain-text equivalent. However, when the code is run in 'republish' or 'auto-generate perl' contexts, we do not want the StandardHeader or StandardFooter portions to be interpolated at all.### begin: package CustomerModule ### ... ### ... ### begin node: ccPastDue30 %hDataRec = ( caption => 'Past Due 30 Days', domain => 'customer_corresp', codename => 'ccPastDue30', desc => 'for accounts that are 30 days late', keywords => 'customer warning deadbeat', ### ----------------------------------------------- body => q^ ^.MainModule::StandardHeader().q^ Dear __fname__ __lname__, It has come to our attention that your account is 30 days past due. Please address this oversight as soon as possible to avoid late fees and additional charges. Thank you. ^.MainModule::StandardFooter().q^ ^, ### ----------------------------------------------- ); do{my %hTemp = %hDataRec; $root->{$hTemp{mnemonic}} = \%hTemp; };### end_node ### begin node: ccPastDue60 ### ... ### ... };### end_node ### begin node: ccPastDue90 ### ... ### ... };### end_node